aboutsummaryrefslogtreecommitdiffstats
path: root/tests/java5/generics
diff options
context:
space:
mode:
authoracolyer <acolyer>2005-08-17 08:37:11 +0000
committeracolyer <acolyer>2005-08-17 08:37:11 +0000
commitd7bb145d6e9ea76fa2e9cc1648ab0869ca5e6c2c (patch)
tree933ff1f1abdbcc82f5681ce48f53749ab166e62e /tests/java5/generics
parentc75040720d62262539d37af46339d6e3a6a89c3f (diff)
downloadaspectj-d7bb145d6e9ea76fa2e9cc1648ab0869ca5e6c2c.tar.gz
aspectj-d7bb145d6e9ea76fa2e9cc1648ab0869ca5e6c2c.zip
test cases for all examples in the new generics chapter of the ajdk
Diffstat (limited to 'tests/java5/generics')
-rw-r--r--tests/java5/generics/ajdk/ArgsExamples.aj63
-rw-r--r--tests/java5/generics/ajdk/BridgeMethodExamples.aj29
-rw-r--r--tests/java5/generics/ajdk/ErasureMatching.aj33
-rw-r--r--tests/java5/generics/ajdk/MixedParameterizedAndTypeVariables.aj15
-rw-r--r--tests/java5/generics/ajdk/SignatureWildcards.aj19
-rw-r--r--tests/java5/generics/ajdk/SimpleParameterizedTypeExamples.aj41
6 files changed, 200 insertions, 0 deletions
diff --git a/tests/java5/generics/ajdk/ArgsExamples.aj b/tests/java5/generics/ajdk/ArgsExamples.aj
new file mode 100644
index 000000000..833d9d154
--- /dev/null
+++ b/tests/java5/generics/ajdk/ArgsExamples.aj
@@ -0,0 +1,63 @@
+import java.util.*;
+
+class C {
+
+ public void foo(List<String> listOfStrings) {}
+
+ public void bar(List<Double> listOfDoubles) {}
+
+ public void goo(List<? extends Number> listOfSomeNumberType) {}
+
+}
+
+aspect A {
+
+ before(List<Double> listOfDoubles) : execution(* C.*(..)) && args(listOfDoubles) {
+ for (Double d : listOfDoubles) {
+ // do something
+ }
+ }
+
+ @org.aspectj.lang.annotation.SuppressAjWarnings
+ before(List<Double> listOfDoubles) : execution(* C.*(..)) && args(listOfDoubles) {
+ for (Double d : listOfDoubles) {
+ // do something
+ }
+ }
+
+ @org.aspectj.lang.annotation.SuppressAjWarnings("uncheckedArgument")
+ before(List<Double> listOfDoubles) : execution(* C.*(..)) && args(listOfDoubles) {
+ for (Double d : listOfDoubles) {
+ // do something
+ }
+ }
+
+ before(List<Double> listOfDoubles) : execution(* C.*(List<Double>)) && args(listOfDoubles) {
+ for (Double d : listOfDoubles) {
+ // do something
+ }
+ }
+
+}
+
+public aspect ArgsExamples {
+
+ before() : args(List) && execution(* *(..)) {
+ System.out.println("args(List)");
+ }
+
+ before() : args(List<String>) && execution(* *(..)) {
+ System.out.println("args List of String");
+ }
+
+ before() : args(List<Double>) && execution(* *(..)) {
+ System.out.println("args List of Double");
+ }
+
+ public static void main(String[] args) {
+ C c = new C();
+ c.foo(new ArrayList<String>());
+ c.bar(new ArrayList<Double>());
+ c.goo(new ArrayList<Float>());
+ }
+} \ No newline at end of file
diff --git a/tests/java5/generics/ajdk/BridgeMethodExamples.aj b/tests/java5/generics/ajdk/BridgeMethodExamples.aj
new file mode 100644
index 000000000..cbf3e6411
--- /dev/null
+++ b/tests/java5/generics/ajdk/BridgeMethodExamples.aj
@@ -0,0 +1,29 @@
+public aspect BridgeMethodExamples {
+
+ declare warning : execution(Object SubGeneric.foo(Object)) : "no match";
+ declare warning : execution(Object Generic.foo(Object)) : "double match";
+ declare warning : call(Object SubGeneric.foo(Object)) : "match";
+
+ void foo() {
+ SubGeneric rawType = new SubGeneric();
+ rawType.foo("hi"); // call to bridge method (will result in a runtime failure in this case)
+ Object n = new Integer(5);
+ rawType.foo(n); // call to bridge method that would succeed at runtime
+ }
+}
+
+class Generic<T> {
+
+ public T foo(T someObject) {
+ return someObject;
+ }
+
+}
+
+class SubGeneric<N extends Number> extends Generic<N> {
+
+ public N foo(N someNumber) {
+ return someNumber;
+ }
+
+} \ No newline at end of file
diff --git a/tests/java5/generics/ajdk/ErasureMatching.aj b/tests/java5/generics/ajdk/ErasureMatching.aj
new file mode 100644
index 000000000..8f0686ddf
--- /dev/null
+++ b/tests/java5/generics/ajdk/ErasureMatching.aj
@@ -0,0 +1,33 @@
+import java.util.List;
+
+public aspect ErasureMatching {
+
+ declare warning : execution(static Object Utils.first(List)) : "static generic method match";
+
+ declare warning : execution(Number Utils.max(Number, Number)) : "instance generic method match";
+
+ declare warning : execution(public List G.getAllDataItems()) : "method in generic type match";
+
+ declare warning : set(Object G.myData) : "field in generic type match";
+
+}
+
+class Utils {
+
+ /** static generic method */
+ static <T> T first(List<T> ts) { return null; }
+
+ /** instance generic method */
+ <T extends Number> T max(T t1, T t2) { return t1; }
+
+}
+
+class G<T> {
+
+ // field with parameterized type
+ T myData = null;
+
+ // method with parameterized return type
+ public List<T> getAllDataItems() { return null; }
+
+} \ No newline at end of file
diff --git a/tests/java5/generics/ajdk/MixedParameterizedAndTypeVariables.aj b/tests/java5/generics/ajdk/MixedParameterizedAndTypeVariables.aj
new file mode 100644
index 000000000..3037253f5
--- /dev/null
+++ b/tests/java5/generics/ajdk/MixedParameterizedAndTypeVariables.aj
@@ -0,0 +1,15 @@
+import java.util.List;
+public aspect MixedParameterizedAndTypeVariables {
+
+ declare warning : execution(List G.foo(List)) : "erasure match";
+ declare warning : execution(List G.foo(List<String>)) : "mixed match";
+ declare warning : execution(* *(List<String>)) : "params only match";
+ declare warning : execution(List<Object> G.foo(List<String>)) : "wrong erasure";
+
+}
+
+class G<T> {
+
+ List<T> foo(List<String> ls) { return null; }
+
+} \ No newline at end of file
diff --git a/tests/java5/generics/ajdk/SignatureWildcards.aj b/tests/java5/generics/ajdk/SignatureWildcards.aj
new file mode 100644
index 000000000..7b93949f8
--- /dev/null
+++ b/tests/java5/generics/ajdk/SignatureWildcards.aj
@@ -0,0 +1,19 @@
+import java.util.List;
+
+public aspect SignatureWildcards {
+
+ declare warning : execution(* C.*(List)) : "any list";
+ declare warning : execution(* C.*(List<? extends Number>)) : "only foo";
+ declare warning : execution(* C.*(List<?>)) : "some list";
+ declare warning : execution(* C.*(List<? extends Object+>)) : "any list with upper bound";
+}
+
+class C {
+
+ public void foo(List<? extends Number> listOfSomeNumberType) {}
+
+ public void bar(List<?> listOfSomeType) {}
+
+ public void goo(List<Double> listOfDoubles) {}
+
+ } \ No newline at end of file
diff --git a/tests/java5/generics/ajdk/SimpleParameterizedTypeExamples.aj b/tests/java5/generics/ajdk/SimpleParameterizedTypeExamples.aj
new file mode 100644
index 000000000..1ecb5cb26
--- /dev/null
+++ b/tests/java5/generics/ajdk/SimpleParameterizedTypeExamples.aj
@@ -0,0 +1,41 @@
+import java.util.*;
+
+public aspect SimpleParameterizedTypeExamples {
+
+ declare warning : get(List Foo.myStrings) : "get myStrings 1";
+ declare warning : get(List<String> Foo.myStrings) : "get myStrings 2";
+ declare warning : get(List<Number> *) : "get myStrings 3 - no match";
+
+ declare warning : get(List Foo.myFloats) : "get myFloats 1";
+ declare warning : get(List<Float> *) : "get myFloats 2";
+ declare warning : get(List<Number+> *) : "get myFloats 3";
+ declare warning : get(List<Double> *) : "get myFloats 4 - no match";
+
+ declare warning : execution(List get*(..)) : "getter 1";
+ declare warning : execution(List<*> get*(..)) : "getter 2";
+ declare warning : execution(List<String> get*(..)) : "getter 3";
+ declare warning : execution(List<Number+> get*(..)) : "getter 4";
+
+ declare warning : call(* addStrings(List)) : "call 1";
+ declare warning : call(* addStrings(List<String>)) : "call 2";
+ declare warning : call(* addStrings(List<Number>)) : "call 3 - no match";
+
+ void bar() {
+ Foo f = new Foo();
+ f.addStrings(null);
+ }
+}
+
+class Foo {
+
+ List<String> myStrings;
+ List<Float> myFloats;
+
+ public List<String> getStrings() { return myStrings; }
+ public List<Float> getFloats() { return myFloats; }
+
+ public void addStrings(List<String> evenMoreStrings) {
+ myStrings.addAll(evenMoreStrings);
+ }
+
+} \ No newline at end of file