diff options
author | acolyer <acolyer> | 2005-04-25 16:14:07 +0000 |
---|---|---|
committer | acolyer <acolyer> | 2005-04-25 16:14:07 +0000 |
commit | 90e41018152ca4f04e4442e5fae02ee2b97c2a61 (patch) | |
tree | 8239fcc928f949a9e9e04286f694bce362985ff5 /tests/java5 | |
parent | cce34110147c340556de02464bb609f947d9f075 (diff) | |
download | aspectj-90e41018152ca4f04e4442e5fae02ee2b97c2a61.tar.gz aspectj-90e41018152ca4f04e4442e5fae02ee2b97c2a61.zip |
test cases for @AspectJ visitors
Diffstat (limited to 'tests/java5')
29 files changed, 537 insertions, 11 deletions
diff --git a/tests/java5/ataspectj/SimpleBefore.java b/tests/java5/ataspectj/SimpleBefore.java index 2327881b4..8b5019f94 100644 --- a/tests/java5/ataspectj/SimpleBefore.java +++ b/tests/java5/ataspectj/SimpleBefore.java @@ -14,7 +14,7 @@ public class SimpleBefore { X.s.append("2"); } - @Aspect("issingleton") + @Aspect("issingleton()") public static class X { public static StringBuffer s = new StringBuffer(""); diff --git a/tests/java5/ataspectj/annotationGen/APointcut.java b/tests/java5/ataspectj/annotationGen/APointcut.java new file mode 100644 index 000000000..32d504dfd --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/APointcut.java @@ -0,0 +1,13 @@ +import org.aspectj.lang.reflect.*; + +public class APointcut { + + @org.aspectj.lang.annotation.Pointcut("execution(* *.*(..))") + void myPointcut() {}; + + public static void main(String[] args) throws Exception { + AjType myType = AjTypeSystem.getAjType(APointcut.class); + Pointcut pc = myType.getDeclaredPointcut("myPointcut"); + } + +}
\ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/AdviceInAClass.java b/tests/java5/ataspectj/annotationGen/AdviceInAClass.java new file mode 100644 index 000000000..9929781cd --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/AdviceInAClass.java @@ -0,0 +1,8 @@ +import org.aspectj.lang.annotation.Before; + +public class AdviceInAClass { + + @Before("execution(* *(..))") + public void doSomething() {} + +}
\ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/AfterReturningWithBadPCut.java b/tests/java5/ataspectj/annotationGen/AfterReturningWithBadPCut.java new file mode 100644 index 000000000..6c36178bf --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/AfterReturningWithBadPCut.java @@ -0,0 +1,9 @@ +import org.aspectj.lang.annotation.*; + +@Aspect +public class AfterReturningWithBadPCut { + + @AfterReturning("excution(* *.*(..))") + public void logExit() {} + +}
\ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/BadParameterBinding.java b/tests/java5/ataspectj/annotationGen/BadParameterBinding.java new file mode 100644 index 000000000..8e4c2e58f --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/BadParameterBinding.java @@ -0,0 +1,18 @@ +import org.aspectj.lang.annotation.*; + +@Aspect +public class BadParameterBinding { + + @SuppressAjWarnings + @Before("execution(* *(..)) && this(bpb)") + public void logEntry(BadParameterBinding bpb) {} + + @SuppressAjWarnings + @AfterReturning("execution(* *(..)) && this(bpb)") + public void logExit() {} + + @SuppressAjWarnings + @AfterThrowing("call(* TheUnknownType.*(..))") + public void logException() {} + +}
\ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/BasicAdvice.aj b/tests/java5/ataspectj/annotationGen/BasicAdvice.aj new file mode 100644 index 000000000..04fb00be7 --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/BasicAdvice.aj @@ -0,0 +1,122 @@ + +import java.lang.reflect.Method; +import org.aspectj.lang.annotation.*; + +public aspect BasicAdvice { + + @SuppressAjWarnings + before() : execution(* *.*(..)) { + // + } + + @SuppressAjWarnings + after() : call(* Integer.*(..)) { + + } + + @SuppressAjWarnings + after() returning : get(String *) { + + } + + @SuppressAjWarnings + after() returning(String strVal) : get(String *) { + + } + + @SuppressAjWarnings + after() throwing : execution(* *.*(..)) { + + } + + @SuppressAjWarnings + after() throwing(RuntimeException ex) : execution(* *.*(..)) { + + } + + @SuppressAjWarnings + void around() : set(* foo) { + proceed(); + } + + private static int adviceCount = 0; + + public static void main(String[] args) { + Method[] methods = BasicAdvice.class.getDeclaredMethods(); + for (Method method : methods) { + adviceCount++; + if (method.getName().startsWith("ajc$before$")) { + checkBefore(method); + } else if (method.getName().startsWith("ajc$after$")) { + checkAfter(method); + } else if (method.getName().startsWith("ajc$afterReturning$")) { + checkAfterReturning(method); + } else if (method.getName().startsWith("ajc$afterThrowing$")) { + checkAfterThrowing(method); + } else if (method.getName().startsWith("ajc$around$")) { + if (!method.getName().endsWith("proceed")) { + checkAround(method); + } else { + adviceCount--; + } + } else { + adviceCount--; + } + } + if (adviceCount != 7) throw new RuntimeException("Expected 7 advice methods, found " + adviceCount); + } + + private static void checkBefore(Method method) { + assertTrue("expecting 2 annotations",method.getAnnotations().length == 2); + Before beforeAnnotation = method.getAnnotation(Before.class); + assertTrue("expecting execution(* *.*(..))",beforeAnnotation.value().equals("execution(* *.*(..))")); + } + + private static void checkAfter(Method method) { + assertTrue("expecting 2 annotations",method.getAnnotations().length == 2); + After afterAnnotation = method.getAnnotation(After.class); + assertTrue("expecting call(* Integer.*(..))",afterAnnotation.value().equals("call(* Integer.*(..))")); + } + + private static void checkAfterReturning(Method method) { + assertTrue("expecting 2 annotations",method.getAnnotations().length == 2); + AfterReturning afterAnnotation = method.getAnnotation(AfterReturning.class); + if (method.getParameterTypes().length == 1) { + // form with returning arg + assertTrue("expecting get(String *)",afterAnnotation.pointcut().equals("get(String *)")); + assertTrue("expecting empty",afterAnnotation.value().equals("")); + assertTrue("expecting strVal",afterAnnotation.returning().equals("strVal")); + } else { + // form without returning arg + assertTrue("expecting get(String *)",afterAnnotation.pointcut().equals("get(String *)")); + assertTrue("expecting empty",afterAnnotation.value().equals("")); + assertTrue("expecting empty returning",afterAnnotation.returning().equals("")); + } + } + + private static void checkAfterThrowing(Method method) { + assertTrue("expecting 2 annotations",method.getAnnotations().length == 2); + AfterThrowing afterAnnotation = method.getAnnotation(AfterThrowing.class); + if (method.getParameterTypes().length == 1) { + // form with returning arg + assertTrue("expecting execution(* *.*(..))",afterAnnotation.pointcut().equals("execution(* *.*(..))")); + assertTrue("expecting empty",afterAnnotation.value().equals("")); + assertTrue("expecting ex",afterAnnotation.throwing().equals("ex")); + } else { + // form without returning arg + assertTrue("expecting execution(* *.*(..))",afterAnnotation.pointcut().equals("execution(* *.*(..))")); + assertTrue("expecting empty",afterAnnotation.value().equals("")); + assertTrue("expecting empty throwing",afterAnnotation.throwing().equals("")); + } + } + + private static void checkAround(Method method) { + assertTrue("expecting 2 annotations",method.getAnnotations().length == 2); + Around aroundAnnotation = method.getAnnotation(Around.class); + assertTrue("expecting set(* foo)",aroundAnnotation.value().equals("set(* foo)")); + } + + private static void assertTrue(String msg, boolean expr) { + if (!expr) throw new RuntimeException(msg); + } +}
\ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/BeforeWithBadReturn.java b/tests/java5/ataspectj/annotationGen/BeforeWithBadReturn.java new file mode 100644 index 000000000..e219e9181 --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/BeforeWithBadReturn.java @@ -0,0 +1,9 @@ +import org.aspectj.lang.annotation.*; + +@Aspect +public class BeforeWithBadReturn { + + @Before("execution(* *(..))") + public String logEntry() {} + +}
\ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/InnerAspectAspect.aj b/tests/java5/ataspectj/annotationGen/InnerAspectAspect.aj new file mode 100644 index 000000000..324c9bb3a --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/InnerAspectAspect.aj @@ -0,0 +1,15 @@ +import org.aspectj.lang.annotation.Aspect; +import java.lang.annotation.*; + +public aspect InnerAspectAspect { + + public static void main(String[] args) { + Annotation[] annotations = InnerAspect.class.getAnnotations(); + if (annotations.length != 1) throw new RuntimeException("Should have one annotation"); + Aspect aspectAnnotation = (Aspect) annotations[0]; + if (!aspectAnnotation.value().equals("")) throw new RuntimeException("value should be empty"); + } + + private static aspect InnerAspect {} + +}
\ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/InnerAspectClass.aj b/tests/java5/ataspectj/annotationGen/InnerAspectClass.aj new file mode 100644 index 000000000..91842f521 --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/InnerAspectClass.aj @@ -0,0 +1,15 @@ +import org.aspectj.lang.annotation.Aspect; +import java.lang.annotation.*; + +public class InnerAspectClass { + + public static void main(String[] args) { + Annotation[] annotations = InnerAspect.class.getAnnotations(); + if (annotations.length != 1) throw new RuntimeException("Should have one annotation"); + Aspect aspectAnnotation = (Aspect) annotations[0]; + if (!aspectAnnotation.value().equals("")) throw new RuntimeException("value should be empty"); + } + + private static aspect InnerAspect {} + +}
\ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/PerCflowAspect.aj b/tests/java5/ataspectj/annotationGen/PerCflowAspect.aj new file mode 100644 index 000000000..e0190caf7 --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/PerCflowAspect.aj @@ -0,0 +1,20 @@ +import org.aspectj.lang.annotation.Aspect; +import java.lang.annotation.*; + +public aspect PerCflowAspect percflow(execution(* Foo.foo(..))) { + + public static void main(String[] args) { + Annotation[] annotations = PerCflowAspect.class.getAnnotations(); + if (annotations.length != 1) throw new RuntimeException("Should have one annotation"); + Aspect aspectAnnotation = (Aspect) annotations[0]; + if (!aspectAnnotation.value().equals("percflow(execution(* Foo.foo(..)))")) + throw new RuntimeException("value should be equal to perclause but was: " + aspectAnnotation.value()); + } + +} + +class Foo { + + void foo() {} + +}
\ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/PerCflowbelowAspect.aj b/tests/java5/ataspectj/annotationGen/PerCflowbelowAspect.aj new file mode 100644 index 000000000..4018bafed --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/PerCflowbelowAspect.aj @@ -0,0 +1,19 @@ +import org.aspectj.lang.annotation.Aspect; +import java.lang.annotation.*; + +public aspect PerCflowbelowAspect percflowbelow(execution(* Foo.foo(..))) { + + public static void main(String[] args) { + Annotation[] annotations = PerCflowbelowAspect.class.getAnnotations(); + if (annotations.length != 1) throw new RuntimeException("Should have one annotation"); + Aspect aspectAnnotation = (Aspect) annotations[0]; + if (!aspectAnnotation.value().equals("percflowbelow(execution(* Foo.foo(..)))")) throw new RuntimeException("value should be equal to perclause"); + } + +} + +class Foo { + + void foo() {} + +}
\ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/PerTargetAspect.aj b/tests/java5/ataspectj/annotationGen/PerTargetAspect.aj new file mode 100644 index 000000000..c436b8fca --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/PerTargetAspect.aj @@ -0,0 +1,21 @@ +import org.aspectj.lang.annotation.Aspect; +import java.lang.annotation.*; + +public aspect PerTargetAspect pertarget(fooCall()) { + + pointcut fooCall() : call(* Foo.foo(..)); + + public static void main(String[] args) { + Annotation[] annotations = PerTargetAspect.class.getAnnotations(); + if (annotations.length != 1) throw new RuntimeException("Should have one annotation"); + Aspect aspectAnnotation = (Aspect) annotations[0]; + if (!aspectAnnotation.value().equals("pertarget(fooCall())")) throw new RuntimeException("value should be equal to perclause"); + } + +} + +class Foo { + + void foo() {} + +}
\ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/PerThisAspect.aj b/tests/java5/ataspectj/annotationGen/PerThisAspect.aj new file mode 100644 index 000000000..1521b4b4c --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/PerThisAspect.aj @@ -0,0 +1,19 @@ +import org.aspectj.lang.annotation.Aspect; +import java.lang.annotation.*; + +public aspect PerThisAspect perthis(execution(* Foo.foo(..))) { + + public static void main(String[] args) { + Annotation[] annotations = PerThisAspect.class.getAnnotations(); + if (annotations.length != 1) throw new RuntimeException("Should have one annotation"); + Aspect aspectAnnotation = (Aspect) annotations[0]; + if (!aspectAnnotation.value().equals("perthis(execution(* Foo.foo(..)))")) throw new RuntimeException("value should be equal to perclause"); + } + +} + +class Foo { + + void foo() {} + +}
\ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/PerTypeWithinAspect.aj b/tests/java5/ataspectj/annotationGen/PerTypeWithinAspect.aj new file mode 100644 index 000000000..3b435604d --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/PerTypeWithinAspect.aj @@ -0,0 +1,13 @@ +import org.aspectj.lang.annotation.Aspect; +import java.lang.annotation.*; + +public aspect PerTypeWithinAspect pertypewithin(javax.ejb..*) { + + public static void main(String[] args) { + Annotation[] annotations = PerTypeWithinAspect.class.getAnnotations(); + if (annotations.length != 1) throw new RuntimeException("Should have one annotation"); + Aspect aspectAnnotation = (Aspect) annotations[0]; + if (!aspectAnnotation.value().equals("pertypewithin(javax.ejb..*)")) throw new RuntimeException("value should be equal to perclause"); + } + +} diff --git a/tests/java5/ataspectj/annotationGen/PointcutAssortment.java b/tests/java5/ataspectj/annotationGen/PointcutAssortment.java new file mode 100644 index 000000000..1237b28cd --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/PointcutAssortment.java @@ -0,0 +1,42 @@ +import org.aspectj.lang.annotation.*; + +public class PointcutAssortment { + + @Pointcut("execution(* PointcutAssortment.*(..))") + void pc1() {} + + @Pointcut("call(* PointcutAssortment.*(..))") + String pc2() {} + + @Pointcut("foo()") + void pc3() {} + + @Pointcut("pc1() || pc2()") + void pc4() { + System.out.println("hi there!"); + } + + @Pointcut("this(Integer)") + void pc5() {} + + @Pointcut("this(i)") + void pc6(Integer i) {} + + @Pointcut("OtherClass.intSet() && pc6(myInt)") + void pc7(Integer myInt) {} + + @Pointcut("get(* *)") + @Pointcut("set(* *)") + void pc8() {} + + @Pointcut("target(foo)") + void pc9() {} + +} + +class OtherClass { + + @Pointcut("set(Integer *)") + void intSet() {}; + +}
\ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/PointcutModifiers.aj b/tests/java5/ataspectj/annotationGen/PointcutModifiers.aj new file mode 100644 index 000000000..88e1769cf --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/PointcutModifiers.aj @@ -0,0 +1,45 @@ +import org.aspectj.lang.reflect.*; +import java.lang.reflect.*; + +public abstract aspect PointcutModifiers { + + protected abstract pointcut p1(); + + pointcut p2(); + + public pointcut p3(): get(String s); + + protected pointcut p4() : set(String s); + + private pointcut p5() : call(* String.*(..)); + + public static void main(String[] args) throws NoSuchPointcutException { + AjType myType = AjTypeSystem.getAjType(PointcutModifiers.class); + assertTrue(myType != null, "found my type"); + Pointcut[] pointcuts = myType.getDeclaredPointcuts(); + assertTrue(pointcuts != null, "found some pointcuts"); + if (pointcuts.length != 5) throw new RuntimeException("Expecting 5 pointcuts"); + Pointcut pc1 = myType.getDeclaredPointcut("p1"); + assertTrue(pc1 != null, "found pc1"); + Pointcut pc2 = myType.getDeclaredPointcut("p2"); + assertTrue(pc2 != null, "found pc2"); + Pointcut pc3 = myType.getDeclaredPointcut("p3"); + assertTrue(pc3 != null, "found pc3"); + Pointcut pc4 = myType.getDeclaredPointcut("p4"); + assertTrue(pc4 != null, "found pc4"); + Pointcut pc5 = myType.getDeclaredPointcut("p5"); + assertTrue(pc5 != null, "found pc5"); + assertTrue(Modifier.isAbstract(pc1.getModifiers()),"pc1 is abstract" ); + assertTrue(Modifier.isProtected(pc1.getModifiers()),"pc1 is protected"); + assertTrue(!Modifier.isPrivate(pc2.getModifiers()),"pc2 not private"); + assertTrue(!Modifier.isPublic(pc2.getModifiers()),"pc2 not public"); + assertTrue(!Modifier.isProtected(pc2.getModifiers()),"pc2 not protected"); + assertTrue(Modifier.isPublic(pc3.getModifiers()),"pc3 is public"); + assertTrue(Modifier.isProtected(pc4.getModifiers()),"pc1 is protected"); + assertTrue(Modifier.isPrivate(pc5.getModifiers()),"pc5 is private"); + } + + private static void assertTrue(boolean expr, String msg) { + if (!expr) throw new RuntimeException(msg); + } +}
\ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/PointcutsWithParams.aj b/tests/java5/ataspectj/annotationGen/PointcutsWithParams.aj new file mode 100644 index 000000000..d6902c9ea --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/PointcutsWithParams.aj @@ -0,0 +1,23 @@ +import org.aspectj.lang.reflect.*; + +public aspect PointcutsWithParams { + + pointcut pc1(String s) : args(s); + + pointcut pc2(Integer i, Double d, String s) : args(i,d,s); + + public static void main(String[] args) throws NoSuchPointcutException { + AjType myType = AjTypeSystem.getAjType(PointcutsWithParams.class); + Pointcut p1 = myType.getPointcut("pc1"); + Class[] params = p1.getParameterTypes(); + if (params.length != 1) throw new RuntimeException("expecting one param"); + if (!params[0].equals(String.class)) throw new RuntimeException("expecting a String"); + Pointcut p2 = myType.getPointcut("pc2"); + params = p2.getParameterTypes(); + if (params.length != 3) throw new RuntimeException("expecting three params"); + if (!params[0].equals(Integer.class)) throw new RuntimeException("expecting an Integer"); + if (!params[1].equals(Double.class)) throw new RuntimeException("expecting a Double"); + if (!params[2].equals(String.class)) throw new RuntimeException("expecting a String"); + } + +}
\ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/PrivilegedAspect.aj b/tests/java5/ataspectj/annotationGen/PrivilegedAspect.aj new file mode 100644 index 000000000..50c850430 --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/PrivilegedAspect.aj @@ -0,0 +1,16 @@ +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.internal.lang.annotation.ajcPrivileged; +import java.lang.annotation.*; + +public privileged aspect PrivilegedAspect { + + public static void main(String[] args) { + Annotation[] annotations = PrivilegedAspect.class.getAnnotations(); + if (annotations.length != 2) throw new RuntimeException("Should have two annotations"); + Aspect aspectAnnotation = PrivilegedAspect.class.getAnnotation(Aspect.class); + if (!aspectAnnotation.value().equals("")) throw new RuntimeException("value should be empty"); + ajcPrivileged pAnnotation = PrivilegedAspect.class.getAnnotation(ajcPrivileged.class); + if (pAnnotation == null) throw new RuntimeException("Should be @ajcPrivileged"); + } + +}
\ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/ReferencePointcuts.aj b/tests/java5/ataspectj/annotationGen/ReferencePointcuts.aj new file mode 100644 index 000000000..782021b24 --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/ReferencePointcuts.aj @@ -0,0 +1,20 @@ +import org.aspectj.lang.reflect.*; + +public aspect ReferencePointcuts { + + pointcut pc1() : call(* *.*(..)); + + pointcut pc2() : pc1() || execution(* *.*(..)); + + public static void main(String[] args) throws NoSuchPointcutException { + AjType myType = AjTypeSystem.getAjType(ReferencePointcuts.class); + Pointcut p1 = myType.getPointcut("pc1"); + if (!p1.getPointcutExpression().equals("call(* *(..))")) + throw new RuntimeException("unexpected pc expression: " + p1.getPointcutExpression()); + Pointcut p2 = myType.getPointcut("pc2"); + if (!p2.getPointcutExpression().equals("(pc1() || execution(* *(..)))")) + throw new RuntimeException("unexpected pc expression: " + p2.getPointcutExpression()); + + } + +}
\ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/Simple14Aspect.aj b/tests/java5/ataspectj/annotationGen/Simple14Aspect.aj new file mode 100644 index 000000000..912d16de0 --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/Simple14Aspect.aj @@ -0,0 +1 @@ +public aspect Simple14Aspect {}
\ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/Simple14AspectTest.java b/tests/java5/ataspectj/annotationGen/Simple14AspectTest.java new file mode 100644 index 000000000..d92eb6198 --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/Simple14AspectTest.java @@ -0,0 +1,11 @@ +import org.aspectj.lang.annotation.Aspect; +import java.lang.annotation.*; + +public class Simple14AspectTest { + + public static void main(String[] args) { + Annotation[] annotations = Simple14Aspect.class.getAnnotations(); + if (annotations.length != 0) throw new RuntimeException("Should have no annotations"); + } + +}
\ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/SimpleAnnotatedAspect.aj b/tests/java5/ataspectj/annotationGen/SimpleAnnotatedAspect.aj new file mode 100644 index 000000000..376dee77d --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/SimpleAnnotatedAspect.aj @@ -0,0 +1,13 @@ +import org.aspectj.lang.annotation.Aspect; +import java.lang.annotation.*; +@Aspect +public class SimpleAnnotatedAspect { + + public static void main(String[] args) { + Annotation[] annotations = SimpleAnnotatedAspect.class.getAnnotations(); + if (annotations.length != 1) throw new RuntimeException("Should have one annotation"); + Aspect aspectAnnotation = (Aspect) annotations[0]; + if (!aspectAnnotation.value().equals("")) throw new RuntimeException("value should be empty"); + } + +}
\ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/SimpleAspect.aj b/tests/java5/ataspectj/annotationGen/SimpleAspect.aj new file mode 100644 index 000000000..34f6954dc --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/SimpleAspect.aj @@ -0,0 +1,13 @@ +import org.aspectj.lang.annotation.Aspect; +import java.lang.annotation.*; + +public aspect SimpleAspect { + + public static void main(String[] args) { + Annotation[] annotations = SimpleAspect.class.getAnnotations(); + if (annotations.length != 1) throw new RuntimeException("Should have one annotation"); + Aspect aspectAnnotation = (Aspect) annotations[0]; + if (!aspectAnnotation.value().equals("")) throw new RuntimeException("value should be empty"); + } + +}
\ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/SimplePointcut.aj b/tests/java5/ataspectj/annotationGen/SimplePointcut.aj new file mode 100644 index 000000000..e022f2b53 --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/SimplePointcut.aj @@ -0,0 +1,29 @@ +import java.lang.annotation.*; +import org.aspectj.lang.annotation.*; +import java.lang.reflect.*; + +public aspect SimplePointcut { + + pointcut myPointcut() : call(* String.*(..)); + + public static void main(String[] args) { + Method[] methods = SimplePointcut.class.getDeclaredMethods(); + boolean foundit = false; + for (Method method : methods) { + if (method.getName().startsWith("ajc$pointcut$")) { + if (foundit) throw new RuntimeException("Only expecting one pointcut method"); + foundit = true; + if (method.getName().indexOf("$myPointcut$") == -1) { + throw new RuntimeException("Pointcut name not captured"); + } + if (method.getAnnotations().length != 1) { + throw new RuntimeException("Expecting one annotation, found " + method.getAnnotations().length); + } + Pointcut pcAnn = method.getAnnotation(Pointcut.class); + if (!pcAnn.value().equals("call(* java.lang.String.*(..))")) + throw new RuntimeException("Pointcut expression not set correctly in annotation: " + pcAnn.value()); + } + } + } + +}
\ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/TwoForThePriceOfOne.java b/tests/java5/ataspectj/annotationGen/TwoForThePriceOfOne.java new file mode 100644 index 000000000..842f07ab1 --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/TwoForThePriceOfOne.java @@ -0,0 +1,10 @@ +import org.aspectj.lang.annotation.*; + +@Aspect +public class TwoForThePriceOfOne { + + @Before("execution(* *(..))") + @Pointcut("get(* *)") + public void logEntry() {} + +}
\ No newline at end of file diff --git a/tests/java5/ataspectj/ataspectj/PrecedenceTest.java b/tests/java5/ataspectj/ataspectj/PrecedenceTest.java index e488aa3c6..c5959fc4b 100644 --- a/tests/java5/ataspectj/ataspectj/PrecedenceTest.java +++ b/tests/java5/ataspectj/ataspectj/PrecedenceTest.java @@ -50,7 +50,7 @@ public class PrecedenceTest extends TestCase { @Aspect() public static class TestAspect_1 { @Before("execution(* ataspectj.PrecedenceTest.hello())") - void before() { + public void before() { log("TestAspect_1"); } } @@ -59,7 +59,7 @@ public class PrecedenceTest extends TestCase { @DeclarePrecedence("ataspectj.PrecedenceTest.TestAspect_3, ataspectj.PrecedenceTest.TestAspect_1") public static class TestAspect_2 { @Before("execution(* ataspectj.PrecedenceTest.hello())") - void before() { + public void before() { log("TestAspect_2"); } } @@ -67,7 +67,7 @@ public class PrecedenceTest extends TestCase { @Aspect() public static class TestAspect_3 { @Before("execution(* ataspectj.PrecedenceTest.hello())") - void before() { + public void before() { log("TestAspect_3"); } } diff --git a/tests/java5/ataspectj/ataspectj/XXJoinPointTest.java b/tests/java5/ataspectj/ataspectj/XXJoinPointTest.java index 168e2fbe6..d14eb8a03 100644 --- a/tests/java5/ataspectj/ataspectj/XXJoinPointTest.java +++ b/tests/java5/ataspectj/ataspectj/XXJoinPointTest.java @@ -57,33 +57,33 @@ public class XXJoinPointTest extends TestCase { void pc() {} @Before("pc()") - void before(JoinPoint jp) { + public void before(JoinPoint jp) { assertEquals("hello", jp.getSignature().getName()); log("jp"); } @Before("pc()") - void before(JoinPoint.StaticPart sjp) { + public void before(JoinPoint.StaticPart sjp) { assertEquals("hello", sjp.getSignature().getName()); log("sjp"); } @Before("pc()") - void beforeEnclosing(JoinPoint.EnclosingStaticPart esjp) { + public void beforeEnclosing(JoinPoint.EnclosingStaticPart esjp) { assertEquals("testJoinPointsInAdviceSignature", esjp.getSignature().getName()); log("esjp"); } //weird order @Before("pc()") - void beforeWEIRD1(JoinPoint jp, JoinPoint.StaticPart sjp) { + public void beforeWEIRD1(JoinPoint jp, JoinPoint.StaticPart sjp) { assertEquals("hello", jp.getSignature().getName()); assertEquals("hello", sjp.getSignature().getName()); log("jp-sjp"); } @Before("pc()") - void before(JoinPoint.StaticPart sjp, JoinPoint.EnclosingStaticPart esjp) { + public void before(JoinPoint.StaticPart sjp, JoinPoint.EnclosingStaticPart esjp) { assertEquals("hello", sjp.getSignature().getName()); assertEquals("testJoinPointsInAdviceSignature", esjp.getSignature().getName()); log("sjp-esjp"); @@ -91,7 +91,7 @@ public class XXJoinPointTest extends TestCase { // conventional order @Before("pc()") - void before(JoinPoint.StaticPart sjp, JoinPoint jp, JoinPoint.EnclosingStaticPart esjp) { + public void before(JoinPoint.StaticPart sjp, JoinPoint jp, JoinPoint.EnclosingStaticPart esjp) { assertEquals("hello", sjp.getSignature().getName()); assertEquals("hello", jp.getSignature().getName()); assertEquals("testJoinPointsInAdviceSignature", esjp.getSignature().getName()); @@ -100,7 +100,7 @@ public class XXJoinPointTest extends TestCase { // weird order @Before("pc()") - void beforeWEIRD2(JoinPoint.EnclosingStaticPart esjp, JoinPoint jp, JoinPoint.StaticPart sjp) { + public void beforeWEIRD2(JoinPoint.EnclosingStaticPart esjp, JoinPoint jp, JoinPoint.StaticPart sjp) { assertEquals("testJoinPointsInAdviceSignature", esjp.getSignature().getName()); assertEquals("hello", jp.getSignature().getName()); assertEquals("hello", sjp.getSignature().getName()); diff --git a/tests/java5/ataspectj/coverage/Test040.java b/tests/java5/ataspectj/coverage/Test040.java index 038ebff1e..b4ba98086 100644 --- a/tests/java5/ataspectj/coverage/Test040.java +++ b/tests/java5/ataspectj/coverage/Test040.java @@ -5,6 +5,7 @@ import org.aspectj.lang.annotation.*; class Foo{ } aspect A{ + @SuppressAjWarnings @Before("call(* org.aspectprogrammer..*(..)) && this(Foo)") public void callFromFoo() { System.out.println("Call from Foo"); diff --git a/tests/java5/ataspectj/coverage/Test041.java b/tests/java5/ataspectj/coverage/Test041.java index 28b1562d4..d444561a9 100644 --- a/tests/java5/ataspectj/coverage/Test041.java +++ b/tests/java5/ataspectj/coverage/Test041.java @@ -3,6 +3,7 @@ import org.aspectj.lang.annotation.*; aspect A{ + @SuppressAjWarnings @AdviceName("") before() : call(* org.aspectprogrammer..*(..)) { System.out.println("Call from Foo"); |