summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/java5/annotations/ajdkExamples/AnnotatingAspects.aj49
-rw-r--r--tests/java5/annotations/ajdkExamples/AnnotationInheritance.aj33
-rw-r--r--tests/java5/annotations/ajdkExamples/AnnotationPatternMatching.aj35
-rw-r--r--tests/java5/annotations/ajdkExamples/AnnotationsInSignaturePatterns.aj92
-rw-r--r--tests/java5/annotations/ajdkExamples/AnnotationsInTypePatterns.aj32
-rw-r--r--tests/java5/annotations/ajdkExamples/Cachable.java1
-rw-r--r--tests/java5/annotations/ajdkExamples/Catastrophic.java1
-rw-r--r--tests/java5/annotations/ajdkExamples/Classified.java1
-rw-r--r--tests/java5/annotations/ajdkExamples/Immutable.java1
-rw-r--r--tests/java5/annotations/ajdkExamples/NonPersistent.java4
-rw-r--r--tests/java5/annotations/ajdkExamples/Oneway.java1
-rw-r--r--tests/java5/annotations/ajdkExamples/Persisted.java1
-rw-r--r--tests/java5/annotations/ajdkExamples/RetentionTime.aj24
-rw-r--r--tests/java5/annotations/ajdkExamples/RuntimeTypeMatching.aj143
-rw-r--r--tests/java5/annotations/ajdkExamples/Secure.java1
-rw-r--r--tests/java5/annotations/ajdkExamples/SensitiveData.java1
-rw-r--r--tests/java5/annotations/ajdkExamples/SuppressAj.aj21
-rw-r--r--tests/java5/annotations/ajdkExamples/Transaction.java1
-rw-r--r--tests/java5/annotations/ajdkExamples/org/abc/Types.java5
-rw-r--r--tests/java5/annotations/ajdkExamples/org/xyz/OrgXYZAnnotation.java1
-rw-r--r--tests/java5/annotations/ajdkExamples/org/xyz/SignatureTypes.java32
-rw-r--r--tests/java5/annotations/ajdkExamples/org/xyz/Types.java8
-rw-r--r--tests/java5/annotations/aspectMembers/a/AnnotatedAspect05.aj27
-rw-r--r--tests/java5/annotations/aspectMembers/a/AnnotatedAspect06.aj22
-rw-r--r--tests/java5/annotations/aspectMembers/a/AnnotatedAspect07.aj11
-rw-r--r--tests/java5/annotations/aspectMembers/a/AnnotatedAspect08.aj27
-rw-r--r--tests/java5/annotations/aspectMembers/a/Annotations.java1
-rw-r--r--tests/src/org/aspectj/systemtest/ajc150/Annotations.java87
-rw-r--r--tests/src/org/aspectj/systemtest/ajc150/ajc150.xml130
29 files changed, 774 insertions, 19 deletions
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<Observer> Subject.observers;
+
+ @ITDMethodAnnotation
+ public void Subject.addObserver(Observer o) {
+ ((List<Observer>)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<Observer>)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 @@
<ajc-test dir="java5/annotations/aspectMembers" title="annotated advice">
<compile files="a/Annotations.java,a/AnnotatedAspect05.aj" options="-1.5">
+ <message kind="warning" line="16"/>
</compile>
</ajc-test>
<ajc-test dir="java5/annotations/aspectMembers" title="annotated advice with bad target">
<compile files="a/Annotations.java,a/AnnotatedAspect06.aj" options="-1.5">
+ <message kind="error" line="6" text="The annotation @ConstructorAnnotation is disallowed for this location"/>
</compile>
</ajc-test>
@@ -1021,5 +1023,133 @@
</compile>
</ajc-test>
+ <!-- ======================================================================================= -->
+ <!-- ajdk examples -->
+ <!-- ======================================================================================= -->
+ <ajc-test dir="java5/annotations/ajdkExamples" title="ajdk: annotating aspects chapter">
+ <compile files="AnnotatingAspects.aj" options="-1.5">
+ </compile>
+ </ajc-test>
+
+ <ajc-test dir="java5/annotations/ajdkExamples" title="ajdk: annotating aspects chapter, ex 2">
+ <compile files="SuppressAj.aj" options="-1.5">
+ </compile>
+ </ajc-test>
+
+ <ajc-test dir="java5/annotations/ajdkExamples" title="ajdk: annotation pattern matching">
+ <compile files="AnnotationPatternMatching.aj,org/xyz/OrgXYZAnnotation.java" options="-1.5">
+ <message kind="warning" line="25" text="@Immutable"/>
+ <message kind="warning" line="25" text="!@Persistent"/>
+ <message kind="warning" line="29" text="!@Persistent"/>
+ <message kind="warning" line="31" text="!@Persistent"/>
+ <message kind="warning" line="33" text="!@Persistent"/>
+ <message kind="warning" line="29" text="@Foo @Goo"/>
+ <message kind="warning" line="29" text="@(Foo || Goo)"/>
+ <message kind="warning" line="31" text="@(Foo || Goo)"/>
+ <message kind="warning" line="33" text="@(org.xyz..*)"/>
+ </compile>
+ </ajc-test>
+
+ <ajc-test dir="java5/annotations/ajdkExamples" title="ajdk: annotation type pattern matching">
+ <compile files="AnnotationsInTypePatterns.aj,org/xyz/OrgXYZAnnotation.java,org/xyz/Types.java,org/abc/Types.java,Immutable.java,NonPersistent.java" options="-1.5">
+ <message kind="warning" line="23" text="(@Immutable *)"/>
+ <message kind="warning" line="32" text="(@Immutable *)"/>
+ <message kind="warning" line="3" text="(@Immutable *)"/>
+ <message kind="warning" line="5" text="(@Immutable *)"/>
+ <message kind="warning" line="8" text="(@Immutable *)"/>
+ <message kind="warning" line="25" text="(!@Immutable *)"/>
+ <message kind="warning" line="27" text="(!@Immutable *)"/>
+ <message kind="warning" line="29" text="(!@Immutable *)"/>
+ <message kind="warning" line="5" text="(!@Immutable *)"/>
+ <message kind="warning" line="6" text="(!@Immutable *)"/>
+ <message kind="warning" line="2" text="(!@Immutable *)"/>
+ <message kind="warning" line="1" text="(!@Immutable *)"/>
+ <message kind="warning" line="4" text="(!@Immutable *)"/>
+ <message kind="warning" line="3" text="@Immutable (org.xyz.* || org.abc.*)"/>
+ <message kind="warning" line="5" text="@Immutable (org.xyz.* || org.abc.*)"/>
+ <message kind="warning" line="8" text="@Immutable (org.xyz.* || org.abc.*)"/>
+ <message kind="warning" line="32" text="((@Immutable Foo+) || Goo)"/>
+ <message kind="warning" line="27" text="((@Immutable Foo+) || Goo)"/>
+ <message kind="warning" line="3" text="@(Immutable || NonPersistent) org.xyz..*"/>
+ <message kind="warning" line="6" text="@(Immutable || NonPersistent) org.xyz..*"/>
+ <message kind="warning" line="8" text="@(Immutable || NonPersistent) org.xyz..*"/>
+ <message kind="warning" line="8" text="@Immutable @NonPersistent org.xyz..*"/>
+ <message kind="warning" line="6" text="@(@Inherited *) org.xyz..*"/>
+ </compile>
+ </ajc-test>
+
+ <ajc-test dir="java5/annotations/ajdkExamples" title="ajdk: annotations in sig patterns">
+ <compile files="AnnotationsInSignaturePatterns.aj,Cachable.java,SensitiveData.java,Persisted.java,Classified.java,Immutable.java,Secure.java,Catastrophic.java,Oneway.java,Transaction.java,org/xyz/SignatureTypes.java" options="-1.5">
+ <message kind="warning" line="32" text="@SensitiveData * *"/>
+ <message kind="warning" line="6" text="@SensitiveData * *"/>
+ <message kind="warning" line="12" text="@SensitiveData * *"/>
+ <message kind="warning" line="6" text="@SensitiveData List org.xyz..*.*"/>
+ <message kind="warning" line="10" text="(@SensitiveData *) org.xyz..*.*"/>
+ <message kind="warning" line="12" text="(@SensitiveData *) org.xyz..*.*"/>
+ <message kind="warning" line="50" text="@Foo (@Goo *) (@Hoo *).*"/>
+ <message kind="warning" line="38" text="@Persisted @Classified * *"/>
+
+ <message kind="warning" line="44" text="@Oneway * *(..)"/>
+ <message kind="warning" line="17" text="@Transaction * (@Persisted org.xyz..*).*(..)"/>
+ <message kind="warning" line="52" text="* *.*(@Immutable *,..)"/>
+ <message kind="warning" line="53" text="* *.*(@Immutable *,..)"/>
+ <message kind="warning" line="54" text="* *.*(@Immutable *,..)"/>
+
+ <message kind="warning" line="62" text="within(@Secure *)"/>
+ <message kind="warning" line="63" text="within(@Secure *)"/>
+ <message kind="warning" line="66" text="staticinitialization(@Persisted *)"/>
+ <message kind="warning" line="16" text="staticinitialization(@Persisted *)"/>
+ <message kind="warning" line="56" text="call(@Oneway * *(..))"/>
+ <message kind="warning" line="27" text="execution(public (@Immutable *) org.xyz..*.*(..))"/>
+ <message kind="warning" line="25" text="set(@Cachable * *)"/>
+ <message kind="warning" line="80" text="handler(!@Catastrophic *)"/>
+
+ </compile>
+ </ajc-test>
+
+ <ajc-test dir="java5/annotations/ajdkExamples" title="ajdk: runtime annotations">
+ <compile files="RuntimeTypeMatching.aj" options="-1.5">
+ <message kind="warning" line="122" text="@within(Foo)"/>
+ <message kind="warning" line="123" text="@within(Foo)"/>
+ </compile>
+ <run class="RuntimeTypeMatching">
+ <stdout>
+ <line text="This information is TOP-SECRET"/>
+ <line text="@target(Classified) at call(void A.a())"/>
+ <line text="@this(Foo) at execution(void B.b())"/>
+ <line text="This information is TOP-SECRET"/>
+ <line text="@target(Classified) at call(Class java.lang.Object.getClass())"/>
+ <line text="1 @Foo()"/>
+ <line text="1 @Foo()"/>
+ <line text="1 @Classified(classification=TOP-SECRET)"/>
+ <line text="This information is TOP-SECRET"/>
+ <line text="Entering critical join point with priority 3"/>
+ <line text="Entering critical join point with reflectively obtained priority 3"/>
+ <line text="@target(Classified) at call(void A.a())"/>
+ <line text="@this(Foo) at execution(void B.callA(A))"/>
+ <line text="(Class) Transaction required at execution(void ByeByeEJB.method1())"/>
+ <line text="(Method) Transaction required at execution(void ByeByeEJB.method1())"/>
+ <line text="(Class) Transaction required at execution(void ByeByeEJB.method2())"/>
+ <line text="(Method) Transaction required at execution(void ByeByeEJB.method2())"/>
+ <line text="(Class) Transaction required at execution(void ByeByeEJB.method3())"/>
+ </stdout>
+ </run>
+ </ajc-test>
+
+ <ajc-test dir="java5/annotations/ajdkExamples" title="ajdk: @retention checking">
+ <compile files="RetentionTime.aj" options="-1.5">
+ <message kind="error" line="8" text="Annotation type Goo does not have runtime retention"/>
+ <message kind="error" line="13" text="Annotation type Goo does not have runtime retention"/>
+ <message kind="error" line="18" text="Annotation type Goo does not have runtime retention"/>
+ </compile>
+ </ajc-test>
+
+ <ajc-test dir="java5/annotations/ajdkExamples" title="ajdk: @inherited">
+ <compile files="AnnotationInheritance.aj" options="-1.5">
+ <message kind="warning" line="16" text="annotatedMethodCall()"/>
+ <message kind="warning" line="16" text="c1MethodCall()"/>
+ <message kind="warning" line="17" text="c1MethodCall()"/>
+ </compile>
+ </ajc-test>
</suite>