From 69845b3545539b7961e8b4a3ef4a5ac416a305bb Mon Sep 17 00:00:00 2001 From: acolyer Date: Wed, 9 Mar 2005 11:18:05 +0000 Subject: [PATCH] test cases from ajdk:annotations chapter --- .../ajdkExamples/AnnotatingAspects.aj | 49 ++++++ .../ajdkExamples/AnnotationInheritance.aj | 33 ++++ .../ajdkExamples/AnnotationPatternMatching.aj | 35 +++++ .../AnnotationsInSignaturePatterns.aj | 92 +++++++++++ .../ajdkExamples/AnnotationsInTypePatterns.aj | 32 ++++ .../annotations/ajdkExamples/Cachable.java | 1 + .../ajdkExamples/Catastrophic.java | 1 + .../annotations/ajdkExamples/Classified.java | 1 + .../annotations/ajdkExamples/Immutable.java | 1 + .../ajdkExamples/NonPersistent.java | 4 + .../annotations/ajdkExamples/Oneway.java | 1 + .../annotations/ajdkExamples/Persisted.java | 1 + .../annotations/ajdkExamples/RetentionTime.aj | 24 +++ .../ajdkExamples/RuntimeTypeMatching.aj | 143 ++++++++++++++++++ .../annotations/ajdkExamples/Secure.java | 1 + .../ajdkExamples/SensitiveData.java | 1 + .../annotations/ajdkExamples/SuppressAj.aj | 21 +++ .../annotations/ajdkExamples/Transaction.java | 1 + .../ajdkExamples/org/abc/Types.java | 5 + .../org/xyz/OrgXYZAnnotation.java | 1 + .../ajdkExamples/org/xyz/SignatureTypes.java | 32 ++++ .../ajdkExamples/org/xyz/Types.java | 8 + .../aspectMembers/a/AnnotatedAspect05.aj | 27 ++++ .../aspectMembers/a/AnnotatedAspect06.aj | 22 +++ .../aspectMembers/a/AnnotatedAspect07.aj | 11 ++ .../aspectMembers/a/AnnotatedAspect08.aj | 27 ++++ .../aspectMembers/a/Annotations.java | 1 + .../systemtest/ajc150/Annotations.java | 87 ++++++++--- .../org/aspectj/systemtest/ajc150/ajc150.xml | 130 ++++++++++++++++ 29 files changed, 774 insertions(+), 19 deletions(-) create mode 100644 tests/java5/annotations/ajdkExamples/AnnotatingAspects.aj create mode 100644 tests/java5/annotations/ajdkExamples/AnnotationInheritance.aj create mode 100644 tests/java5/annotations/ajdkExamples/AnnotationPatternMatching.aj create mode 100644 tests/java5/annotations/ajdkExamples/AnnotationsInSignaturePatterns.aj create mode 100644 tests/java5/annotations/ajdkExamples/AnnotationsInTypePatterns.aj create mode 100644 tests/java5/annotations/ajdkExamples/Cachable.java create mode 100644 tests/java5/annotations/ajdkExamples/Catastrophic.java create mode 100644 tests/java5/annotations/ajdkExamples/Classified.java create mode 100644 tests/java5/annotations/ajdkExamples/Immutable.java create mode 100644 tests/java5/annotations/ajdkExamples/NonPersistent.java create mode 100644 tests/java5/annotations/ajdkExamples/Oneway.java create mode 100644 tests/java5/annotations/ajdkExamples/Persisted.java create mode 100644 tests/java5/annotations/ajdkExamples/RetentionTime.aj create mode 100644 tests/java5/annotations/ajdkExamples/RuntimeTypeMatching.aj create mode 100644 tests/java5/annotations/ajdkExamples/Secure.java create mode 100644 tests/java5/annotations/ajdkExamples/SensitiveData.java create mode 100644 tests/java5/annotations/ajdkExamples/SuppressAj.aj create mode 100644 tests/java5/annotations/ajdkExamples/Transaction.java create mode 100644 tests/java5/annotations/ajdkExamples/org/abc/Types.java create mode 100644 tests/java5/annotations/ajdkExamples/org/xyz/OrgXYZAnnotation.java create mode 100644 tests/java5/annotations/ajdkExamples/org/xyz/SignatureTypes.java create mode 100644 tests/java5/annotations/ajdkExamples/org/xyz/Types.java create mode 100644 tests/java5/annotations/aspectMembers/a/AnnotatedAspect05.aj create mode 100644 tests/java5/annotations/aspectMembers/a/AnnotatedAspect06.aj create mode 100644 tests/java5/annotations/aspectMembers/a/AnnotatedAspect07.aj create mode 100644 tests/java5/annotations/aspectMembers/a/AnnotatedAspect08.aj diff --git a/tests/java5/annotations/ajdkExamples/AnnotatingAspects.aj b/tests/java5/annotations/ajdkExamples/AnnotatingAspects.aj new file mode 100644 index 000000000..994dc4cfb --- /dev/null +++ b/tests/java5/annotations/ajdkExamples/AnnotatingAspects.aj @@ -0,0 +1,49 @@ +import java.util.List; + +@interface AspectAnnotation {} +@interface InterfaceAnnotation {} +@interface ITDFieldAnnotation {} +@interface ITDMethodAnnotation {} +@interface MethodAnnotation {} +@interface AdviceAnnotation {} + +@AspectAnnotation +public abstract aspect AnnotatingAspects { + + @InterfaceAnnotation + public interface Observer {} + + @InterfaceAnnotation + interface Subject {} + + @ITDFieldAnnotation + private List Subject.observers; + + @ITDMethodAnnotation + public void Subject.addObserver(Observer o) { + ((List)observers).add(o); // this cast will not be needed when generics are fixed + } + + @ITDMethodAnnotation + public void Subject.removeObserver(Observer o) { + observers.remove(o); + } + + @MethodAnnotation + private void notifyObservers(Subject subject) { + for(Observer o : (List)subject.observers) // this cast will not be needed when generics are fixed + notifyObserver(o,subject); + } + + @MethodAnnotation + protected abstract void notifyObserver(Observer o, Subject s); + + protected abstract pointcut observedEvent(Subject subject); + + @AdviceAnnotation + after(Subject subject) returning : observedEvent(subject) { + notifyObservers(subject); + } + + +} \ No newline at end of file diff --git a/tests/java5/annotations/ajdkExamples/AnnotationInheritance.aj b/tests/java5/annotations/ajdkExamples/AnnotationInheritance.aj new file mode 100644 index 000000000..68c14269f --- /dev/null +++ b/tests/java5/annotations/ajdkExamples/AnnotationInheritance.aj @@ -0,0 +1,33 @@ + import java.lang.annotation.*; + + class C1 { + @SomeAnnotation + public void aMethod() {} + } + + class C2 extends C1 { + public void aMethod() {} + } + + class Main { + public static void main(String[] args) { + C1 c1 = new C1(); + C2 c2 = new C2(); + c1.aMethod(); + c2.aMethod(); + } + } + + aspect X { + + pointcut annotatedMethodCall() : + call(@SomeAnnotation * C1.aMethod()); //CW L16 + + pointcut c1MethodCall() : // CW L16, L17 + call(* C1.aMethod()); + + declare warning : annotatedMethodCall() : "annotatedMethodCall()"; + declare warning : c1MethodCall() : "c1MethodCall()"; + } + + @Inherited @interface SomeAnnotation {} \ No newline at end of file diff --git a/tests/java5/annotations/ajdkExamples/AnnotationPatternMatching.aj b/tests/java5/annotations/ajdkExamples/AnnotationPatternMatching.aj new file mode 100644 index 000000000..23be9d785 --- /dev/null +++ b/tests/java5/annotations/ajdkExamples/AnnotationPatternMatching.aj @@ -0,0 +1,35 @@ +import org.xyz.*; + +public aspect AnnotationPatternMatching { + + declare warning : execution(@Immutable * *(..)) : "@Immutable"; + + declare warning : execution(!@Persistent * *(..)) : "!@Persistent"; + + declare warning : execution(@Foo @Goo * *(..)) : "@Foo @Goo"; + + declare warning : execution(@(Foo || Goo) * *(..)) : "@(Foo || Goo)"; + + declare warning : execution(@(org.xyz..*) * *(..)) : "@(org.xyz..*)"; + +} + +@interface Immutable {} +@interface Persistent {} +@interface Foo{} +@interface Goo{} + + +class Annotated { + + @Immutable void m1() {} + + @Persistent void m2() {} + + @Foo @Goo void m3() {} + + @Foo void m4() {} + + @OrgXYZAnnotation void m5() {} + +} \ No newline at end of file diff --git a/tests/java5/annotations/ajdkExamples/AnnotationsInSignaturePatterns.aj b/tests/java5/annotations/ajdkExamples/AnnotationsInSignaturePatterns.aj new file mode 100644 index 000000000..066eaef84 --- /dev/null +++ b/tests/java5/annotations/ajdkExamples/AnnotationsInSignaturePatterns.aj @@ -0,0 +1,92 @@ +import org.xyz.*; +//import org.abc.*; +import java.util.List; + +public aspect AnnotationsInSignaturePatterns { + + declare warning : set(@SensitiveData * *) : "@SensitiveData * *"; + declare warning : set(@SensitiveData List org.xyz..*.*) : "@SensitiveData List org.xyz..*.*"; + declare warning : set((@SensitiveData *) org.xyz..*.*) : "(@SensitiveData *) org.xyz..*.*"; + declare warning : set(@Foo (@Goo *) (@Hoo *).*) : "@Foo (@Goo *) (@Hoo *).*"; + declare warning : set(@Persisted @Classified * *) : "@Persisted @Classified * *"; + + declare warning : execution(@Oneway * *(..)) : "@Oneway * *(..)"; + declare warning : execution(@Transaction * (@Persisted org.xyz..*).*(..)) : "@Transaction * (@Persisted org.xyz..*).*(..)"; + declare warning : execution(* *.*(@Immutable *,..)) : "* *.*(@Immutable *,..)"; + + declare warning : within(@Secure *) : "within(@Secure *)"; + declare warning : staticinitialization(@Persisted *) : "staticinitialization(@Persisted *)"; + declare warning : call(@Oneway * *(..)) : "call(@Oneway * *(..))"; + declare warning : execution(public (@Immutable *) org.xyz..*.*(..)) : "execution(public (@Immutable *) org.xyz..*.*(..))"; + declare warning : set(@Cachable * *) : "set(@Cachable * *)"; + declare warning : handler(!@Catastrophic *) : "handler(!@Catastrophic *)"; + +} + +@interface Foo {} +@interface Goo {} +@interface Hoo {} + +class A { + + @SensitiveData int x = 1; + + @Persisted int y = 2; + + @Classified int z = 3; + + @Persisted @Classified int a = 99; +} + + +@Goo class G { + + @Oneway void g() {} + void g2() {} + +} +@Hoo class H { + + @Foo G g = new G(); + + void doIt(II i) {} + void doIt(II i, G g) {} + void doIt(II i, G g, H h) {} + void doIt(G g, H h) { + g.g(); + } +} + +@Immutable class II {} + +@Secure class S { + int i = 1; +} + +@Persisted class P {} + +@Catastrophic class NastyException extends Exception {} + +class OKException extends Exception {} + +class InError { + + public void ab() { + try { + a(); + b(); + } catch (NastyException nEx) { + ; + } catch (OKException okEx) { + ; + } + } + + private void a() throws NastyException { + throw new NastyException(); + } + + private void b() throws OKException { + throw new OKException(); + } +} \ No newline at end of file diff --git a/tests/java5/annotations/ajdkExamples/AnnotationsInTypePatterns.aj b/tests/java5/annotations/ajdkExamples/AnnotationsInTypePatterns.aj new file mode 100644 index 000000000..2348bce73 --- /dev/null +++ b/tests/java5/annotations/ajdkExamples/AnnotationsInTypePatterns.aj @@ -0,0 +1,32 @@ +import org.xyz.*; +import org.abc.*; +import java.lang.annotation.Inherited; + +public aspect AnnotationsInTypePatterns { + + declare warning : staticinitialization(@Immutable *) : "(@Immutable *)"; + + declare warning : staticinitialization(!@Immutable *) : "(!@Immutable *)"; + + declare warning : staticinitialization(@Immutable (org.xyz.* || org.abc.*)) : "@Immutable (org.xyz.* || org.abc.*)"; + + declare warning : staticinitialization((@Immutable Foo+) || Goo) : "((@Immutable Foo+) || Goo)"; + + declare warning : staticinitialization(@(Immutable || NonPersistent) org.xyz..*) : "@(Immutable || NonPersistent) org.xyz..*"; + + declare warning : staticinitialization(@Immutable @NonPersistent org.xyz..*) : "@Immutable @NonPersistent org.xyz..*"; + + declare warning : staticinitialization(@(@Inherited *) org.xyz..*) : "@(@Inherited *) org.xyz..*"; +} + +@Immutable +class A {} + +class B {} + +class Goo {} + +class Foo {} + +@Immutable +class SubFoo extends Foo {} \ No newline at end of file diff --git a/tests/java5/annotations/ajdkExamples/Cachable.java b/tests/java5/annotations/ajdkExamples/Cachable.java new file mode 100644 index 000000000..9cff589ce --- /dev/null +++ b/tests/java5/annotations/ajdkExamples/Cachable.java @@ -0,0 +1 @@ +public @interface Cachable {} \ No newline at end of file diff --git a/tests/java5/annotations/ajdkExamples/Catastrophic.java b/tests/java5/annotations/ajdkExamples/Catastrophic.java new file mode 100644 index 000000000..6af1fec42 --- /dev/null +++ b/tests/java5/annotations/ajdkExamples/Catastrophic.java @@ -0,0 +1 @@ +public @interface Catastrophic {} \ No newline at end of file diff --git a/tests/java5/annotations/ajdkExamples/Classified.java b/tests/java5/annotations/ajdkExamples/Classified.java new file mode 100644 index 000000000..381ae0c29 --- /dev/null +++ b/tests/java5/annotations/ajdkExamples/Classified.java @@ -0,0 +1 @@ +public @interface Classified {} \ No newline at end of file diff --git a/tests/java5/annotations/ajdkExamples/Immutable.java b/tests/java5/annotations/ajdkExamples/Immutable.java new file mode 100644 index 000000000..6a81edf5c --- /dev/null +++ b/tests/java5/annotations/ajdkExamples/Immutable.java @@ -0,0 +1 @@ +public @interface Immutable {} \ No newline at end of file diff --git a/tests/java5/annotations/ajdkExamples/NonPersistent.java b/tests/java5/annotations/ajdkExamples/NonPersistent.java new file mode 100644 index 000000000..6510066c1 --- /dev/null +++ b/tests/java5/annotations/ajdkExamples/NonPersistent.java @@ -0,0 +1,4 @@ +import java.lang.annotation.Inherited; + +@Inherited +public @interface NonPersistent {} \ No newline at end of file diff --git a/tests/java5/annotations/ajdkExamples/Oneway.java b/tests/java5/annotations/ajdkExamples/Oneway.java new file mode 100644 index 000000000..f9f965c92 --- /dev/null +++ b/tests/java5/annotations/ajdkExamples/Oneway.java @@ -0,0 +1 @@ +public @interface Oneway {} \ No newline at end of file diff --git a/tests/java5/annotations/ajdkExamples/Persisted.java b/tests/java5/annotations/ajdkExamples/Persisted.java new file mode 100644 index 000000000..28eb9a4ae --- /dev/null +++ b/tests/java5/annotations/ajdkExamples/Persisted.java @@ -0,0 +1 @@ +public @interface Persisted {} \ No newline at end of file diff --git a/tests/java5/annotations/ajdkExamples/RetentionTime.aj b/tests/java5/annotations/ajdkExamples/RetentionTime.aj new file mode 100644 index 000000000..f3c0722fb --- /dev/null +++ b/tests/java5/annotations/ajdkExamples/RetentionTime.aj @@ -0,0 +1,24 @@ +import java.lang.annotation.*; + +public aspect RetentionTime { + + pointcut withinType() : @within(Foo); + pointcut withinTypeBind(Foo foo) : @within(foo); + pointcut withinTypeClass() : @within(Goo); + pointcut withinTypeClassBind(Goo goo) : @within(goo); + + pointcut withincodeAnn() : @withincode(Foo); + pointcut withincodeAnnBind(Foo foo) : @withincode(foo); + pointcut withincodeAnnClass() : @withincode(Goo); + pointcut withincodeAnnBindClass(Goo goo) : @withincode(goo); + + pointcut atann() : @annotation(Foo); + pointcut atannBind(Foo foo) : @annotation(foo); + pointcut atannClass() : @annotation(Goo); + pointcut atannBindClass(Goo goo) : @annotation(goo); + +} + +@Retention(RetentionPolicy.RUNTIME) @interface Foo {} + +@interface Goo {} \ No newline at end of file diff --git a/tests/java5/annotations/ajdkExamples/RuntimeTypeMatching.aj b/tests/java5/annotations/ajdkExamples/RuntimeTypeMatching.aj new file mode 100644 index 000000000..16d85affc --- /dev/null +++ b/tests/java5/annotations/ajdkExamples/RuntimeTypeMatching.aj @@ -0,0 +1,143 @@ +import java.lang.annotation.*; +import java.lang.reflect.*; +import org.aspectj.lang.*; +import org.aspectj.lang.reflect.*; + +public aspect RuntimeTypeMatching { + + public static void main(String[] args) { + A a = new A(); + B b = new B(); + a.a(); + b.b(); + b.callA(a); + ByeByeEJB pojo = new ByeByeEJB(); + pojo.method1(); + pojo.method2(); + pojo.method3(); + } + + after() returning : @this(Foo) && execution(* A+.*(..)) { + System.out.println("@this(Foo) at " + thisJoinPoint.toString()); + } + + after() returning : call(* *(..)) && @target(Classified) { + System.out.println("@target(Classified) at " + thisJoinPoint.toString()); + } + + pointcut callToClassifiedObject(Classified classificationInfo) : + call(* *(..)) && @target(classificationInfo); + + before(Classified classification) : callToClassifiedObject(classification) { + System.out.println("This information is " + classification.classification()); + } + + pointcut txRequiredMethod(Tx transactionAnnotation) : + execution(* *(..)) && @this(transactionAnnotation) + && if(transactionAnnotation.policy() == TxPolicy.REQUIRED); + + before() : txRequiredMethod(Tx) { + System.out.println("(Class) Transaction required at " + thisJoinPoint); + } + + before(Tx tranAnn) : execution(* *(..)) && @annotation(tranAnn) && if(tranAnn.policy()==TxPolicy.REQUIRED) { + System.out.println("(Method) Transaction required at " + thisJoinPoint); + } + + /** + * matches any join point with at least one argument, and where the + * type of the first argument has the @Classified annotation + */ + pointcut classifiedArgument() : @args(Classified,..); + + before() : classifiedArgument() { + System.out.println("Classified data being passed at " + thisJoinPoint); + } + + /** + * matches any join point with three arguments, where the third + * argument has an annotation of type @Untrusted. + */ + pointcut untrustedData(Untrusted untrustedDataSource) : + @args(*,*,untrustedDataSource); + + before(Untrusted source) : untrustedData(source) { + System.out.println("Untrusted data being passed at " + thisJoinPoint); + if (source == null) System.out.println("FAIL"); + } + + before() : execution(* callA(..)) { + Annotation[] thisAnnotations = thisJoinPoint.getThis().getClass().getAnnotations(); + Annotation[] targetAnnotations = thisJoinPoint.getTarget().getClass().getAnnotations(); + Annotation[] firstParamAnnotations = thisJoinPoint.getArgs()[0].getClass().getAnnotations(); + + System.out.println(thisAnnotations.length + " " + thisAnnotations[0].toString()); + System.out.println(targetAnnotations.length + " " + targetAnnotations[0].toString()); + System.out.println(firstParamAnnotations.length + " " + firstParamAnnotations[0].toString()); + + } + + // up to @within and @withincode examples + declare warning : @within(Foo) && execution(* *(..)) : "@within(Foo)"; + + pointcut insideCriticalMethod(Critical c) : @withincode(c); + + before(Critical c) : insideCriticalMethod(c) { + System.out.println("Entering critical join point with priority " + c.priority()); + } + + before() : insideCriticalMethod(Critical) { + Signature sig = thisEnclosingJoinPointStaticPart.getSignature(); + AnnotatedElement declaringTypeAnnotationInfo = sig.getDeclaringType(); + if (sig instanceof MemberSignature) { + // this must be an initialization, pre-initialization, call, execution, get, or + // set join point. + AnnotatedElement memberAnnotationInfo = ((MemberSignature)sig).getAccessibleObject(); + Critical c = memberAnnotationInfo.getAnnotation(Critical.class); + System.out.println("Entering critical join point with reflectively obtained priority " + c.priority()); + } + } + +} + +@Retention(RetentionPolicy.RUNTIME) @interface Foo {} +@Retention(RetentionPolicy.RUNTIME) @interface Classified { + String classification() default "TOP-SECRET"; +} +@Retention(RetentionPolicy.RUNTIME) @interface Untrusted {} +@Retention(RetentionPolicy.RUNTIME) @interface Critical { + int priority() default 5; +} + +enum TxPolicy { REQUIRED, REQUIRESNEW } +@Retention(RetentionPolicy.RUNTIME) @interface Tx { + TxPolicy policy() default TxPolicy.REQUIRED; +} + +@Classified class A { + void a() {}; +} + +@Foo class B extends A { + void b() {}; + @Critical(priority=3) void callA(A a) { a.a(); } +} + +@Tx(policy=TxPolicy.REQUIRED) +class ByeByeEJB { + @Tx void method1() {} + @Tx(policy=TxPolicy.REQUIRED) void method2() {} + @Tx(policy=TxPolicy.REQUIRESNEW) void method3() {} +} + +@Untrusted class Dodgy {} + +class ToTrustOrNot { + + void a() { + b(5,2,new Dodgy()); + b(5,2,new String()); + } + + void b(int x, int y, Object o) {} +} \ No newline at end of file diff --git a/tests/java5/annotations/ajdkExamples/Secure.java b/tests/java5/annotations/ajdkExamples/Secure.java new file mode 100644 index 000000000..5d7e6870d --- /dev/null +++ b/tests/java5/annotations/ajdkExamples/Secure.java @@ -0,0 +1 @@ +public @interface Secure {} \ No newline at end of file diff --git a/tests/java5/annotations/ajdkExamples/SensitiveData.java b/tests/java5/annotations/ajdkExamples/SensitiveData.java new file mode 100644 index 000000000..71a64d4de --- /dev/null +++ b/tests/java5/annotations/ajdkExamples/SensitiveData.java @@ -0,0 +1 @@ +public @interface SensitiveData {} \ No newline at end of file diff --git a/tests/java5/annotations/ajdkExamples/SuppressAj.aj b/tests/java5/annotations/ajdkExamples/SuppressAj.aj new file mode 100644 index 000000000..40a9720d3 --- /dev/null +++ b/tests/java5/annotations/ajdkExamples/SuppressAj.aj @@ -0,0 +1,21 @@ + import org.aspectj.lang.annotation.SuppressAjWarnings; + + public aspect SuppressAj { + + pointcut anInterfaceOperation() : execution(* AnInterface.*(..)); + + + @SuppressAjWarnings // may not match if there are no implementers of the interface... + before() : anInterfaceOperation() { + // do something... + } + + @SuppressAjWarnings("adviceDidNotMatch") // alternate form + after() returning : anInterfaceOperation() { + // do something... + } + } + + interface AnInterface { + void foo(); + } \ No newline at end of file diff --git a/tests/java5/annotations/ajdkExamples/Transaction.java b/tests/java5/annotations/ajdkExamples/Transaction.java new file mode 100644 index 000000000..e41e0dd98 --- /dev/null +++ b/tests/java5/annotations/ajdkExamples/Transaction.java @@ -0,0 +1 @@ +public @interface Transaction {} \ No newline at end of file diff --git a/tests/java5/annotations/ajdkExamples/org/abc/Types.java b/tests/java5/annotations/ajdkExamples/org/abc/Types.java new file mode 100644 index 000000000..b0ed7f8e0 --- /dev/null +++ b/tests/java5/annotations/ajdkExamples/org/abc/Types.java @@ -0,0 +1,5 @@ + +class E {} + +@Immutable +class F {} \ No newline at end of file diff --git a/tests/java5/annotations/ajdkExamples/org/xyz/OrgXYZAnnotation.java b/tests/java5/annotations/ajdkExamples/org/xyz/OrgXYZAnnotation.java new file mode 100644 index 000000000..963617cbb --- /dev/null +++ b/tests/java5/annotations/ajdkExamples/org/xyz/OrgXYZAnnotation.java @@ -0,0 +1 @@ +public @interface OrgXYZAnnotation {} \ No newline at end of file diff --git a/tests/java5/annotations/ajdkExamples/org/xyz/SignatureTypes.java b/tests/java5/annotations/ajdkExamples/org/xyz/SignatureTypes.java new file mode 100644 index 000000000..d37157439 --- /dev/null +++ b/tests/java5/annotations/ajdkExamples/org/xyz/SignatureTypes.java @@ -0,0 +1,32 @@ +import java.util.List; +import java.util.ArrayList; + +class C { + + @SensitiveData List l = new ArrayList(); + + List l2 = new ArrayList(); + + D d = new D(); + + @SensitiveData D d2 = new D(); + +} + +@SensitiveData @Persisted class D { + @Transaction void update() {} + void read() {} +} + +@Immutable interface I {} + +class E { + + @Cachable Object expensive = null; + + public I getI() { + return null; + } + +} + diff --git a/tests/java5/annotations/ajdkExamples/org/xyz/Types.java b/tests/java5/annotations/ajdkExamples/org/xyz/Types.java new file mode 100644 index 000000000..4d0339328 --- /dev/null +++ b/tests/java5/annotations/ajdkExamples/org/xyz/Types.java @@ -0,0 +1,8 @@ + +@Immutable +class C {} + +@NonPersistent +class D {} + +@Immutable @NonPersistent class G {} \ No newline at end of file diff --git a/tests/java5/annotations/aspectMembers/a/AnnotatedAspect05.aj b/tests/java5/annotations/aspectMembers/a/AnnotatedAspect05.aj new file mode 100644 index 000000000..f54f15e8d --- /dev/null +++ b/tests/java5/annotations/aspectMembers/a/AnnotatedAspect05.aj @@ -0,0 +1,27 @@ +package a; + +import org.aspectj.lang.annotation.SuppressAjWarnings; + +@TypeAnnotation +public aspect AnnotatedAspect05 { + +// @ConstructorAnnotation +// before() : execution(* *(..)) {} + + @MethodAnnotation + @SuppressAjWarnings + after() returning : set(* *) {} + + @AnyAnnotation + after() throwing : get(* *) {} + + @MethodAnnotation + @SuppressAjWarnings + after() : handler(*) {} + + @MethodAnnotation + @SuppressAjWarnings + void around() : call(new(..)) { proceed(); } + +} + diff --git a/tests/java5/annotations/aspectMembers/a/AnnotatedAspect06.aj b/tests/java5/annotations/aspectMembers/a/AnnotatedAspect06.aj new file mode 100644 index 000000000..db964c903 --- /dev/null +++ b/tests/java5/annotations/aspectMembers/a/AnnotatedAspect06.aj @@ -0,0 +1,22 @@ +package a; + +@TypeAnnotation +public aspect AnnotatedAspect06 { + + @ConstructorAnnotation + before() : execution(* *(..)) {} + + @MethodAnnotation + after() returning : set(* *) {} + + @AnyAnnotation + after() throwing : get(* *) {} + + @MethodAnnotation + after() : handler(*) {} + + @MethodAnnotation + void around() : call(new(..)) { proceed(); } + +} + diff --git a/tests/java5/annotations/aspectMembers/a/AnnotatedAspect07.aj b/tests/java5/annotations/aspectMembers/a/AnnotatedAspect07.aj new file mode 100644 index 000000000..aedaf596b --- /dev/null +++ b/tests/java5/annotations/aspectMembers/a/AnnotatedAspect07.aj @@ -0,0 +1,11 @@ +package a; + +@TypeAnnotation +public aspect AnnotatedAspect07 { + + // should just compile harmlessly + + @AnyAnnotation + pointcut foo() : get(* *); +} + diff --git a/tests/java5/annotations/aspectMembers/a/AnnotatedAspect08.aj b/tests/java5/annotations/aspectMembers/a/AnnotatedAspect08.aj new file mode 100644 index 000000000..438af6e3f --- /dev/null +++ b/tests/java5/annotations/aspectMembers/a/AnnotatedAspect08.aj @@ -0,0 +1,27 @@ +package a; + +@TypeAnnotation +public aspect AnnotatedAspect08 { + + // should just compile harmlessly + + @AnyAnnotation + declare warning : get(* *) : "bah humbug"; + + @FieldAnnotation + declare error: set(* *) : "hum bahbug"; + + @AnyAnnotation + declare soft : execution(* *) : Exception; + + @ConstructorAnnotation + declare parents : A implements I; + + @AnyAnnotation + declare parents : A extends B; +} + +class A {} +class B {} +interface I {} + diff --git a/tests/java5/annotations/aspectMembers/a/Annotations.java b/tests/java5/annotations/aspectMembers/a/Annotations.java index 21a0bb1a7..16fef9a57 100644 --- a/tests/java5/annotations/aspectMembers/a/Annotations.java +++ b/tests/java5/annotations/aspectMembers/a/Annotations.java @@ -26,4 +26,5 @@ import java.lang.annotation.*; @Target(ElementType.TYPE) @interface TypeAnnotation {} +@Retention(RetentionPolicy.RUNTIME) @interface AnyAnnotation {} \ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/ajc150/Annotations.java b/tests/src/org/aspectj/systemtest/ajc150/Annotations.java index f8bc17ce1..5480d50a6 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/Annotations.java +++ b/tests/src/org/aspectj/systemtest/ajc150/Annotations.java @@ -11,6 +11,9 @@ package org.aspectj.systemtest.ajc150; import java.io.File; +import java.lang.annotation.Annotation; +import java.net.URL; +import java.net.URLClassLoader; import junit.framework.Test; @@ -75,35 +78,81 @@ public class Annotations extends XMLBasedAjcTestCase { } // more implementation work needed before this test passes -// public void testAnnotatedITDs() { -// runTest("annotated itds"); -// } + public void testAnnotatedITDs() { + runTest("annotated itds"); + } public void testAnnotatedITDsWithWrongAnnotationType() { runTest("annotated itds with bad target"); } -// these tests to be completed -// public void testAnnotatedAdvice() { -// runTest("annotated advice"); -// } -// -// public void testAnnotatedAdviceWithWrongAnnotationType() { -// runTest("annotated advice with bad target"); -// } -// -// public void testAnnotatedPointcut() { -// runTest("annotated pointcut"); -// } -// -// public void testAnnotatedDeclareStatements() { -// runTest("annotated declare statements"); -// } + public void testAnnotatedAdvice() { + runTest("annotated advice"); + try { + File classFile = new File(ajc.getSandboxDirectory(),"a/AnnotatedAspect05.class"); + ClassLoader cl = new URLClassLoader(new URL[] {ajc.getSandboxDirectory().toURI().toURL()}); + Class c = cl.loadClass("a.AnnotatedAspect05"); + Class ann = cl.loadClass("a.AnyAnnotation"); + java.lang.reflect.Method[] methods = c.getDeclaredMethods(); + for (int i = 0; i < methods.length; i++) { + if (methods[i].getName().startsWith("ajc$afterThrowing")) { + Annotation annotation = methods[i].getAnnotation(ann); + assertNotNull("Should have @AnyAnnotation",annotation); + } + } + } catch (Exception ex) { + fail(ex.getMessage()); + } + } + + public void testAnnotatedAdviceWithWrongAnnotationType() { + runTest("annotated advice with bad target"); + } + + public void testAnnotatedPointcut() { + runTest("annotated pointcut"); + } + + public void testAnnotatedDeclareStatements() { + runTest("annotated declare statements"); + } public void testBasicDeclareAnnotation() { runTest("basic declare annotation parse test"); } + public void testAJDKAnnotatingAspects() { + runTest("ajdk: annotating aspects chapter"); + } + + public void testAJDKAnnotatingAspects2() { + runTest("ajdk: annotating aspects chapter, ex 2"); + } + + public void testAnnotationPatterns() { + runTest("ajdk: annotation pattern matching"); + } + + public void testAnnotationTypePatterns() { + runTest("ajdk: annotation type pattern matching"); + } + + public void testAnnotationSigPatterns() { + runTest("ajdk: annotations in sig patterns"); + } + + public void testAnnotationRuntimeMatching() { + runTest("ajdk: runtime annotations"); + } + + public void testAnnotationRetentionChecking() { + runTest("ajdk: @retention checking"); + } + + public void testAnnotationInheritance() { + runTest("ajdk: @inherited"); + } + // helper methods..... public SyntheticRepository createRepos(File cpentry) { diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml index 5cf5084fa..6b7fad53e 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml @@ -994,11 +994,13 @@ + + @@ -1021,5 +1023,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.39.5