[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Oddity with @Around and proceed arguments
|
Ron,
How are you building and running the
application? Which version of AspectJ are you using? It works for me using
a hand-coded aop.xml file and load-time weaving support. I had to change
the aspect a little to cope with the fact that the "proceed()"
method throws Throwable but this is what I got:
Console
84
info AspectJ Weaver Version
DEVELOPMENT built on Friday Jan 20, 2006 at 10:29:42 GMT
info register classloader
org.aspectj.weaver.loadtime.WeavingURLClassLoader
info using /C:/workspaces/temp/Test/bin/META-INF/aop.xml
info register aspect A
info weaving 'M'
info generating class 'M$AjcClosure1'
info weaving 'C'
info weaving 'A'
A.java
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class A {
@Pointcut( "call(void C.bar( int
)) && args( i ) " )
void fooOfC( int i ) {}
@Around("fooOfC( i )")
public void foo2( ProceedingJoinPoint
pjp, int i) throws Throwable {
// pjp.proceed(
new Object[] { pjp.getTarget(), i } );
pjp.proceed( new Object[]
{ i*2 } );
}
}
aop.xml
<?xml version="1.0" encoding="UTF-8"?>
<aspectj>
<aspects>
<aspect name="A"/>
</aspects>
<weaver
options="-verbose"/>
</aspectj>
Cheers
Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester, SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
http://w3.hursley.ibm.com/~websterm/
Please respond to aspectj-users@xxxxxxxxxxx
Sent by:
aspectj-users-bounces@xxxxxxxxxxx
To:
aspectj-users@xxxxxxxxxxx
cc:
Subject:
[aspectj-users]
Oddity with @Around and proceed arguments
Hi experts!
I'm a newcomer to this technology, so forgive me if I've missed the
obvious. For various reasons, the project I'm working on is interesting
in incorporating the annotation style for aspect declaration. I've
encountered an oddity which I'm unsure about. In essense I have
duplicated the @Around example in chapter 9 of the developers notebook
(http://www.eclipse.org/aspectj/doc/released/adk15notebook/ataspectj-pcadvice.html)
where each of the following classes are in a separate .java file:
public class M {
public static void main( String[] args ) {
C c = new C();
c.bar(42);
}
}
public class C {
public void bar(int i) {
System.out.println( i );
}
}
@Aspect
public class A {
@Pointcut( "call(void C.bar( int )) &&
args( i ) " )
void fooOfC( int i ) {}
@Around("fooOfC( i )")
public void foo2( ProceedingJoinPoint pjp,
int i) {
pjp.proceed( new Object[] { pjp.getTarget(),
i } );
/* Doc doesn't show this ---^^^^^^^^^^^^^^^
* Via the doc I should have
passed just the int reference thus:
* pjp.proceed( new Object[]
{ i } );
*/
}
}
When I followed the example by only including the int in the Object
array, I was getting a ClassCastException which after javap'ing the file
indicated that the weaver appeared to be expecting two arguments rather
than one. The first (and missing arg) appearing to be the instance
of
object to proceed to. By getting the target from the pjp reference
and
adding it to the array of objects passed, the problem seems to be solved
and everything worked fine. So, I'd just like to have confidence
that
what I'm doing is in fact the correct methodology and that this is a
documentation oversight or alternately, that my limited understanding
has resulted in me completely bolluxing everything up and things should
be specified in a different way.
Thanks for your help!!!
=Ron=
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users