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<Long> gic = new GenericImplementingClass<Long>(); | |||||
gic.asInt(55L); | |||||
} | |||||
declare warning : | |||||
execution<T>(* GenericInterface<T extends Number>.asInt(T)) : | |||||
"execution<T>(* GenericInterface<T extends Number>.asInt(T))"; | |||||
} |
public aspect HandlerPointcutTests { | |||||
// CE line 4 - no type variables allowed in handler | |||||
pointcut exceptionHandler() : handler<T>(GenericInterface<T>); | |||||
// CE line 8 - no parameterized types | |||||
// CW line 8 - unresolved absolute type name T | |||||
pointcut unboundTypeInHandler() : handler(GenericInterface<T>); | |||||
// CE line 11 - no parameterized types | |||||
pointcut parameterizedHandler() : handler(GenericInterface<Double>); | |||||
} |
import java.util.List; | |||||
public aspect ParameterizedTypesInAnnotationPatterns { | |||||
// CE - not an annotation type | |||||
pointcut simple() : staticinitialization(@List<String> String); | |||||
// CE - not an annotation type | |||||
pointcut generic() : staticinitialization<T>(@List<T> Class<T>); | |||||
// no CE, good enough for now? may improve error reporting for this later | |||||
pointcut combined() : staticinitialization(@(Foo || List<String>) String); | |||||
} | |||||
@interface Foo {} |
public aspect ParameterizedTypesInAtPCDs { | |||||
public pointcut atthis() : @this(List<String>); | |||||
public pointcut attarget() : @target(List<String>); | |||||
public pointcut atargs() : @args(List<String>); | |||||
public pointcut atannotation() : @annotation(List<String>); | |||||
public pointcut atwithin() : @within(List<String>); | |||||
public pointcut atwithincode() : @withincode(List<String>); | |||||
} |
public aspect PointcutsThatDontAllowTypeVars { | |||||
public pointcut handlerWithVars() : handler<T>(*); | |||||
public pointcut cflowWithVars() : cflow<T>(ifWithVars()); | |||||
public pointcut cflowbelowWithVars() : cflowbelow<S>(ifWithVars()); | |||||
public pointcut thisWithVars() : this<T>(String); | |||||
public pointcut targetWithVars() : target<T>(String); | |||||
public pointcut argsWithVars() : args<T>(String); | |||||
public pointcut atthisWithVars() : @this<T>(*); | |||||
public pointcut attargetWithVars() : @target<T>(*); | |||||
public pointcut atargsWithVars() : @args<T>(*); | |||||
public pointcut atwithinWithVars() : @within<T>(*); | |||||
public pointcut atwithincodeWithVars() : @withincode<T>(*); | |||||
public pointcut atannotationWithVars() : @annotation<T>(*); | |||||
public pointcut ifWithVars() : if<T>(true); // message for this one should be improved... | |||||
} |
public class GenericsTests extends 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<T> should fail PASS | |||||
* - @Foo<String> should fail PASS | |||||
* - @(Foo || Bar<T>) 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() { | public static Test suite() { | ||||
return XMLBasedAjcTestCase.loadSuite(GenericsTests.class); | return XMLBasedAjcTestCase.loadSuite(GenericsTests.class); | ||||
} | } | ||||
// 2. ITDF | // 2. ITDF | ||||
// -- Pointcut tests... | // -- 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() { | public void testExecutionWithRawType() { | ||||
runTest("execution pcd with raw type matching"); | runTest("execution pcd with raw type matching"); | ||||
runTest("execution pcd with generic declaring type and erased parameter types"); | 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 | // --- helpers | ||||
// Check the signature attribute on a class is correct | // Check the signature attribute on a class is correct |
<!-- end of generic decps --> | <!-- end of generic decps --> | ||||
<!-- generics and pointcuts --> | <!-- generics and pointcuts --> | ||||
<ajc-test dir="java5/generics/pointcuts" title="handler pcd and generics / type vars"> | |||||
<compile files="GenericInterface.java,HandlerPointcutTests.aj" options="-1.5"> | |||||
<message kind="error" line="4" text="Syntax error on token"/> | |||||
<message kind="error" line="8" text="a parameterized type pattern may not be used in a handler pointcut expression"/> | |||||
<message kind="warning" line="8" text="no match for this type name: T"/> | |||||
<message kind="error" line="11" text="a parameterized type pattern may not be used in a handler pointcut expression"/> | |||||
</compile> | |||||
</ajc-test> | |||||
<ajc-test dir="java5/generics/pointcuts" title="pointcuts that dont allow type vars"> | |||||
<compile files="PointcutsThatDontAllowTypeVars.aj" options="-1.5"> | |||||
<message kind="error" line="3" text="Syntax error on token"/> | |||||
<message kind="error" line="5" text="Syntax error on token"/> | |||||
<message kind="error" line="7" text="Syntax error on token"/> | |||||
<message kind="error" line="9" text="Syntax error on token"/> | |||||
<message kind="error" line="11" text="Syntax error on token"/> | |||||
<message kind="error" line="13" text="Syntax error on token"/> | |||||
<message kind="error" line="15" text="Syntax error on token"/> | |||||
<message kind="error" line="17" text="Syntax error on token"/> | |||||
<message kind="error" line="19" text="Syntax error on token"/> | |||||
<message kind="error" line="21" text="Syntax error on token"/> | |||||
<message kind="error" line="23" text="Syntax error on token"/> | |||||
<message kind="error" line="25" text="Syntax error on token"/> | |||||
<message kind="error" line="27" text="Syntax error on token"/> | |||||
</compile> | |||||
</ajc-test> | |||||
<ajc-test dir="java5/generics/pointcuts" title="annotation pcds with parameterized types"> | |||||
<compile files="ParameterizedTypesInAtPCDs.aj" options="-1.5"> | |||||
<message kind="error" line="3" text="Syntax error on token"/> | |||||
<message kind="error" line="5" text="Syntax error on token"/> | |||||
<message kind="error" line="7" text="Syntax error on token"/> | |||||
<message kind="error" line="9" text="Syntax error on token"/> | |||||
<message kind="error" line="11" text="Syntax error on token"/> | |||||
<message kind="error" line="13" text="Syntax error on token"/> | |||||
</compile> | |||||
</ajc-test> | |||||
<ajc-test dir="java5/generics/pointcuts" title="annotation patterns with parameterized types"> | |||||
<compile files="ParameterizedTypesInAnnotationPatterns.aj" options="-1.5"> | |||||
<message kind="error" line="5" text="is not an annotation type"/> | |||||
<message kind="error" line="7" text="is not an annotation type"/> | |||||
</compile> | |||||
</ajc-test> | |||||
<ajc-test dir="java5/generics/pointcuts" title="execution pcd with raw type matching"> | <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"> | <compile files="GenericInterface.java,ConcreteImplementingClass.java,GenericImplementingClass.java,RawTypeMatching.aj" options="-1.5"> | ||||
</compile> | </compile> | ||||
</ajc-test> | </ajc-test> | ||||
<ajc-test dir="java5/generics/pointcuts" title="execution pcd with generic signature matching"> | |||||
<compile files="GenericInterface.java,ConcreteImplementingClass.java,GenericImplementingClass.java,GenericSignatureMatching.aj" options="-1.5"> | |||||
<message kind="warning" line="4" text="execution<T>(* GenericInterface<T extends Number>.asInt(T))"/> | |||||
<message kind="warning" line="5" text="execution<T>(* GenericInterface<T extends Number>.asInt(T))"/> | |||||
</compile> | |||||
</ajc-test> | |||||
<!-- end of generics and pointcuts tests --> | <!-- end of generics and pointcuts tests --> | ||||
<!-- ============================================================== --> | <!-- ============================================================== --> |