@Around("call(void M.method(String)) && args(p)")
public void a( ProceedingJoinPoint pjp, String p) throws Throwable {
System.err.println("advice from ataj aspect");
- pjp.proceed( new Object[] { pjp.getTarget(),"faked" } );
+ pjp.proceed( new Object[] { "faked" } );
}
public static void main(String []argv) {
@Around("call(void M.method(String)) && args(p) && this(t) && target(t2)")
public void a( ProceedingJoinPoint pjp, M t,String p, M t2) throws Throwable {
System.err.println("advice from ataj aspect");
- pjp.proceed(new Object[]{newM2,"faked",newM3});
+ pjp.proceed(new Object[]{newM2,newM3,"faked"});
}
public static void main(String []argv) {
--- /dev/null
+// Bind the target and pass in the right order
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.*;
+
+@Aspect
+public class A42 {
+ M newM = new M("2");
+
+ @Around("call(void M.method(String)) && args(p) && target(t)")
+ public void a( ProceedingJoinPoint pjp, M t, String p) throws Throwable {
+ System.err.println("advice from ataj aspect");
+ pjp.proceed(new Object[]{newM,"faked"});
+ }
+
+ public static void main(String []argv) {
+ M.main(argv);
+ }
+}
+
+class M {
+
+ String prefix;
+
+ public M(String prefix) { this.prefix = prefix; }
+
+ public static void main( String[] args ) {
+ M m = new M("1");
+ m.method("real");
+ }
+
+ public void method(String s) { System.err.println(prefix+s); }
+}
@Aspect
public class A7 {
- M newM = new M("2");
+ N newN = new N();
@Around("call(void M.method(String)) && args(p) && this(t)")
- public void a( ProceedingJoinPoint pjp, M t,String p) throws Throwable {
+ public void a( ProceedingJoinPoint pjp, N t,String p) throws Throwable {
System.err.println("advice from ataj aspect");
- pjp.proceed(new Object[]{newM,"faked"});
+ pjp.proceed(new Object[]{newN,"faked"});
}
public static void main(String []argv) {
- M.main(argv);
+ N.main(argv);
}
}
+class N {
+ public static void main( String[] args ) {
+ N n = new N();
+ n.methodCaller("real");
+ }
+
+
+ public void methodCaller(String param) {
+ M m = new M("1");
+ m.method(param);
+ }
+
+}
+
+
+class M {
+ String prefix;
+ public M(String prefix) { this.prefix = prefix; }
+ public void method(String s) { System.err.println(prefix+s); }
+}
+
+/*
class M {
String prefix;
public void method(String s) { System.err.println(prefix+s); }
}
+*/
M newM3 = new M("3");
@Around("execution(void M.method(String)) && args(p) && this(t) && target(t2)")
- public void a( ProceedingJoinPoint pjp, M t,String p, M t2) throws Throwable {
+ public void a( ProceedingJoinPoint pjp, M t,M t2,String p) throws Throwable {
System.err.println("advice from ataj aspect");
- pjp.proceed(new Object[]{newM2,"faked",newM3});
+ pjp.proceed(new Object[]{newM2,newM3,"faked"});
}
public static void main(String []argv) {
--- /dev/null
+// target() is used, but not in a binding capacity, so dont need to supply
+// in proceed
+
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.*;
+
+@Aspect
+public class Break1 {
+
+ @Around("call(void M.method(String)) && args(p) && target(M)")
+ public void a( ProceedingJoinPoint pjp, String p) throws Throwable {
+ System.err.println("advice from ataj aspect");
+ pjp.proceed(new Object[]{"faked"});
+ }
+
+ public static void main(String []argv) {
+ M.main(argv);
+ }
+}
+
+class M {
+
+ String prefix;
+
+ public M(String prefix) { this.prefix = prefix; }
+
+ public static void main( String[] args ) {
+ M m = new M("1");
+ m.method("real");
+ }
+
+ public void method(String s) { System.err.println(prefix+s); }
+}
--- /dev/null
+// this() is used for matching but not binding
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.*;
+
+@Aspect
+public class Break2 {
+ M newM2 = new M("2");
+ M newM3 = new M("3");
+
+ @Around("execution(void M.method(String)) && args(p) && this(M)")
+ public void a( ProceedingJoinPoint pjp, String p) throws Throwable {
+ System.err.println("advice from ataj aspect");
+ pjp.proceed(new Object[]{"faked"});
+ }
+
+ public static void main(String []argv) {
+ M.main(argv);
+ }
+}
+
+class M {
+
+ String prefix;
+
+ public M(String prefix) { this.prefix = prefix; }
+
+ public static void main( String[] args ) {
+ M m = new M("1");
+ m.methodCaller("real");
+ }
+
+ public void methodCaller(String param) {
+ method(param);
+ }
+
+ public void method(String s) { System.err.println(prefix+s); }
+
+}
System.err.println("advice running");
return thisJoinPoint.proceed(new Object[]{i*2});
}
+ public static void main(String []argv) {
+ Foo.main(argv);
+ }
}
-public class Foo {
+class Foo {
int a;
public void setAge(int i) {
System.err.println("Setting age to "+i);
import org.aspectj.lang.annotation.*;
@Aspect
-public class ProceedAspect {
+public class BugCase2 {
@Pointcut("execution(* setAge(..)) && args(i)")
void setAge(int i) {}
System.err.println("advice running");
return thisJoinPoint.proceed(new Object[]{i*2});
}
+ public static void main(String []argv) {
+ Foo.main(argv);
+ }
}
-public class Foo {
+ class Foo {
int a;
public void setAge(int i) {
System.err.println("Setting age to "+i);
-
+import java.util.*;
import org.aspectj.lang.annotation.*;
+import org.aspectj.lang.*;
@Aspect
-public class X {
+public class MultipleArgs {
- @Before("call(* callone(..)) && !within(X) && args(a,b,c)")
- public void b1(ProceedingJoinPoint pjp,int a,String b,List c) {
+ @Around("call(* callone(..)) && !within((MultipleArgs)) && args(a,b,c)")
+ public void a1(ProceedingJoinPoint pjp,int a,String b,List c) {
System.err.println("advice running");
pjp.proceed(new Object[]{a,b,c});
}
- @Before("call(* calltwo(..)) && !within(X) && args(a,b,c)")
- public void b1(ProceedingJoinPoint pjp,String b,List c,int a) {
+ @Around("call(* calltwo(..)) && !within((MultipleArgs)) && args(a,b,c)")
+ public void a2(ProceedingJoinPoint pjp,String b,List c,int a) {
System.err.println("advice running");
pjp.proceed(new Object[]{a,b,c});
}
- @Before("call(* callone(..)) && !within(X) && args(a,b,c) && this(o)")
- public void b1(ProceedingJoinPoint pjp,int a,String b,List c,Object o) {
+ @Around("call(* callone(..)) && !within((MultipleArgs)) && args(a,b,c) && this(o)")
+ public void a3(ProceedingJoinPoint pjp,int a,String b,List c,Object o) {
System.err.println("advice running");
pjp.proceed(new Object[]{o,a,b,c});
}
--- /dev/null
+// Bind the target and pass in the right order
+
+aspect X42 {
+ M newM = new M("2");
+
+ void around(M t,String p): call(void M.method(String)) && args(p) && target(t) {
+ System.err.println("advice from code aspect");
+ proceed( newM , "faked" );
+ }
+
+ public static void main(String []argv) {
+ M.main(argv);
+ }
+}
+
+
+
+class M {
+
+ String prefix;
+
+ public M(String prefix) { this.prefix = prefix; }
+
+ public static void main( String[] args ) {
+ M m = new M("1");
+ m.method("real");
+ }
+
+ public void method(String s) { System.err.println(prefix+s); }
+}
</run>
</ajc-test>
+ <ajc-test dir="features151/ataround" title="annotation style - basic - noinline">
+ <compile files="A1.java" options="-1.5 -XnoInline"/>
+ <run class="A1">
+ <stderr>
+ <line text="advice from ataj aspect"/>
+ <line text="faked"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
<ajc-test dir="features151/ataround" title="annotation style - basic">
<compile files="A1.java" options="-1.5"/>
<run class="A1">
-
-
- <ajc-test dir="features151/ataround" title="code style - forget to pass target">
- <compile files="X2.java" options="-1.5">
- <message kind="error" line="7" text="too few arguments to proceed, expected 2"/>
- </compile>
- </ajc-test>
-
- <ajc-test dir="features151/ataround" title="annotation style - forget to pass target">
- <compile files="A2.java" options="-1.5">
- <message kind="error" line="7" text="too few arguments to proceed, expected 2"/>
- </compile>
- </ajc-test>
-
-
- <ajc-test dir="features151/ataround" title="code style - incorrect arg types">
- <compile files="X3.java" options="-1.5">
- <message kind="error" line="7" text="Type mismatch: cannot convert from String to M"/>
- <message kind="error" line="7" text="Type mismatch: cannot convert from M to String"/>
- </compile>
- </ajc-test>
-
- <ajc-test dir="features151/ataround" title="annotation style - incorrect arg types">
- <compile files="A3.java" options="-1.5">
- <message kind="error" line="7" text="too few arguments to proceed, expected 2"/>
- </compile>
- </ajc-test>
-
-
- <ajc-test dir="features151/ataround" title="code style - correct usage, binding and passing new target for call">
+ <ajc-test dir="features151/ataround" title="code style - correct usage, binding and passing same target for call">
<compile files="X4.java" options="-1.5"/>
<run class="X4">
<stderr>
</run>
</ajc-test>
- <ajc-test dir="features151/ataround" title="annotation style - correct usage, binding and passing new target for call">
+ <ajc-test dir="features151/ataround" title="annotation style - correct usage, binding and passing same target for call - noinline">
+ <compile files="A4.java" options="-1.5 -XnoInline"/>
+ <run class="A4">
+ <stderr>
+ <line text="advice from ataj aspect"/>
+ <line text="1faked"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="features151/ataround" title="annotation style - correct usage, binding and passing same target for call">
<compile files="A4.java" options="-1.5"/>
<run class="A4">
<stderr>
- <ajc-test dir="features151/ataround" title="code style - changing target for call">
- <compile files="X5.java" options="-1.5"/>
- <run class="X5">
+
+ <ajc-test dir="features151/ataround" title="code style - correct usage, binding and passing new target for call">
+ <compile files="X42.java" options="-1.5"/>
+ <run class="X42">
<stderr>
<line text="advice from code aspect"/>
<line text="2faked"/>
</run>
</ajc-test>
- <ajc-test dir="features151/ataround" title="annotation style - changing target for call">
- <compile files="A5.java" options="-1.5"/>
- <run class="A5">
+ <ajc-test dir="features151/ataround" title="annotation style - correct usage, binding and passing new target for call - noinline">
+ <compile files="A42.java" options="-1.5 -XnoInline"/>
+ <run class="A42">
<stderr>
<line text="advice from ataj aspect"/>
<line text="2faked"/>
</run>
</ajc-test>
-
-
- <ajc-test dir="features151/ataround" title="code style - changing target for call - reverse order">
- <compile files="X6.java" options="-1.5"/>
- <run class="X6">
- <stderr>
- <line text="advice from code aspect"/>
- <line text="2faked"/>
- </stderr>
- </run>
- </ajc-test>
-
- <ajc-test dir="features151/ataround" title="annotation style - changing target for call - reverse order">
- <compile files="A6.java" options="-1.5"/>
- <run class="A6">
+ <ajc-test dir="features151/ataround" title="annotation style - correct usage, binding and passing new target for call">
+ <compile files="A42.java" options="-1.5"/>
+ <run class="A42">
<stderr>
<line text="advice from ataj aspect"/>
<line text="2faked"/>
+
+
+ <ajc-test dir="features151/ataround" title="code style - forget to pass target">
+ <compile files="X2.java" options="-1.5">
+ <message kind="error" line="7" text="too few arguments to proceed, expected 2"/>
+ </compile>
+ </ajc-test>
+
+ <ajc-test dir="features151/ataround" title="annotation style - forget to pass target">
+ <compile files="A2.java" options="-1.5">
+ <message kind="error" line="7" text="too few arguments to proceed, expected 2"/>
+ </compile>
+ </ajc-test>
+
+
+
+
<ajc-test dir="features151/ataround" title="code style - bind this on call - change on proceed - no effect">
<compile files="X7.java" options="-1.5"/>
<run class="X7">
</run>
</ajc-test>
+ <ajc-test dir="features151/ataround" title="annotation style - bind this on call - change on proceed - no effect - noinline">
+ <compile files="A7.java" options="-1.5 -XnoInline"/>
+ <run class="A7">
+ <stderr>
+ <line text="advice from ataj aspect"/>
+ <line text="1faked"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
<ajc-test dir="features151/ataround" title="annotation style - bind this on call - change on proceed - no effect">
<compile files="A7.java" options="-1.5"/>
<run class="A7">
</run>
</ajc-test>
+ <ajc-test dir="features151/ataround" title="annotation style - bind this on execution - change on proceed - works - noinline">
+ <compile files="A8.java" options="-1.5 -XnoInline"/>
+ <run class="A8">
+ <stderr>
+ <line text="advice from ataj aspect"/>
+ <line text="2faked"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
<ajc-test dir="features151/ataround" title="annotation style - bind this on execution - change on proceed - works">
<compile files="A8.java" options="-1.5"/>
<run class="A8">
<stderr>
- <line text="advice from code aspect"/>
+ <line text="advice from ataj aspect"/>
<line text="2faked"/>
</stderr>
</run>
</ajc-test>
+
+
+ <ajc-test dir="features151/ataround" title="code style - incorrect arg types">
+ <compile files="X3.java" options="-1.5">
+ <message kind="error" line="7" text="Type mismatch: cannot convert from String to M"/>
+ <message kind="error" line="7" text="Type mismatch: cannot convert from M to String"/>
+ </compile>
+ </ajc-test>
+
+ <ajc-test dir="features151/ataround" title="annotation style - incorrect arg types">
+ <compile files="A3.java" options="-1.5">
+ <message kind="error" line="7" text="too few arguments to proceed, expected 2"/>
+ </compile>
+ </ajc-test>
+
+
+
<ajc-test dir="features151/ataround" title="code style - bind this and target on execution - change on proceed - works">
<compile files="X9.java" options="-1.5"/>
</run>
</ajc-test>
+ <ajc-test dir="features151/ataround" title="annotation style - bind this and target on execution - change on proceed - works - noinline">
+ <compile files="A9.java" options="-1.5 -XnoInline"/>
+ <run class="A9">
+ <stderr>
+ <line text="advice from ataj aspect"/>
+ <line text="3faked"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
<ajc-test dir="features151/ataround" title="annotation style - bind this and target on execution - change on proceed - works">
<compile files="A9.java" options="-1.5"/>
<run class="A9">
<stderr>
- <line text="advice from code aspect"/>
+ <line text="advice from ataj aspect"/>
<line text="3faked"/>
</stderr>
</run>
- </ajc-test>
-
-
+ </ajc-test>
+
+
+
+
<ajc-test dir="features151/ataround" title="code style - bind this and target on call - change on proceed - works">
<compile files="X10.java" options="-1.5"/>
</run>
</ajc-test>
+ <ajc-test dir="features151/ataround" title="annotation style - bind this and target on call - change on proceed - works - noinline">
+ <compile files="A10.java" options="-1.5"/>
+ <run class="A10">
+ <stderr>
+ <line text="advice from ataj aspect"/>
+ <line text="3faked"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
<ajc-test dir="features151/ataround" title="annotation style - bind this and target on call - change on proceed - works">
<compile files="A10.java" options="-1.5"/>
<run class="A10">
<stderr>
- <line text="advice from code aspect"/>
+ <line text="advice from ataj aspect"/>
<line text="3faked"/>
</stderr>
</run>
</ajc-test>
+
+
+
+
+ <ajc-test dir="features151/ataround" title="breaking it - one">
+ <compile files="Break1.java" options="-1.5"/>
+ <run class="Break1">
+ <stderr>
+ <line text="advice from ataj aspect"/>
+ <line text="1faked"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="features151/ataround" title="breaking it - two">
+ <compile files="Break2.java" options="-1.5"/>
+ <run class="Break2">
+ <stderr>
+ <line text="advice from ataj aspect"/>
+ <line text="1faked"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+
+ <ajc-test dir="features151/ataround" title="bug case one">
+ <compile files="BugCase1.java" options="-1.5"/>
+ <run class="BugCase1">
+ <stderr>
+ <line text="advice running"/>
+ <line text="Setting age to 10"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="features151/ataround" title="bug case two">
+ <compile files="BugCase2.java" options="-1.5"/>
+ <run class="BugCase2">
+ <stderr>
+ <line text="advice running"/>
+ <line text="Setting age to 10"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+
+ <ajc-test dir="features151/ataround" title="multiple args">
+ <compile files="MultipleArgs.java" options="-1.5"/>
+ <run class="MultipleArgs">
+ <stderr>
+ <line text="advice running"/>
+ <line text="advice running"/>
+ <line text="advice running"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+
+
+
+
+
+
+ <ajc-test dir="features151/ataround" title="code style - changing target for call - reverse order">
+ <compile files="X6.java" options="-1.5"/>
+ <run class="X6">
+ <stderr>
+ <line text="advice from code aspect"/>
+ <line text="2faked"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="features151/ataround" title="annotation style - changing target for call - reverse order">
+ <compile files="A6.java" options="-1.5"/>
+ <run class="A6">
+ <stderr>
+ <line text="advice from ataj aspect"/>
+ <line text="2faked"/>
+ </stderr>
+ </run>
+ </ajc-test>
+
+
+
+
+
+
+
+