]> source.dussan.org Git - aspectj.git/commitdiff
Declare annotation with ITDs: testcode
authoraclement <aclement>
Thu, 17 Mar 2005 19:56:13 +0000 (19:56 +0000)
committeraclement <aclement>
Thu, 17 Mar 2005 19:56:13 +0000 (19:56 +0000)
tests/java5/annotations/binding/BindingWithAnnotatedItds1.aj [new file with mode: 0644]
tests/java5/annotations/binding/BindingWithAnnotatedItds2.aj [new file with mode: 0644]
tests/java5/annotations/binding/BindingWithAnnotatedItds3.aj [new file with mode: 0644]
tests/java5/annotations/binding/BindingWithDeclaredAnnotationItds1.aj [new file with mode: 0644]
tests/java5/annotations/binding/BindingWithDeclaredAnnotationItds2.aj [new file with mode: 0644]
tests/java5/annotations/binding/BindingWithDeclaredAnnotationItds3.aj [new file with mode: 0644]
tests/java5/annotations/binding/BindingWithDeclaredAnnotationItds4.aj [new file with mode: 0644]

diff --git a/tests/java5/annotations/binding/BindingWithAnnotatedItds1.aj b/tests/java5/annotations/binding/BindingWithAnnotatedItds1.aj
new file mode 100644 (file)
index 0000000..0c2ac30
--- /dev/null
@@ -0,0 +1,26 @@
+// Annotated ITD (method) being matched upon and extracted
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME) @interface Fruit { String value();}
+
+public aspect BindingWithAnnotatedItds1 {
+
+  @Fruit("apple") int A.m() { return 1; }
+  
+  public static void main(String[]argv) {
+    A a = new A();
+    a.m();
+  }
+  
+}
+
+class A { }
+
+aspect X {
+
+  before(Fruit f): execution(* *(..)) && @annotation(f) {
+    System.err.println("Found "+f.value()+" at jp "+thisJoinPoint+
+                       " ("+thisJoinPoint.getSourceLocation()+")");
+  }
+  
+}
diff --git a/tests/java5/annotations/binding/BindingWithAnnotatedItds2.aj b/tests/java5/annotations/binding/BindingWithAnnotatedItds2.aj
new file mode 100644 (file)
index 0000000..f7cee7b
--- /dev/null
@@ -0,0 +1,37 @@
+// Annotated ITD (field) being matched upon and extracted
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME) @interface Fruit { String value();}
+
+public aspect BindingWithAnnotatedItds2 {
+
+  @Fruit("banana") int A.i;
+  public @Fruit("apple") String A.j;
+
+  private @Fruit("orange") int[] A.k;
+  
+  public static void main(String[]argv) {
+    A a = new A();
+    a.i = 5;
+    a.j = "hello";
+    a.k = new int[]{1,2,3};
+  }
+  
+}
+
+class A { }
+
+aspect X {
+
+  before(Fruit f): set(* *) && @annotation(f) {
+    System.err.println("Found "+f.value()+" at jp "+thisJoinPoint+
+                       " ("+thisJoinPoint.getSourceLocation()+")");
+  }
+
+  //before(Fruit f): execution(* *(..)) && @annotation(f) {
+  //  System.err.println("Execution of something fruity at this jp"+thisJoinPoint+
+  //    " ("+thisJoinPoint.getSourceLocation()+")");
+  //}
+  
+}
diff --git a/tests/java5/annotations/binding/BindingWithAnnotatedItds3.aj b/tests/java5/annotations/binding/BindingWithAnnotatedItds3.aj
new file mode 100644 (file)
index 0000000..8bee421
--- /dev/null
@@ -0,0 +1,33 @@
+// Annotated ITD (ctor) being matched upon and extracted
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME) @interface Fruit { String value();}
+
+public aspect BindingWithAnnotatedItds3 {
+
+  @Fruit("pear") A.new(String s) { }
+
+  private @Fruit("orange") A.new(int i) { }
+
+  public @Fruit("tomato") A.new(boolean b) { }
+  
+  public static void main(String[]argv) {
+    A instance1 = new A("a");
+    A instance2 = new A(3);
+    A instance3 = new A(true);
+  }
+  
+}
+
+class A { 
+
+}
+
+aspect X {
+
+  before(Fruit f): execution(new(..)) && @annotation(f) {
+    System.err.println("Found "+f.value()+" at jp "+thisJoinPoint+
+                       " ("+thisJoinPoint.getSourceLocation()+")");
+  }
+  
+}
diff --git a/tests/java5/annotations/binding/BindingWithDeclaredAnnotationItds1.aj b/tests/java5/annotations/binding/BindingWithDeclaredAnnotationItds1.aj
new file mode 100644 (file)
index 0000000..4f36edc
--- /dev/null
@@ -0,0 +1,44 @@
+// Annotated ITD (method) being matched upon and extracted
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME) @interface Fruit { String value();}
+
+public aspect BindingWithDeclaredAnnotationItds1 {
+
+  int A.m() { return 1; }
+
+  public int A.n() { return 2; }
+   
+  private int A.o() { return 3; }
+  
+  public static void main(String[]argv) {
+    A a = new A();
+    a.m();
+    a.n();
+    a.o();
+  }
+  
+}
+
+class A { }
+
+aspect X {
+
+  declare @method: int A.m(): @Fruit("orange");
+
+  declare @method: int A.n(): @Fruit("banana");
+
+  declare @method: int A.o(): @Fruit("tomato");
+
+  before(Fruit f): execution(* *(..)) && @annotation(f) {
+    System.err.println("Found "+f.value()+" at jp "+thisJoinPoint+
+                       " ("+thisJoinPoint.getSourceLocation()+")");
+  }
+
+  before(Fruit f): call(* *(..)) && @annotation(f) {
+    System.err.println("Found "+f.value()+" at jp "+thisJoinPoint+
+                       " ("+thisJoinPoint.getSourceLocation()+")");
+  }
+
+  
+}
diff --git a/tests/java5/annotations/binding/BindingWithDeclaredAnnotationItds2.aj b/tests/java5/annotations/binding/BindingWithDeclaredAnnotationItds2.aj
new file mode 100644 (file)
index 0000000..3e852a9
--- /dev/null
@@ -0,0 +1,39 @@
+// Annotated ITD (field) being matched upon and extracted
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME) @interface Fruit { String value();}
+
+public aspect BindingWithDeclaredAnnotationItds2 {
+
+  int A.i;
+
+  private String A.j;
+
+  public boolean[] A.k;
+  
+  public static void main(String[]argv) {
+    A a = new A();
+    a.i = 5;
+    a.j = "hello";
+    a.k = new boolean[]{true,false};
+  }
+  
+}
+
+class A { }
+
+aspect X {
+
+  declare @field: int A.i: @Fruit("orange");
+
+  declare @field: String A.j: @Fruit("banana");
+
+  declare @field: boolean[] A.k: @Fruit("apple");
+
+  before(Fruit f): set(* *) && @annotation(f) {
+    System.err.println("Found "+f.value()+" at jp "+thisJoinPoint+
+                       " ("+thisJoinPoint.getSourceLocation()+")");
+  }
+
+  
+}
diff --git a/tests/java5/annotations/binding/BindingWithDeclaredAnnotationItds3.aj b/tests/java5/annotations/binding/BindingWithDeclaredAnnotationItds3.aj
new file mode 100644 (file)
index 0000000..3dd5e0d
--- /dev/null
@@ -0,0 +1,36 @@
+// Annotated ITD (field) being matched upon and extracted
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME) @interface Fruit { String value();}
+@Retention(RetentionPolicy.RUNTIME) @interface Drink { String value();}
+
+public aspect BindingWithDeclaredAnnotationItds3 {
+
+  int A.i;
+
+  public static void main(String[]argv) {
+    A a = new A();
+    a.i = 5;
+  }
+  
+}
+
+class A { }
+
+aspect X {
+
+  declare @field: int A.i: @Fruit("orange");
+  declare @field: int A.i: @Drink("margarita");
+
+  before(Fruit f): set(* *) && @annotation(f) {
+    System.err.println("Found fruit "+f.value()+" at jp "+thisJoinPoint+
+                       " ("+thisJoinPoint.getSourceLocation()+")");
+  }
+
+  before(Drink d): set(* *) && @annotation(d) {
+    System.err.println("Found drink "+d.value()+" at jp "+thisJoinPoint+
+                       " ("+thisJoinPoint.getSourceLocation()+")");
+  }
+
+  
+}
diff --git a/tests/java5/annotations/binding/BindingWithDeclaredAnnotationItds4.aj b/tests/java5/annotations/binding/BindingWithDeclaredAnnotationItds4.aj
new file mode 100644 (file)
index 0000000..2ecc73c
--- /dev/null
@@ -0,0 +1,37 @@
+// Annotated ITD (ctor) being matched upon and extracted
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME) @interface Fruit { String value();}
+
+public aspect BindingWithDeclaredAnnotationItds4 {
+
+  A.new(String s) { }
+
+  private A.new(int i) { }
+
+  public A.new(boolean b) { }
+  
+  public static void main(String[]argv) {
+    A instance1 = new A("a");
+    A instance2 = new A(3);
+    A instance3 = new A(true);
+  }
+  
+}
+
+class A { 
+
+}
+
+aspect X {
+
+  declare @constructor: A.new(String): @Fruit("pear");
+  declare @constructor: A.new(int): @Fruit("orange");
+  declare @constructor: A.new(boolean): @Fruit("tomato");
+
+  before(Fruit f): execution(new(..)) && @annotation(f) {
+    System.err.println("Found "+f.value()+" at jp "+thisJoinPoint+
+                       " ("+thisJoinPoint.getSourceLocation()+")");
+  }
+  
+}