diff options
author | acolyer <acolyer> | 2005-07-29 13:10:36 +0000 |
---|---|---|
committer | acolyer <acolyer> | 2005-07-29 13:10:36 +0000 |
commit | 42fc0becde4ce2fca4b20d0d9e1f70127b6d7f42 (patch) | |
tree | 87e749906dfefc0ef6c26c3a4cdbe47fc5980729 | |
parent | 506b37517e2681c790cad02367107c43084f342c (diff) | |
download | aspectj-42fc0becde4ce2fca4b20d0d9e1f70127b6d7f42.tar.gz aspectj-42fc0becde4ce2fca4b20d0d9e1f70127b6d7f42.zip |
tests for initialization and preinitialization pointcut matching with generics
5 files changed, 155 insertions, 6 deletions
diff --git a/tests/java5/generics/pointcuts/InitializationPointcutMatching.aj b/tests/java5/generics/pointcuts/InitializationPointcutMatching.aj new file mode 100644 index 000000000..a27021118 --- /dev/null +++ b/tests/java5/generics/pointcuts/InitializationPointcutMatching.aj @@ -0,0 +1,21 @@ +public aspect InitializationPointcutMatching { + + // rule 1) you can't use generic or parameterized type patterns in the declaring type position + pointcut tryInitGeneric() : initialization(Generic<T>.new(..)); // CE L 4 + pointcut tryPreInitGeneric() : preinitialization(Generic<T>.new(..)); // CE L5 + pointcut tryInitParameterized() : initialization(Generic<String>.new(..)); // CE L6 + pointcut tryPreInitParameterized() : preinitialization(Generic<String>.new(..)); // CE L7 + pointcut trySneakyInit() : initialization((Object || Generic<Number>).new(..)); // CE L8 + pointcut badThrows() : initialization(Generic.new(..) throws Ex*<String>); // CE L9 +} + + +class Generic<T> { + + T foo = null; + + T getFoo() { + return foo; + } + +} diff --git a/tests/java5/generics/pointcuts/InitializationPointcutMatchingDeclaringType.aj b/tests/java5/generics/pointcuts/InitializationPointcutMatchingDeclaringType.aj new file mode 100644 index 000000000..1d7e5e533 --- /dev/null +++ b/tests/java5/generics/pointcuts/InitializationPointcutMatchingDeclaringType.aj @@ -0,0 +1,18 @@ +public aspect InitializationPointcutMatchingDeclaringType { + + // rule 2) a raw declaring type pattern matches any generic type + + declare warning : initialization(Generic.new(..)) : "generic/param init matching ok"; // CW L15,33 + declare warning : preinitialization(Generic.new(..)) : "generic/param preinit matching ok"; // CW L12,32 +} + + +class Generic<T> { + + public T foo = null; + + T getFoo() { + return foo; + } + +} diff --git a/tests/java5/generics/pointcuts/InitializationPointcutMatchingParamTypes.aj b/tests/java5/generics/pointcuts/InitializationPointcutMatchingParamTypes.aj new file mode 100644 index 000000000..8e086c2fb --- /dev/null +++ b/tests/java5/generics/pointcuts/InitializationPointcutMatchingParamTypes.aj @@ -0,0 +1,53 @@ +public aspect InitializationPointcutMatchingParamTypes { + + // rule 3) a raw parameter pattern matches any parameterized type + declare warning : initialization(Generic.new(java.util.List)) + : "raw param type matching in init ok"; + declare warning : preinitialization(Generic.new(java.util.List)) + : "raw param type matching in preinit ok"; + + // rule 4) A param type declared using a type variable is matched by its erasure + declare warning : initialization(Generic.new(Object)) : "erasure matching in init ok"; + declare warning : preinitialization(Generic.new(Object)) : "erasure matching in preinit ok"; + declare warning : initialization(Generic.new(java.util.List<Object>)) : "does not match! erasure is List"; + declare warning : preinitialization(Generic.new(java.util.List<Object>)) : "does not match! erasure is List"; + declare warning : initialization(Generic.new(java.util.ArrayList)) : "erasure matching in init with params ok"; + declare warning : preinitialization(Generic.new(java.util.ArrayList)) : "erasure matching in preinit with params ok"; + + // rule 5) A param type declared using a parameterized type is matched by parameterized type patterns + declare warning : initialization(UglyBuilding.new(java.util.List<String>)) : "parameterized type matching in init ok"; + declare warning : preinitialization(UglyBuilding.new(java.util.List<String>)) : "parameterized type matching in preinit ok"; + declare warning : initialization(UglyBuilding.new(java.util.Map<Number,String>)) : "parameterized type matching in init ok x2"; + declare warning : preinitialization(UglyBuilding.new(java.util.Map<Number,String>)) : "parameterized type matching in preinit ok x2"; + + // rule 6) generic wildcards match exactly, aspectj wildcards match wildly + declare warning : initialization(UglyBuilding.new(java.util.List<?>,int)) : "wildcard init matching ok"; + declare warning : preinitialization(UglyBuilding.new(java.util.List<?>,int)) : "wildcard preinit matching ok"; + declare warning : initialization(UglyBuilding.new(java.util.List<? extends Number>,double)) : "wildcard extends init matching ok"; + declare warning : preinitialization(UglyBuilding.new(java.util.List<? extends Number>,double)) : "wildcard extends preinit matching ok"; + declare warning : initialization(UglyBuilding.new(java.util.List<? super Double>,float)) : "wildcard super init matching ok"; + declare warning : preinitialization(UglyBuilding.new(java.util.List<? super Double>,float)) : "wildcard super preinit matching ok"; + + declare warning : initialization(UglyBuilding.new(java.util.List<*>,..)) : "the really wild show"; +} + + +class Generic<T> { + public Generic(java.util.List<String> ls) {} + public Generic(T t) {} + public Generic(java.util.ArrayList<T> ts) {} +} + +interface ISore<E> { + + void iSee(E anE); + +} + +class UglyBuilding { + public UglyBuilding(java.util.List<String> ls) {} + public UglyBuilding(java.util.Map<Number,String> mns) {} + public UglyBuilding(java.util.List<?> ls, int i) {} + public UglyBuilding(java.util.List<? extends Number> ln, double d) {} + public UglyBuilding(java.util.List<? super Double> ln, float f) {} +}
\ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java b/tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java index 99ed2fee6..b382f1ff2 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java @@ -74,11 +74,11 @@ public class GenericsTests extends XMLBasedAjcTestCase { * - generic declaring type PASS * - field type is type variable PASS * - field type is parameterized PASS - * initialization, preinitialization - * - generic declaring type - * - type variables as params - * - parameterized types as params - * - no join points for init, preinit of parameterized types (as per staticinit) + * initialization, preinitialization PASS + * - generic declaring type PASS + * - type variables as params PASS + * - parameterized types as params PASS + * - no join points for init, preinit of parameterized types (as per staticinit) PASS * execution, withincode * - wait till we get there! * call @@ -315,6 +315,18 @@ public class GenericsTests extends XMLBasedAjcTestCase { runTest("this and target with various parameterizations and generic types - runtime"); } + public void testInitAndPreInitPointcutErrors() { + runTest("init and preinit with parameterized declaring types"); + } + + public void testInitAndPreInitPointcutMatchingWithGenericDeclaringTypes() { + runTest("init and preinit with raw declaring type pattern"); + } + + public void testInitAndPreInitPointcutMatchingWithParameterizedParameterTypes() { + runTest("init and preinit with parameterized parameter types"); + } + public void testExecutionWithRawType() { runTest("execution pcd with raw type matching"); } diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml index 0057270fc..acbdc7465 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml @@ -2677,7 +2677,52 @@ <message kind="warning" line="88" text="the really wild show"/> </compile> </ajc-test> - + + <ajc-test dir="java5/generics/pointcuts" title="init and preinit with parameterized declaring types"> + <compile files="InitializationPointcutMatching.aj" options="-1.5"> + <message kind="warning" line="4" text="no match for this type name: T"/> + <message kind="warning" line="5" text="no match for this type name: T"/> + <message kind="error" line="4" text="no [pre]initialization join points for parameterized types, use raw type instead"/> + <message kind="error" line="5" text="no [pre]initialization join points for parameterized types, use raw type instead"/> + <message kind="error" line="6" text="no [pre]initialization join points for parameterized types, use raw type instead"/> + <message kind="error" line="7" text="no [pre]initialization join points for parameterized types, use raw type instead"/> + <message kind="error" line="8" text="no [pre]initialization join points for parameterized types, use raw type instead"/> + <message kind="error" line="9" text="invalid throws pattern: a generic class may not be a direct or indirect subclass of Throwable"/> + </compile> + </ajc-test> + + <ajc-test dir="java5/generics/pointcuts" title="init and preinit with raw declaring type pattern"> + <compile files="InitializationPointcutMatchingDeclaringType.aj" options="-1.5"> + <message kind="warning" line="10" text="generic/param init matching ok"/> + <message kind="warning" line="10" text="generic/param preinit matching ok"/> + </compile> + </ajc-test> + + <ajc-test dir="java5/generics/pointcuts" title="init and preinit with parameterized parameter types"> + <compile files="InitializationPointcutMatchingParamTypes.aj" options="-1.5"> + <message kind="warning" line="36" text="raw param type matching in init ok"/> + <message kind="warning" line="36" text="raw param type matching in preinit ok"/> + <message kind="warning" line="37" text="erasure matching in init ok"/> + <message kind="warning" line="37" text="erasure matching in preinit ok"/> + <message kind="warning" line="38" text="erasure matching in init with params ok"/> + <message kind="warning" line="38" text="erasure matching in preinit with params ok"/> + <message kind="warning" line="48" text="parameterized type matching in init ok"/> + <message kind="warning" line="48" text="parameterized type matching in preinit ok"/> + <message kind="warning" line="49" text="parameterized type matching in init ok x2"/> + <message kind="warning" line="49" text="parameterized type matching in preinit ok x2"/> + <message kind="warning" line="50" text="wildcard init matching ok"/> + <message kind="warning" line="50" text="wildcard preinit matching ok"/> + <message kind="warning" line="51" text="wildcard extends init matching ok"/> + <message kind="warning" line="51" text="wildcard extends preinit matching ok"/> + <message kind="warning" line="52" text="wildcard super init matching ok"/> + <message kind="warning" line="52" text="wildcard super preinit matching ok"/> + <message kind="warning" line="48" text="the really wild show"/> + <message kind="warning" line="50" text="the really wild show"/> + <message kind="warning" line="51" text="the really wild show"/> + <message kind="warning" line="52" text="the really wild show"/> + </compile> + </ajc-test> + <ajc-test dir="java5/generics/pointcuts" title="execution pcd with raw type matching"> <compile files="GenericInterface.java,ConcreteImplementingClass.java,GenericImplementingClass.java,RawTypeMatching.aj" options="-1.5"> <message kind="warning" line="4" text="execution(* GenericInterface.*(..))"/> |