Bladeren bron

tests for initialization and preinitialization pointcut matching with generics

tags/V1_5_0M3
acolyer 19 jaren geleden
bovenliggende
commit
42fc0becde

+ 21
- 0
tests/java5/generics/pointcuts/InitializationPointcutMatching.aj Bestand weergeven

@@ -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;
}
}

+ 18
- 0
tests/java5/generics/pointcuts/InitializationPointcutMatchingDeclaringType.aj Bestand weergeven

@@ -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;
}
}

+ 53
- 0
tests/java5/generics/pointcuts/InitializationPointcutMatchingParamTypes.aj Bestand weergeven

@@ -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) {}
}

+ 17
- 5
tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java Bestand weergeven

@@ -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");
}

+ 46
- 1
tests/src/org/aspectj/systemtest/ajc150/ajc150.xml Bestand weergeven

@@ -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.*(..))"/>

Laden…
Annuleren
Opslaan