From ceb8d527356c158d321f49efb0ca53dc12762150 Mon Sep 17 00:00:00 2001 From: acolyer Date: Wed, 13 Jul 2005 12:59:45 +0000 Subject: [PATCH] more test cases covering generics in pointcut expressions --- .../pointcuts/GenericSignatureMatching.aj | 17 ++++ .../pointcuts/HandlerPointcutTests.aj | 13 +++ .../ParameterizedTypesInAnnotationPatterns.aj | 14 +++ .../pointcuts/ParameterizedTypesInAtPCDs.aj | 15 ++++ .../PointcutsThatDontAllowTypeVars.aj | 28 ++++++ .../systemtest/ajc150/GenericsTests.java | 90 +++++++++++++++++++ .../org/aspectj/systemtest/ajc150/ajc150.xml | 52 +++++++++++ 7 files changed, 229 insertions(+) create mode 100644 tests/java5/generics/pointcuts/GenericSignatureMatching.aj create mode 100644 tests/java5/generics/pointcuts/HandlerPointcutTests.aj create mode 100644 tests/java5/generics/pointcuts/ParameterizedTypesInAnnotationPatterns.aj create mode 100644 tests/java5/generics/pointcuts/ParameterizedTypesInAtPCDs.aj create mode 100644 tests/java5/generics/pointcuts/PointcutsThatDontAllowTypeVars.aj diff --git a/tests/java5/generics/pointcuts/GenericSignatureMatching.aj b/tests/java5/generics/pointcuts/GenericSignatureMatching.aj new file mode 100644 index 000000000..28faf00eb --- /dev/null +++ b/tests/java5/generics/pointcuts/GenericSignatureMatching.aj @@ -0,0 +1,17 @@ +public aspect GenericSignatureMatching { + + // tests that references to a generic or parameterized type are + // always matched by a type pattern refering to the raw type form + + void someCode() { + ConcreteImplementingClass cic = new ConcreteImplementingClass(); + cic.asInt(5.0d); + GenericImplementingClass gic = new GenericImplementingClass(); + gic.asInt(55L); + } + + declare warning : + execution(* GenericInterface.asInt(T)) : + "execution(* GenericInterface.asInt(T))"; + +} \ No newline at end of file diff --git a/tests/java5/generics/pointcuts/HandlerPointcutTests.aj b/tests/java5/generics/pointcuts/HandlerPointcutTests.aj new file mode 100644 index 000000000..8324d198d --- /dev/null +++ b/tests/java5/generics/pointcuts/HandlerPointcutTests.aj @@ -0,0 +1,13 @@ +public aspect HandlerPointcutTests { + + // CE line 4 - no type variables allowed in handler + pointcut exceptionHandler() : handler(GenericInterface); + + // CE line 8 - no parameterized types + // CW line 8 - unresolved absolute type name T + pointcut unboundTypeInHandler() : handler(GenericInterface); + + // CE line 11 - no parameterized types + pointcut parameterizedHandler() : handler(GenericInterface); + +} \ No newline at end of file diff --git a/tests/java5/generics/pointcuts/ParameterizedTypesInAnnotationPatterns.aj b/tests/java5/generics/pointcuts/ParameterizedTypesInAnnotationPatterns.aj new file mode 100644 index 000000000..54b538491 --- /dev/null +++ b/tests/java5/generics/pointcuts/ParameterizedTypesInAnnotationPatterns.aj @@ -0,0 +1,14 @@ +import java.util.List; + +public aspect ParameterizedTypesInAnnotationPatterns { + // CE - not an annotation type + pointcut simple() : staticinitialization(@List String); + // CE - not an annotation type + pointcut generic() : staticinitialization(@List Class); + + // no CE, good enough for now? may improve error reporting for this later + pointcut combined() : staticinitialization(@(Foo || List) String); + +} + +@interface Foo {} \ No newline at end of file diff --git a/tests/java5/generics/pointcuts/ParameterizedTypesInAtPCDs.aj b/tests/java5/generics/pointcuts/ParameterizedTypesInAtPCDs.aj new file mode 100644 index 000000000..d92cc7c73 --- /dev/null +++ b/tests/java5/generics/pointcuts/ParameterizedTypesInAtPCDs.aj @@ -0,0 +1,15 @@ +public aspect ParameterizedTypesInAtPCDs { + + public pointcut atthis() : @this(List); + + public pointcut attarget() : @target(List); + + public pointcut atargs() : @args(List); + + public pointcut atannotation() : @annotation(List); + + public pointcut atwithin() : @within(List); + + public pointcut atwithincode() : @withincode(List); + +} \ No newline at end of file diff --git a/tests/java5/generics/pointcuts/PointcutsThatDontAllowTypeVars.aj b/tests/java5/generics/pointcuts/PointcutsThatDontAllowTypeVars.aj new file mode 100644 index 000000000..15b622e49 --- /dev/null +++ b/tests/java5/generics/pointcuts/PointcutsThatDontAllowTypeVars.aj @@ -0,0 +1,28 @@ +public aspect PointcutsThatDontAllowTypeVars { + + public pointcut handlerWithVars() : handler(*); + + public pointcut cflowWithVars() : cflow(ifWithVars()); + + public pointcut cflowbelowWithVars() : cflowbelow(ifWithVars()); + + public pointcut thisWithVars() : this(String); + + public pointcut targetWithVars() : target(String); + + public pointcut argsWithVars() : args(String); + + public pointcut atthisWithVars() : @this(*); + + public pointcut attargetWithVars() : @target(*); + + public pointcut atargsWithVars() : @args(*); + + public pointcut atwithinWithVars() : @within(*); + + public pointcut atwithincodeWithVars() : @withincode(*); + + public pointcut atannotationWithVars() : @annotation(*); + + public pointcut ifWithVars() : if(true); // message for this one should be improved... +} \ 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 08eb412ec..2be934fc2 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java @@ -13,6 +13,75 @@ import org.aspectj.testing.XMLBasedAjcTestCase; public class GenericsTests extends XMLBasedAjcTestCase { + /*========================================== + * Generics test plan for pointcuts. + * + * handler PASS + * - does not permit type var spec + * - does not permit generic type (fail with type not found) + * - does not permit parameterized types + * if PASS + * - does not permit type vars + * cflow PASS + * - does not permit type vars + * cflowbelow PASS + * - does not permit type vars + * @this PASS + * - does not permit type vars PASS + * - does not permit parameterized type PASS + * @target PASS + * - does not permit type vars PASS + * - does not permit parameterized type PASS + * @args PASS + * - does not permit type vars PASS + * - does not permit parameterized type PASS + * @annotation PASS + * - does not permit type vars PASS + * - does not permit parameterized type PASS + * @within, @within code - as above PASS + * annotation type pattern with generic and parameterized types PASS + * - just make sure that annotation interfaces can never be generic first! VERIFIED + * - @Foo should fail PASS + * - @Foo should fail PASS + * - @(Foo || Bar) should fail DEFERRED (not critical) + * staticinitialization + * - error on parameterized type + * - permit parameterized type + + * - wrong number of parameters in parameterized type + * - generic type with one type parameter + * - generic type with n type parameters + * - generic type with bounds [extends, extends + i/f's] + * - generic type with wrong number of type params + * - wildcards in bounds + * within + * - as above, but allows parameterized type + * - wildcards in type parameters + * this + * - no type vars + * - parameterized types + * - implements + * - instanceof + * target + * - as this + * args + * - as this/target, plus... + * - known static match + * - known static match fail + * - maybe match with unchecked warning + * get & set + * - parameterized type + * - generic type + * - return type is type variable + * - return type is parameterized + * initialization, preinitialization + * - type variables as type params + * - no join points for parameterized types + * execution, withincode + * - wait till we get there! + * call + * - wait till we get there! + */ + public static Test suite() { return XMLBasedAjcTestCase.loadSuite(GenericsTests.class); } @@ -179,6 +248,22 @@ public class GenericsTests extends XMLBasedAjcTestCase { // 2. ITDF // -- Pointcut tests... + + public void testHandlerWithGenerics() { + runTest("handler pcd and generics / type vars"); + } + + public void testPointcutsThatDontAllowTypeVars() { + runTest("pointcuts that dont allow type vars"); + } + + public void testParameterizedTypesInAtPCDs() { + runTest("annotation pcds with parameterized types"); + } + + public void testAnnotationPatternsWithParameterizedTypes() { + runTest("annotation patterns with parameterized types"); + } public void testExecutionWithRawType() { runTest("execution pcd with raw type matching"); @@ -192,6 +277,11 @@ public class GenericsTests extends XMLBasedAjcTestCase { runTest("execution pcd with generic declaring type and erased parameter types"); } +// not passing yet... +// public void testExecutionWithGenericSignature() { +// runTest("execution pcd with generic signature matching"); +// } + // --- helpers // Check the signature attribute on a class is correct diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml index 8e98d67b9..f2290c049 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml @@ -2464,6 +2464,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -2484,6 +2530,12 @@ + + + + + + -- 2.39.5