From fbd128789f6891089b0ab012ffbb9342211f3d74 Mon Sep 17 00:00:00 2001 From: aclement Date: Thu, 10 Mar 2005 11:58:28 +0000 Subject: [PATCH] Declare annotation: tons of testcode --- .../annotations/declare/AnnotatedType.java | 14 +++++++ .../java5/annotations/declare/BaseTypes.java | 19 +++++++++ .../java5/annotations/declare/BaseTypes2.java | 19 +++++++++ tests/java5/annotations/declare/Colored.java | 3 ++ .../annotations/declare/DeathByAnnotations.aj | 36 ++++++++++++++++++ .../declare/DecaDecpInteractions1.aj | 23 +++++++++++ .../declare/DecaDecpInteractions2.aj | 23 +++++++++++ .../declare/DecaDecpInteractions3.aj | 24 ++++++++++++ .../declare/DecaDecpInteractions4.aj | 24 ++++++++++++ .../java5/annotations/declare/DecaType1.java | 15 ++++++++ .../java5/annotations/declare/DecaType2.java | 20 ++++++++++ .../java5/annotations/declare/DecaType3.java | 21 ++++++++++ .../java5/annotations/declare/DecaTypeBin1.aj | 10 +++++ .../java5/annotations/declare/DecaTypeBin2.aj | 23 +++++++++++ .../java5/annotations/declare/DecaTypeBin3.aj | 19 +++++++++ .../java5/annotations/declare/DecaTypeBin4.aj | 17 +++++++++ .../java5/annotations/declare/DecaTypeBin5.aj | 34 +++++++++++++++++ .../java5/annotations/declare/DecaTypeBin6.aj | 30 +++++++++++++++ .../java5/annotations/declare/DecaTypeBin7.aj | 34 +++++++++++++++++ .../java5/annotations/declare/DecaTypeBin8.aj | 10 +++++ .../java5/annotations/declare/DecaTypeBin9.aj | 10 +++++ .../annotations/declare/EnumAndClassValues.aj | 27 +++++++++++++ .../annotations/declare/FunkyAnnotations.java | 9 +++++ tests/java5/annotations/declare/Temp.java | 13 +++++++ .../annotations/declare/atfield/AtField1.aj | 11 ++++++ .../annotations/declare/atfield/Base.java | 23 +++++++++++ .../annotations/declare/atfield/Colored.java | 2 + .../annotations/declare/atfield/Fruit.java | 2 + .../declare/atfield/RecursiveFields.aj | 11 ++++++ .../declare/atfield/RecursiveFields2.aj | 11 ++++++ .../declare/atfield/RightTarget.aj | 14 +++++++ .../declare/atfield/TwoOnOneField.aj | 11 ++++++ .../declare/atfield/TwoOnOneField2.aj | 14 +++++++ .../declare/atfield/WrongTarget.aj | 19 +++++++++ .../atfield/ignoreTypeNotExposed.properties | 2 + .../declare/atmethodctor/AtCtor1.aj | 10 +++++ .../declare/atmethodctor/AtMethod1.aj | 11 ++++++ .../declare/atmethodctor/Base.class | Bin 0 -> 1094 bytes .../declare/atmethodctor/Base.java | 24 ++++++++++++ .../declare/atmethodctor/Colored.class | Bin 0 -> 306 bytes .../declare/atmethodctor/Colored.java | 2 + .../declare/atmethodctor/Fruit.java | 2 + .../declare/atmethodctor/RightTarget.aj | 19 +++++++++ .../declare/atmethodctor/TwoOnOneMember.aj | 8 ++++ .../declare/atmethodctor/TwoOnOneMember2.aj | 23 +++++++++++ .../declare/atmethodctor/WrongTarget.aj | 13 +++++++ .../ignoreTypeNotExposed.properties | 2 + .../declare/ignoreTypeNotExposed.properties | 2 + 48 files changed, 713 insertions(+) create mode 100644 tests/java5/annotations/declare/AnnotatedType.java create mode 100644 tests/java5/annotations/declare/BaseTypes.java create mode 100644 tests/java5/annotations/declare/BaseTypes2.java create mode 100644 tests/java5/annotations/declare/Colored.java create mode 100644 tests/java5/annotations/declare/DeathByAnnotations.aj create mode 100644 tests/java5/annotations/declare/DecaDecpInteractions1.aj create mode 100644 tests/java5/annotations/declare/DecaDecpInteractions2.aj create mode 100644 tests/java5/annotations/declare/DecaDecpInteractions3.aj create mode 100644 tests/java5/annotations/declare/DecaDecpInteractions4.aj create mode 100644 tests/java5/annotations/declare/DecaType1.java create mode 100644 tests/java5/annotations/declare/DecaType2.java create mode 100644 tests/java5/annotations/declare/DecaType3.java create mode 100644 tests/java5/annotations/declare/DecaTypeBin1.aj create mode 100644 tests/java5/annotations/declare/DecaTypeBin2.aj create mode 100644 tests/java5/annotations/declare/DecaTypeBin3.aj create mode 100644 tests/java5/annotations/declare/DecaTypeBin4.aj create mode 100644 tests/java5/annotations/declare/DecaTypeBin5.aj create mode 100644 tests/java5/annotations/declare/DecaTypeBin6.aj create mode 100644 tests/java5/annotations/declare/DecaTypeBin7.aj create mode 100644 tests/java5/annotations/declare/DecaTypeBin8.aj create mode 100644 tests/java5/annotations/declare/DecaTypeBin9.aj create mode 100644 tests/java5/annotations/declare/EnumAndClassValues.aj create mode 100644 tests/java5/annotations/declare/FunkyAnnotations.java create mode 100644 tests/java5/annotations/declare/Temp.java create mode 100644 tests/java5/annotations/declare/atfield/AtField1.aj create mode 100644 tests/java5/annotations/declare/atfield/Base.java create mode 100644 tests/java5/annotations/declare/atfield/Colored.java create mode 100644 tests/java5/annotations/declare/atfield/Fruit.java create mode 100644 tests/java5/annotations/declare/atfield/RecursiveFields.aj create mode 100644 tests/java5/annotations/declare/atfield/RecursiveFields2.aj create mode 100644 tests/java5/annotations/declare/atfield/RightTarget.aj create mode 100644 tests/java5/annotations/declare/atfield/TwoOnOneField.aj create mode 100644 tests/java5/annotations/declare/atfield/TwoOnOneField2.aj create mode 100644 tests/java5/annotations/declare/atfield/WrongTarget.aj create mode 100644 tests/java5/annotations/declare/atfield/ignoreTypeNotExposed.properties create mode 100644 tests/java5/annotations/declare/atmethodctor/AtCtor1.aj create mode 100644 tests/java5/annotations/declare/atmethodctor/AtMethod1.aj create mode 100644 tests/java5/annotations/declare/atmethodctor/Base.class create mode 100644 tests/java5/annotations/declare/atmethodctor/Base.java create mode 100644 tests/java5/annotations/declare/atmethodctor/Colored.class create mode 100644 tests/java5/annotations/declare/atmethodctor/Colored.java create mode 100644 tests/java5/annotations/declare/atmethodctor/Fruit.java create mode 100644 tests/java5/annotations/declare/atmethodctor/RightTarget.aj create mode 100644 tests/java5/annotations/declare/atmethodctor/TwoOnOneMember.aj create mode 100644 tests/java5/annotations/declare/atmethodctor/TwoOnOneMember2.aj create mode 100644 tests/java5/annotations/declare/atmethodctor/WrongTarget.aj create mode 100644 tests/java5/annotations/declare/atmethodctor/ignoreTypeNotExposed.properties create mode 100644 tests/java5/annotations/declare/ignoreTypeNotExposed.properties diff --git a/tests/java5/annotations/declare/AnnotatedType.java b/tests/java5/annotations/declare/AnnotatedType.java new file mode 100644 index 000000000..ab76aadf4 --- /dev/null +++ b/tests/java5/annotations/declare/AnnotatedType.java @@ -0,0 +1,14 @@ +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) @interface Color { String value();} + +@Color("red") +public class AnnotatedType { + public static void main(String[] argv) { + new AnnotatedType().m(); + } + + public void m() { + System.err.println("m() running"); + } +} diff --git a/tests/java5/annotations/declare/BaseTypes.java b/tests/java5/annotations/declare/BaseTypes.java new file mode 100644 index 000000000..153d54526 --- /dev/null +++ b/tests/java5/annotations/declare/BaseTypes.java @@ -0,0 +1,19 @@ +public class BaseTypes { + + public static void main(String []argv) { + new A().m(); + new B().m(); + new C().m(); + } + +} + +class A { + public void m() { System.err.println("A.m() running");} +} + +class B extends A{ +} + +class C extends B{ +} diff --git a/tests/java5/annotations/declare/BaseTypes2.java b/tests/java5/annotations/declare/BaseTypes2.java new file mode 100644 index 000000000..153d54526 --- /dev/null +++ b/tests/java5/annotations/declare/BaseTypes2.java @@ -0,0 +1,19 @@ +public class BaseTypes { + + public static void main(String []argv) { + new A().m(); + new B().m(); + new C().m(); + } + +} + +class A { + public void m() { System.err.println("A.m() running");} +} + +class B extends A{ +} + +class C extends B{ +} diff --git a/tests/java5/annotations/declare/Colored.java b/tests/java5/annotations/declare/Colored.java new file mode 100644 index 000000000..0ec387c28 --- /dev/null +++ b/tests/java5/annotations/declare/Colored.java @@ -0,0 +1,3 @@ +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) public @interface Colored {String value();} diff --git a/tests/java5/annotations/declare/DeathByAnnotations.aj b/tests/java5/annotations/declare/DeathByAnnotations.aj new file mode 100644 index 000000000..7e04aed76 --- /dev/null +++ b/tests/java5/annotations/declare/DeathByAnnotations.aj @@ -0,0 +1,36 @@ +package p.q; +import java.lang.annotation.*; + + +@Retention(RetentionPolicy.RUNTIME) @interface Colored {String value();} +@Retention(RetentionPolicy.RUNTIME) @interface Fruit {String value();} +@Retention(RetentionPolicy.RUNTIME) @interface Material {String value();} + +aspect AllTogether { + + declare @type: DeathByAnnotations: @Colored("red"); + declare @method: * m*(..): @Fruit("tomato"); + declare @constructor: DeathByAnnotations.new(..): @Fruit("tomato"); + + declare @field: * DeathByAnnotations.*: @Material("wood"); + +} + +public class DeathByAnnotations { + int i; + static String s; + + public static void main(String[]argv) { + new DeathByAnnotations().i = 3; + s = "hello"; + new DeathByAnnotations().m1(); + new DeathByAnnotations(3).m2(); + } + + public DeathByAnnotations() {} + public DeathByAnnotations(int i) {} + + public void m1() {} + public void m2() {} + +} diff --git a/tests/java5/annotations/declare/DecaDecpInteractions1.aj b/tests/java5/annotations/declare/DecaDecpInteractions1.aj new file mode 100644 index 000000000..22f60ff8a --- /dev/null +++ b/tests/java5/annotations/declare/DecaDecpInteractions1.aj @@ -0,0 +1,23 @@ +import java.lang.annotation.*; + +interface Marker {} + +@Retention(RetentionPolicy.RUNTIME) @interface Color { String value();} + +// Color put on a particular type, marker interface added to any types with Color annotation +// Deca specified first +public aspect DecaDecpInteractions1 { + + declare @type: A : @Color("red"); + + declare parents: @Color * implements Marker; +} + +aspect X { + before(): execution(* *(..)) && this(Marker) { + System.err.println("Marker interface identified on "+thisJoinPoint); + } + before(): execution(* *(..)) && @this(Color) { + System.err.println("Color annotation identified on "+thisJoinPoint); + } +} diff --git a/tests/java5/annotations/declare/DecaDecpInteractions2.aj b/tests/java5/annotations/declare/DecaDecpInteractions2.aj new file mode 100644 index 000000000..200945972 --- /dev/null +++ b/tests/java5/annotations/declare/DecaDecpInteractions2.aj @@ -0,0 +1,23 @@ +import java.lang.annotation.*; + +interface Marker {} + +@Retention(RetentionPolicy.RUNTIME) @interface Color { String value();} + +// Color put on a particular type, marker interface added to any types with Color annotation +// Decp specified first +public aspect DecaDecpInteractions2 { + + declare parents: @Color * implements Marker; + + declare @type: A : @Color("red"); +} + +aspect X { + before(): execution(* *(..)) && this(Marker) { + System.err.println("Marker interface identified on "+thisJoinPoint); + } + before(): execution(* *(..)) && @this(Color) { + System.err.println("Color annotation identified on "+thisJoinPoint); + } +} diff --git a/tests/java5/annotations/declare/DecaDecpInteractions3.aj b/tests/java5/annotations/declare/DecaDecpInteractions3.aj new file mode 100644 index 000000000..6002c930c --- /dev/null +++ b/tests/java5/annotations/declare/DecaDecpInteractions3.aj @@ -0,0 +1,24 @@ +import java.lang.annotation.*; + +interface Marker {} + +@Retention(RetentionPolicy.RUNTIME) @interface Color { String value();} + +// Put the marker interface on a particular type and add the annotation on +// types with that interface. +// deca specified first +public aspect DecaDecpInteractions3 { + + declare @type: Marker+ : @Color("red"); + + declare parents: A* implements Marker; +} + +aspect X { + before(): execution(* *(..)) && this(Marker) { + System.err.println("Marker interface identified on "+thisJoinPoint); + } + before(): execution(* *(..)) && @this(Color) { + System.err.println("Color annotation identified on "+thisJoinPoint); + } +} diff --git a/tests/java5/annotations/declare/DecaDecpInteractions4.aj b/tests/java5/annotations/declare/DecaDecpInteractions4.aj new file mode 100644 index 000000000..4e442747b --- /dev/null +++ b/tests/java5/annotations/declare/DecaDecpInteractions4.aj @@ -0,0 +1,24 @@ +import java.lang.annotation.*; + +interface Marker {} + +@Retention(RetentionPolicy.RUNTIME) @interface Color { String value();} + +// Put the marker interface on a particular type and add the annotation on +// types with that interface. +// decp specified first +public aspect DecaDecpInteractions4 { + + declare parents: A* implements Marker; + + declare @type: Marker+ : @Color("red"); +} + +aspect X { + before(): execution(* *(..)) && this(Marker) { + System.err.println("Marker interface identified on "+thisJoinPoint); + } + before(): execution(* *(..)) && @this(Color) { + System.err.println("Color annotation identified on "+thisJoinPoint); + } +} diff --git a/tests/java5/annotations/declare/DecaType1.java b/tests/java5/annotations/declare/DecaType1.java new file mode 100644 index 000000000..ed0707ec1 --- /dev/null +++ b/tests/java5/annotations/declare/DecaType1.java @@ -0,0 +1,15 @@ +import java.lang.annotation.*; + +public class DecaType1 { + public static void main(String[] argv) { + Annotation a = DecaType1.class.getAnnotation(MyAnnotation.class); + System.err.println("annotation is "+a); + } +} + +aspect X { + declare @type: DecaType1 : @MyAnnotation; +} + +@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME) +@interface MyAnnotation {} diff --git a/tests/java5/annotations/declare/DecaType2.java b/tests/java5/annotations/declare/DecaType2.java new file mode 100644 index 000000000..19306daf1 --- /dev/null +++ b/tests/java5/annotations/declare/DecaType2.java @@ -0,0 +1,20 @@ +import java.lang.annotation.*; + +public class DecaType2 { + public static void main(String[] argv) { + Annotation a = DecaType2.class.getAnnotation(MyAnnotation.class); + System.err.println("annotation on DecaType2 is "+a); + a = X.class.getAnnotation(MyAnnotation.class); + System.err.println("annotation on X is "+a); + a = MyAnnotation.class.getAnnotation(MyAnnotation.class); + System.err.println("annotation on MyAnnotation is "+a); + } +} + +aspect X { + declare @type: * : @MyAnnotation; +} + +@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME) +@interface MyAnnotation {} + diff --git a/tests/java5/annotations/declare/DecaType3.java b/tests/java5/annotations/declare/DecaType3.java new file mode 100644 index 000000000..4a80ba36d --- /dev/null +++ b/tests/java5/annotations/declare/DecaType3.java @@ -0,0 +1,21 @@ +import java.lang.annotation.*; + +public class DecaType3 { + public static void main(String[] argv) { + new DecaType3().sayhello(); + } + public void sayhello() { + System.err.println("hello world"); + } +} + +aspect X { + declare @type: DecaType3 : @MyAnnotation; + + after(): call(* println(..)) && @this(MyAnnotation) { + System.err.println("advice running"); + } +} + +@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME) +@interface MyAnnotation {} diff --git a/tests/java5/annotations/declare/DecaTypeBin1.aj b/tests/java5/annotations/declare/DecaTypeBin1.aj new file mode 100644 index 000000000..57a2ac61a --- /dev/null +++ b/tests/java5/annotations/declare/DecaTypeBin1.aj @@ -0,0 +1,10 @@ + +public aspect DecaTypeBin1 { + declare @type: A : @Colored("red"); +} + +aspect X { + before(): execution(* *(..)) && @this(Colored) { + System.err.println("Color identified on "+this.getClass()); + } +} diff --git a/tests/java5/annotations/declare/DecaTypeBin2.aj b/tests/java5/annotations/declare/DecaTypeBin2.aj new file mode 100644 index 000000000..c43877c68 --- /dev/null +++ b/tests/java5/annotations/declare/DecaTypeBin2.aj @@ -0,0 +1,23 @@ +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) @interface ComplexAnnotation { + int ival(); + byte bval(); + char cval(); + long jval(); + double dval(); + boolean zval(); + short sval(); + float fval(); + String s(); +} + +public aspect DecaTypeBin2 { + declare @type: A : @ComplexAnnotation(ival=4,bval=2,cval=5,fval=3.0f,dval=33.4,zval=false,jval=56,sval=99,s="s"); +} + +aspect X { + before(): execution(* *(..)) && @this(ComplexAnnotation) { + System.err.println("ComplexAnnotation identified on "+thisJoinPoint); + } +} diff --git a/tests/java5/annotations/declare/DecaTypeBin3.aj b/tests/java5/annotations/declare/DecaTypeBin3.aj new file mode 100644 index 000000000..70c402ce1 --- /dev/null +++ b/tests/java5/annotations/declare/DecaTypeBin3.aj @@ -0,0 +1,19 @@ +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) @interface Color { String value();} +@Retention(RetentionPolicy.RUNTIME) @interface Fruit { String value();} + +public aspect DecaTypeBin3 { + declare @type: A : @Color("Yellow"); + declare @type: A : @Fruit("Banana"); +} + +aspect X { + before(): execution(* *(..)) && @this(Color) { + System.err.println("Color identified on "+thisJoinPoint); + } + + before(): execution(* *(..)) && @this(Fruit) { + System.err.println("Fruit identified on "+thisJoinPoint); + } +} diff --git a/tests/java5/annotations/declare/DecaTypeBin4.aj b/tests/java5/annotations/declare/DecaTypeBin4.aj new file mode 100644 index 000000000..85684e18a --- /dev/null +++ b/tests/java5/annotations/declare/DecaTypeBin4.aj @@ -0,0 +1,17 @@ +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) @interface Fruit { String value();} + +public aspect DecaTypeBin4 { + declare @type: AnnotatedType : @Fruit("Banana"); +} + +aspect X { + before(): execution(* *(..)) && @this(Color) { + System.err.println("Color identified on "+thisJoinPoint); + } + + before(): execution(* *(..)) && @this(Fruit) { + System.err.println("Fruit identified on "+thisJoinPoint); + } +} diff --git a/tests/java5/annotations/declare/DecaTypeBin5.aj b/tests/java5/annotations/declare/DecaTypeBin5.aj new file mode 100644 index 000000000..8fef8bbcd --- /dev/null +++ b/tests/java5/annotations/declare/DecaTypeBin5.aj @@ -0,0 +1,34 @@ +// Putting the wrong annotations onto types +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @interface ColorT { String value();} +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) @interface ColorM { String value();} +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.CONSTRUCTOR) @interface ColorC { String value();} +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.ANNOTATION_TYPE) @interface ColorA { String value();} +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) @interface ColorF { String value();} +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) @interface ColorP { String value();} +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.LOCAL_VARIABLE) @interface ColorL { String value();} +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PACKAGE) @interface ColorPkg { String value();} + +public aspect DecaTypeBin5 { + declare @type: A : @ColorT("Red"); + declare @type: A : @ColorM("Orange"); + declare @type: A : @ColorC("Yellow"); + declare @type: A : @ColorA("Green"); + declare @type: A : @ColorF("Blue"); + declare @type: A : @ColorP("Indigo"); + declare @type: A : @ColorL("Violet"); + declare @type: A : @ColorPkg("White"); +} + +aspect X { + before(): execution(* *(..)) && @this(ColorT) { System.err.println("ColorT identified on "+thisJoinPoint); } + before(): execution(* *(..)) && @this(ColorM) { System.err.println("ColorM identified on "+thisJoinPoint); } + before(): execution(* *(..)) && @this(ColorC) { System.err.println("ColorC identified on "+thisJoinPoint); } + before(): execution(* *(..)) && @this(ColorA) { System.err.println("ColorA identified on "+thisJoinPoint); } + before(): execution(* *(..)) && @this(ColorF) { System.err.println("ColorF identified on "+thisJoinPoint); } + before(): execution(* *(..)) && @this(ColorP) { System.err.println("ColorP identified on "+thisJoinPoint); } + before(): execution(* *(..)) && @this(ColorL) { System.err.println("ColorL identified on "+thisJoinPoint); } + before(): execution(* *(..)) && @this(ColorPkg) { System.err.println("ColorPkg identified on "+thisJoinPoint); } + +} diff --git a/tests/java5/annotations/declare/DecaTypeBin6.aj b/tests/java5/annotations/declare/DecaTypeBin6.aj new file mode 100644 index 000000000..bee04bc81 --- /dev/null +++ b/tests/java5/annotations/declare/DecaTypeBin6.aj @@ -0,0 +1,30 @@ +// Putting the wrong annotations on types but specifying patterns as the target +// rather than exact types +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @interface ColorT { String value();} +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) @interface ColorM { String value();} +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.CONSTRUCTOR) @interface ColorC { String value();} +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) @interface ColorF { String value();} +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) @interface ColorP { String value();} +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.LOCAL_VARIABLE) @interface ColorL { String value();} +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PACKAGE) @interface ColorPkg { String value();} + +public aspect DecaTypeBin6 { + declare @type: A+ : @ColorT("Red"); + declare @type: A* : @ColorM("Orange"); + declare @type: *A : @ColorC("Yellow"); + declare @type: *A+ : @ColorL("Green"); + declare @type: @ColorT * : @ColorF("Blue"); // also checks we loop correctly... +} + +aspect X { + before(): execution(* *(..)) && @this(ColorT) { System.err.println("ColorT identified on "+thisJoinPoint); } + before(): execution(* *(..)) && @this(ColorM) { System.err.println("ColorM identified on "+thisJoinPoint); } + before(): execution(* *(..)) && @this(ColorC) { System.err.println("ColorC identified on "+thisJoinPoint); } + before(): execution(* *(..)) && @this(ColorF) { System.err.println("ColorF identified on "+thisJoinPoint); } + before(): execution(* *(..)) && @this(ColorP) { System.err.println("ColorP identified on "+thisJoinPoint); } + before(): execution(* *(..)) && @this(ColorL) { System.err.println("ColorL identified on "+thisJoinPoint); } + before(): execution(* *(..)) && @this(ColorPkg) { System.err.println("ColorPkg identified on "+thisJoinPoint); } + +} diff --git a/tests/java5/annotations/declare/DecaTypeBin7.aj b/tests/java5/annotations/declare/DecaTypeBin7.aj new file mode 100644 index 000000000..db625b6fb --- /dev/null +++ b/tests/java5/annotations/declare/DecaTypeBin7.aj @@ -0,0 +1,34 @@ +// Putting the wrong annotations on types but specifying patterns as the target +// rather than exact types +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) @interface Color { String value();} +@Retention(RetentionPolicy.RUNTIME) @interface Fruit { String value();} +@Retention(RetentionPolicy.RUNTIME) @interface Chocolate { String value();} + +interface M1 {} +interface M2 {} +interface M3 {} + +// sick and twisted +public aspect DecaTypeBin7 { + declare parents: @Chocolate * implements M3; + declare @type: A : @Color("Red"); + declare @type: M1+ : @Fruit("Banana"); + declare parents: @Color * implements M1; + declare @type: M2+ : @Chocolate("maltesers"); + declare parents: @Fruit * implements M2; + + public void B.m() { System.err.println("B.m() running"); } + public void C.m() { System.err.println("C.m() running"); } +} + +aspect X { + before(): execution(* *(..)) && @this(Color) { System.err.println("Color identified on "+thisJoinPoint); } + before(): execution(* *(..)) && @this(Fruit) { System.err.println("Fruit identified on "+thisJoinPoint); } + before(): execution(* *(..)) && @this(Chocolate) { System.err.println("Chocolate identified on "+thisJoinPoint); } + before(): execution(* *(..)) && target(M1) { System.err.println("M1 at "+thisJoinPoint); } + before(): execution(* *(..)) && target(M2) { System.err.println("M2 at "+thisJoinPoint); } + before(): execution(* *(..)) && target(M3) { System.err.println("M3 at "+thisJoinPoint); } + +} diff --git a/tests/java5/annotations/declare/DecaTypeBin8.aj b/tests/java5/annotations/declare/DecaTypeBin8.aj new file mode 100644 index 000000000..c777c83eb --- /dev/null +++ b/tests/java5/annotations/declare/DecaTypeBin8.aj @@ -0,0 +1,10 @@ +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @interface ColorT { String value();} +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.ANNOTATION_TYPE) @interface ColorA { String value();} + +public aspect DecaTypeBin8 { + declare @type: A : @ColorT("Red"); + declare @type: A : @ColorA("Green"); +} + diff --git a/tests/java5/annotations/declare/DecaTypeBin9.aj b/tests/java5/annotations/declare/DecaTypeBin9.aj new file mode 100644 index 000000000..f875df160 --- /dev/null +++ b/tests/java5/annotations/declare/DecaTypeBin9.aj @@ -0,0 +1,10 @@ +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @interface ColorT { String value();} +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.ANNOTATION_TYPE) @interface ColorA { String value();} + +public aspect DecaTypeBin9 { + declare @type: A* : @ColorT("Red"); + declare @type: A* : @ColorA("Green"); +} + diff --git a/tests/java5/annotations/declare/EnumAndClassValues.aj b/tests/java5/annotations/declare/EnumAndClassValues.aj new file mode 100644 index 000000000..9090a0154 --- /dev/null +++ b/tests/java5/annotations/declare/EnumAndClassValues.aj @@ -0,0 +1,27 @@ +import java.lang.annotation.*; + +enum SimpleEnum { Red,Orange,Yellow,Green,Blue,Indigo,Violet }; + +@Retention(RetentionPolicy.RUNTIME) +@interface AnnotationEnumElement { + SimpleEnum enumval(); +} + +@Retention(RetentionPolicy.RUNTIME) +@interface AnnotationClassElement { + Class clz(); +} + + +aspect AnnotatedWithEnumClass { + declare @type: FunkyAnnotations : @AnnotationEnumElement(enumval=SimpleEnum.Red); + declare @type: FunkyAnnotations : @AnnotationClassElement(clz=Integer.class); + + before(AnnotationEnumElement aee): call(* *(..)) && @target(aee) { + System.err.println("advice running: "+aee.enumval()); + } + + before(AnnotationClassElement ace): call(* *(..)) && @target(ace) { + System.err.println("advice running: "+ace.clz()); + } +} diff --git a/tests/java5/annotations/declare/FunkyAnnotations.java b/tests/java5/annotations/declare/FunkyAnnotations.java new file mode 100644 index 000000000..91460e44b --- /dev/null +++ b/tests/java5/annotations/declare/FunkyAnnotations.java @@ -0,0 +1,9 @@ +public class FunkyAnnotations { + + public static void main(String[] argv) { + new FunkyAnnotations().m(); + } + public void m() { + System.err.println("method running"); + } +} diff --git a/tests/java5/annotations/declare/Temp.java b/tests/java5/annotations/declare/Temp.java new file mode 100644 index 000000000..c42536610 --- /dev/null +++ b/tests/java5/annotations/declare/Temp.java @@ -0,0 +1,13 @@ +import java.lang.annotation.*; + +enum SimpleEnum { Red,Orange,Yellow,Green,Blue,Indigo,Violet }; + +@Retention(RetentionPolicy.RUNTIME) +@interface AnnotationEnumElement { + SimpleEnum enumval(); +} + + +@AnnotationEnumElement(enumval=SimpleEnum.Red) +class C { +} diff --git a/tests/java5/annotations/declare/atfield/AtField1.aj b/tests/java5/annotations/declare/atfield/AtField1.aj new file mode 100644 index 000000000..98cda93b5 --- /dev/null +++ b/tests/java5/annotations/declare/atfield/AtField1.aj @@ -0,0 +1,11 @@ +//Simple declare annotation attached to a field +public aspect AtField1 { + declare @field: public int * : @Colored("red"); + declare parents: AtField1 implements java.io.Serializable; +} + +aspect X { + before(): set(@Colored * *) { + System.err.println("Colored field access at "+thisJoinPoint); + } +} diff --git a/tests/java5/annotations/declare/atfield/Base.java b/tests/java5/annotations/declare/atfield/Base.java new file mode 100644 index 000000000..354c62232 --- /dev/null +++ b/tests/java5/annotations/declare/atfield/Base.java @@ -0,0 +1,23 @@ +import java.util.*; + +public class Base { + + public int publicIntField; + + private String privateStringField; + + public List publicListField; + + protected List protectedListField; + + public static void main(String[]argv) { + new Base().x(); + } + + public void x() { + publicIntField = 1; + privateStringField = "aaa"; + publicListField = new ArrayList(); + protectedListField = new ArrayList(); + } +} diff --git a/tests/java5/annotations/declare/atfield/Colored.java b/tests/java5/annotations/declare/atfield/Colored.java new file mode 100644 index 000000000..01feb0cf8 --- /dev/null +++ b/tests/java5/annotations/declare/atfield/Colored.java @@ -0,0 +1,2 @@ +import java.lang.annotation.*; +@Retention(RetentionPolicy.RUNTIME) public @interface Colored {String value();} diff --git a/tests/java5/annotations/declare/atfield/Fruit.java b/tests/java5/annotations/declare/atfield/Fruit.java new file mode 100644 index 000000000..78d60bbe7 --- /dev/null +++ b/tests/java5/annotations/declare/atfield/Fruit.java @@ -0,0 +1,2 @@ +import java.lang.annotation.*; +@Retention(RetentionPolicy.RUNTIME) public @interface Fruit {String value();} diff --git a/tests/java5/annotations/declare/atfield/RecursiveFields.aj b/tests/java5/annotations/declare/atfield/RecursiveFields.aj new file mode 100644 index 000000000..46eae711f --- /dev/null +++ b/tests/java5/annotations/declare/atfield/RecursiveFields.aj @@ -0,0 +1,11 @@ +// check order of application - this should work +public aspect RecursiveFields { + declare @field: public int * : @Colored("blue"); + declare @field: @Colored * * : @Fruit("orange"); +} + +aspect X { + before(): set(@Fruit * *) { + System.err.println("Fruit field access at "+thisJoinPoint); + } +} diff --git a/tests/java5/annotations/declare/atfield/RecursiveFields2.aj b/tests/java5/annotations/declare/atfield/RecursiveFields2.aj new file mode 100644 index 000000000..b695e0813 --- /dev/null +++ b/tests/java5/annotations/declare/atfield/RecursiveFields2.aj @@ -0,0 +1,11 @@ +// check order of application - this should work +public aspect RecursiveFields2 { + declare @field: @Colored * * : @Fruit("orange"); + declare @field: public int * : @Colored("blue"); +} + +aspect X { + before(): set(@Fruit * *) { + System.err.println("Fruit field access at "+thisJoinPoint); + } +} diff --git a/tests/java5/annotations/declare/atfield/RightTarget.aj b/tests/java5/annotations/declare/atfield/RightTarget.aj new file mode 100644 index 000000000..9a8d2c3b5 --- /dev/null +++ b/tests/java5/annotations/declare/atfield/RightTarget.aj @@ -0,0 +1,14 @@ +// trying to put annotations on that correctly use @Target +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) @interface FieldColoring { String value(); } + +public aspect RightTarget { + declare @field: public int * : @FieldColoring("red"); +} + +aspect X { + before(): set(@FieldColoring * *) { + System.err.println("Colored field access at "+thisJoinPoint); + } +} diff --git a/tests/java5/annotations/declare/atfield/TwoOnOneField.aj b/tests/java5/annotations/declare/atfield/TwoOnOneField.aj new file mode 100644 index 000000000..d0f37b6b3 --- /dev/null +++ b/tests/java5/annotations/declare/atfield/TwoOnOneField.aj @@ -0,0 +1,11 @@ +// trying to put two annotations onto one field +public aspect TwoOnOneField { + declare @field: public int * : @Colored("red"); + declare @field: public int * : @Colored("blue"); +} + +aspect X { + before(): set(@Colored * *) { + System.err.println("Colored field access at "+thisJoinPoint); + } +} diff --git a/tests/java5/annotations/declare/atfield/TwoOnOneField2.aj b/tests/java5/annotations/declare/atfield/TwoOnOneField2.aj new file mode 100644 index 000000000..d886eb2c1 --- /dev/null +++ b/tests/java5/annotations/declare/atfield/TwoOnOneField2.aj @@ -0,0 +1,14 @@ +// trying to put two annotations onto one field - should be OK, they are diff annotations +public aspect TwoOnOneField2 { + declare @field: public int * : @Colored("yellow"); + declare @field: public int * : @Fruit("banana"); +} + +aspect X { + before(): set(@Colored * *) { + System.err.println("Colored field access at "+thisJoinPoint); + } + before(): set(@Fruit * *) { + System.err.println("Fruit field access at "+thisJoinPoint); + } +} diff --git a/tests/java5/annotations/declare/atfield/WrongTarget.aj b/tests/java5/annotations/declare/atfield/WrongTarget.aj new file mode 100644 index 000000000..f82eae4b8 --- /dev/null +++ b/tests/java5/annotations/declare/atfield/WrongTarget.aj @@ -0,0 +1,19 @@ +// trying to put wrong annotations onto a field +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) @interface MethodColoring { String value(); } +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @interface TypeColoring { String value(); } + +public aspect WrongTarget { + declare @field: public int * : @MethodColoring("red"); + declare @field: public int * : @TypeColoring("blue"); +} + +aspect X { + before(): set(@MethodColoring * *) { + System.err.println("Colored field access at "+thisJoinPoint); + } + before(): set(@TypeColoring * *) { + System.err.println("Colored field access at "+thisJoinPoint); + } +} diff --git a/tests/java5/annotations/declare/atfield/ignoreTypeNotExposed.properties b/tests/java5/annotations/declare/atfield/ignoreTypeNotExposed.properties new file mode 100644 index 000000000..a0b22a340 --- /dev/null +++ b/tests/java5/annotations/declare/atfield/ignoreTypeNotExposed.properties @@ -0,0 +1,2 @@ +typeNotExposedToWeaver=ignore +adviceDidNotMatch=ignore diff --git a/tests/java5/annotations/declare/atmethodctor/AtCtor1.aj b/tests/java5/annotations/declare/atmethodctor/AtCtor1.aj new file mode 100644 index 000000000..f3d690358 --- /dev/null +++ b/tests/java5/annotations/declare/atmethodctor/AtCtor1.aj @@ -0,0 +1,10 @@ + +public aspect AtCtor1 { + declare @constructor: new(int) : @Colored("red"); +} + +aspect X { + before(): call(new(..)) && @annotation(Colored) { + System.err.println("Colored constructor invocation at "+thisJoinPoint); + } +} diff --git a/tests/java5/annotations/declare/atmethodctor/AtMethod1.aj b/tests/java5/annotations/declare/atmethodctor/AtMethod1.aj new file mode 100644 index 000000000..3b9eae181 --- /dev/null +++ b/tests/java5/annotations/declare/atmethodctor/AtMethod1.aj @@ -0,0 +1,11 @@ + +public aspect AtMethod1 { + declare @method: void m1(..) : @Colored("red"); + +} + +aspect X { + before(Colored c): call(* *(..)) && @annotation(c) { + System.err.println("Colored method invocation at "+thisJoinPoint); + } +} diff --git a/tests/java5/annotations/declare/atmethodctor/Base.class b/tests/java5/annotations/declare/atmethodctor/Base.class new file mode 100644 index 0000000000000000000000000000000000000000..045cae2853f0765ad2eb29b5c6a6b9cd025a4fcd GIT binary patch literal 1094 zcmZva+iuf95QhKF$#pPInx^3l1qwI;9MW(O;-W=JmBK*^iiEh@q^s0XY*&sG;IZH$ zMIiA2JQQMP9VxD`rCsmL&VKvP?ELxr^EZGNo(kmliBS%h;X>06!R&uUF=Z%Vvg2Pv8IFX@@+`#X;zIr?J1}Y@>esHKx zfqP%4k@5_f#8e@LY<2amZqR%mx_;D)LM6S9g)^{B6meF-@>+I%JDmBx>yOq@64*>R zVqinSIA+GgC#)TFbv6X0qn&!+!X~OkRInvbS_%Ci2NRN6=>|hN>C4b%d+E$YNA6Uh z(B(39xE#AIX*Vh9GP~RCZYSN>r~saHNlnfElqQF;FI?Y^UQ(ca!18Wlr-%%035YKi z?x4VyP1`aY%_;E|jD>t0cF)44c;#5Q8m}HOk{~&dYT?p25GeM7SvXX$T~6BMyc{kl zuG3vPY72ncfvIF0WU()gHJaPx5%f2|W4%&dp!SW749?M9&>MN2r?nLa;Q}s_m19{6 zRN;Trl@wGV1!Zzx36!Bxb@K41Rc)uB42|L-lajoV0GJx^99gZ{`i0EL!U=9KP+w)n zPXOvi>d1s73k}>Qzu;F&5Z5(vkNjLHtFgd+8qFVQt%wy}(h|*Oirye{v&zWp&B%;3pC DEGV3z literal 0 HcmV?d00001 diff --git a/tests/java5/annotations/declare/atmethodctor/Base.java b/tests/java5/annotations/declare/atmethodctor/Base.java new file mode 100644 index 000000000..e6c83902c --- /dev/null +++ b/tests/java5/annotations/declare/atmethodctor/Base.java @@ -0,0 +1,24 @@ +import java.util.*; + +public class Base { + + public void m1() { System.err.println("m1() running");} + protected void m2() { System.err.println("m2() running");} + public static void m3() { System.err.println("m3() running");} + + public static void main(String[]argv) { + // new Base().x(); + new Base(3).x(); + } + + public void x() { + m1(); + m2(); + m3(); + } + + public Base() {} + + public Base(int i) {} + +} diff --git a/tests/java5/annotations/declare/atmethodctor/Colored.class b/tests/java5/annotations/declare/atmethodctor/Colored.class new file mode 100644 index 0000000000000000000000000000000000000000..df3572bfebaaa768ed0c862b01f2aad0e07589fe GIT binary patch literal 306 zcmaiwyJ|u~5QhKplJy!bY*NKaOp}9ksvrpjyo6)4Uyp;Vth;dBBlv0-K0qESI0@ph zOEEJ)GvE9J^Zj!?0T`e~P(yEh$}0sTv^RRMBdgsynl3k-1cf5uG4E>Ue9*yo7rkDk zLYYwBYnw5l(|;P}{4Au#tzQVWna|RM-;EWfak=^Y3lbjU%muUMh1r><<=l8j=-!y! z9FIA$?06^Ey?>BTZ%uL#P{s4f*T?v+M<}2K!ks*UN-{u2Q~}k$Tti)IQ|1i`#Uk&| D{H;@K literal 0 HcmV?d00001 diff --git a/tests/java5/annotations/declare/atmethodctor/Colored.java b/tests/java5/annotations/declare/atmethodctor/Colored.java new file mode 100644 index 000000000..01feb0cf8 --- /dev/null +++ b/tests/java5/annotations/declare/atmethodctor/Colored.java @@ -0,0 +1,2 @@ +import java.lang.annotation.*; +@Retention(RetentionPolicy.RUNTIME) public @interface Colored {String value();} diff --git a/tests/java5/annotations/declare/atmethodctor/Fruit.java b/tests/java5/annotations/declare/atmethodctor/Fruit.java new file mode 100644 index 000000000..78d60bbe7 --- /dev/null +++ b/tests/java5/annotations/declare/atmethodctor/Fruit.java @@ -0,0 +1,2 @@ +import java.lang.annotation.*; +@Retention(RetentionPolicy.RUNTIME) public @interface Fruit {String value();} diff --git a/tests/java5/annotations/declare/atmethodctor/RightTarget.aj b/tests/java5/annotations/declare/atmethodctor/RightTarget.aj new file mode 100644 index 000000000..4ed1ec74a --- /dev/null +++ b/tests/java5/annotations/declare/atmethodctor/RightTarget.aj @@ -0,0 +1,19 @@ +// trying to put annotations on that correctly use @Target +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) @interface MethodColoring { String value(); } +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.CONSTRUCTOR) @interface CtorColoring { String value(); } + +public aspect RightTarget { + declare @method: public void m1(..) : @MethodColoring("red"); + declare @constructor: public new(int) : @CtorColoring("red"); +} + +aspect X { + before(): call(* *(..)) && @annotation(MethodColoring) { + System.err.println("Colored method call at "+thisJoinPoint); + } + before(): call(new(..)) && @annotation(CtorColoring) { + System.err.println("Colored ctor call at "+thisJoinPoint); + } +} diff --git a/tests/java5/annotations/declare/atmethodctor/TwoOnOneMember.aj b/tests/java5/annotations/declare/atmethodctor/TwoOnOneMember.aj new file mode 100644 index 000000000..abc2f0c61 --- /dev/null +++ b/tests/java5/annotations/declare/atmethodctor/TwoOnOneMember.aj @@ -0,0 +1,8 @@ +// trying to put two annotations onto one method and two on one ctor - should both be errors +public aspect TwoOnOneMember { + declare @method: public void m1() : @Colored("red"); + declare @method: public void m1() : @Colored("blue"); + declare @constructor: new(int) : @Colored("red"); + declare @constructor: new(int) : @Colored("blue"); +} + diff --git a/tests/java5/annotations/declare/atmethodctor/TwoOnOneMember2.aj b/tests/java5/annotations/declare/atmethodctor/TwoOnOneMember2.aj new file mode 100644 index 000000000..633caa0fc --- /dev/null +++ b/tests/java5/annotations/declare/atmethodctor/TwoOnOneMember2.aj @@ -0,0 +1,23 @@ +// trying to put two annotations onto one a method and two on a ctor +// - should be OK, they are diff annotations +public aspect TwoOnOneMember2 { + declare @method: public void m1() : @Colored("red"); + declare @method: public void m1() : @Fruit("tomato"); + declare @constructor: new(int) : @Colored("green"); + declare @constructor: new(int) : @Fruit("apple"); +} + +aspect X { + before(): call(* *(..)) && @annotation(Colored) { + System.err.println("Colored method call at "+thisJoinPoint.getSourceLocation()); + } + before(): call(* *(..)) && @annotation(Fruit) { + System.err.println("Fruit method call at "+thisJoinPoint.getSourceLocation()); + } + before(): call(new(..)) && @annotation(Colored) { + System.err.println("Colored ctor call at "+thisJoinPoint.getSourceLocation()); + } + before(): call(new(..)) && @annotation(Fruit) { + System.err.println("Fruit ctor call at "+thisJoinPoint.getSourceLocation()); + } +} diff --git a/tests/java5/annotations/declare/atmethodctor/WrongTarget.aj b/tests/java5/annotations/declare/atmethodctor/WrongTarget.aj new file mode 100644 index 000000000..364ce3034 --- /dev/null +++ b/tests/java5/annotations/declare/atmethodctor/WrongTarget.aj @@ -0,0 +1,13 @@ +// trying to put wrong annotations onto a field +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) @interface MethodColoring { String value(); } +@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @interface TypeColoring { String value(); } + +public aspect WrongTarget { + declare @method: void m1(..) : @MethodColoring("red"); + declare @method: void m1(..) : @TypeColoring("blue"); + declare @constructor: new(..) : @MethodColoring("red"); + declare @constructor: new(..) : @TypeColoring("blue"); +} + diff --git a/tests/java5/annotations/declare/atmethodctor/ignoreTypeNotExposed.properties b/tests/java5/annotations/declare/atmethodctor/ignoreTypeNotExposed.properties new file mode 100644 index 000000000..a0b22a340 --- /dev/null +++ b/tests/java5/annotations/declare/atmethodctor/ignoreTypeNotExposed.properties @@ -0,0 +1,2 @@ +typeNotExposedToWeaver=ignore +adviceDidNotMatch=ignore diff --git a/tests/java5/annotations/declare/ignoreTypeNotExposed.properties b/tests/java5/annotations/declare/ignoreTypeNotExposed.properties new file mode 100644 index 000000000..a0b22a340 --- /dev/null +++ b/tests/java5/annotations/declare/ignoreTypeNotExposed.properties @@ -0,0 +1,2 @@ +typeNotExposedToWeaver=ignore +adviceDidNotMatch=ignore -- 2.39.5