@@ -0,0 +1,32 @@ | |||
public aspect GetAndSetPointcutMatching { | |||
// rule 1) you can't use generic or parameterized type patterns in the declaring type position | |||
pointcut tryGetGeneric() : get( * Generic<T>.*); // CE L 4 | |||
pointcut trySetGeneric() : set(* Generic<T>.*); // CE L5 | |||
pointcut tryGetParameterized() : get(* ISore<String>.*); // CE L6 | |||
pointcut trySetParameterized() : set(* ISore<String>.*); // CE L7 | |||
pointcut trySneakyGet() : get(* (Object || ISore<Number>).*); // CE L8 | |||
} | |||
class Generic<T> { | |||
T foo = null; | |||
T getFoo() { | |||
return foo; | |||
} | |||
} | |||
interface ISore<E> { | |||
void iSee(E anE); | |||
} | |||
class UglyBuilding implements ISore<String> { | |||
public void iSee(String s) {} | |||
} |
@@ -0,0 +1,36 @@ | |||
public aspect GetAndSetPointcutMatchingDeclaringType { | |||
// rule 2) a raw declaring type pattern matches any parameterized or generic type | |||
declare warning : get(* Generic.*) : "generic/param get matching ok"; // CW L15,33 | |||
declare warning : set(* Generic.*) : "generic/param set matching ok"; // CW L12,32 | |||
} | |||
class Generic<T> { | |||
public T foo = null; | |||
T getFoo() { | |||
return foo; | |||
} | |||
} | |||
interface ISore<E> { | |||
public static final int x = 5; | |||
void iSee(E anE); | |||
} | |||
class UglyBuilding implements ISore<String> { | |||
public void iSee(String s) { | |||
Generic<String> gs = new Generic<String>(); | |||
gs.foo = "hi"; // set jp | |||
s.equals(gs.foo); // get jp | |||
} | |||
} |
@@ -0,0 +1,90 @@ | |||
public aspect GetAndSetPointcutMatchingFieldType { | |||
Generic<String> gs = new Generic<String>(); | |||
// rule 3) a raw field type pattern matches any parameterized type | |||
declare warning : get(Generic *.*) && withincode(* rawFieldTypePatternMatching()) | |||
: "raw field type matching in get ok"; | |||
declare warning : set(Generic *.*) && withincode(* rawFieldTypePatternMatching()) | |||
: "raw field type matching in set ok"; | |||
void rawFieldTypePatternMatching() { | |||
System.out.println(gs); // get | |||
gs = null; // set | |||
} | |||
// rule 4) A field type declared using a type variable is matched by its erasure | |||
declare warning : get(Object foo) : "erasure matching in get ok"; | |||
declare warning : set(Object foo) : "erasure matching in set ok"; | |||
declare warning : get(java.util.List<Object> foos) : "does not match! erasure is List"; | |||
declare warning : set(java.util.List<Object> foos) : "does not match! erasure is List"; | |||
declare warning : get(java.util.List foos) : "erasure matching in get with params ok"; | |||
declare warning : set(java.util.List foos) : "erasure matching in set with params ok"; | |||
// rule 5) A field type declared using a parameterized type is matched by parameterized type patterns | |||
declare warning : get(java.util.List<String> *) : "parameterized type matching in get ok"; | |||
declare warning : set(java.util.List<String> *) : "parameterized type matching in set ok"; | |||
declare warning : get(java.util.Map<Number,String> *) : "parameterized type matching in get ok x2"; | |||
declare warning : set(java.util.Map<Number,String> *) : "parameterized type matching in set ok x2"; | |||
// rule 6) generic wildcards match exactly, aspectj wildcards match wildly | |||
declare warning : get(java.util.List<?> *) : "wildcard get matching ok"; | |||
declare warning : set(java.util.List<?> *) : "wildcard set matching ok"; | |||
declare warning : get(java.util.List<? extends Number> *) : "wildcard extends get matching ok"; | |||
declare warning : set(java.util.List<? extends Number> *) : "wildcard extends set matching ok"; | |||
declare warning : get(java.util.List<? super Number> *) : "wildcard super get matching ok"; | |||
declare warning : set(java.util.List<? super Number> *) : "wildcard super set matching ok"; | |||
declare warning : get(java.util.List<*> *) : "the really wild show"; | |||
} | |||
class Generic<T> { | |||
public T foo = null; | |||
private java.util.List<T> foos = null; | |||
T getFoo() { | |||
return foo; | |||
} | |||
void bar() { | |||
Object x = foos; | |||
} | |||
} | |||
interface ISore<E> { | |||
public static final int x = 5; | |||
void iSee(E anE); | |||
} | |||
class UglyBuilding /*implements ISore<String>*/ { | |||
java.util.List<String> ls; | |||
java.util.Map<Number,String> mns; | |||
public void iSee(String s) { | |||
ls = null; // set | |||
Object o = ls; // get | |||
mns = null; // set | |||
o = mns; // get | |||
} | |||
java.util.List<?> wl; | |||
java.util.List<? extends Number> snl; | |||
java.util.List<? super Number> nl; | |||
void makeSomeJPs() { | |||
wl = null; | |||
Object o = wl; | |||
snl = null; | |||
o = snl; | |||
nl = null; | |||
o = nl; | |||
} | |||
} |
@@ -9,4 +9,7 @@ public aspect StaticInitializationWithParameterizedTypes { | |||
pointcut badStaticInitClass() : staticinitialization(GenericImplementingClass<Double>); | |||
// CE line 10 | |||
pointcut allowedStaticInitClass() : staticinitialization(GenericImplementingClass<Double>+); | |||
// CE line 14 | |||
pointcut sneakItIntoDisjunction() : staticinitialization(String || GenericInterface<Double>); | |||
} |
@@ -0,0 +1,31 @@ | |||
public aspect ThisAndTargetPointcutMatching { | |||
// rule 1) you can't use generic or parameterized type patterns with this and target | |||
pointcut tryThisGeneric() : this(Generic<T>); // CE L 4 | |||
pointcut tryTargetGeneric() : target(Generic<T>); // CE L5 | |||
pointcut tryThisParameterized() : this(ISore<String>); // CE L6 | |||
pointcut tryTargetParameterized() : target(ISore<String>); // CE /7 | |||
} | |||
class Generic<T> { | |||
T foo = null; | |||
T getFoo() { | |||
return foo; | |||
} | |||
} | |||
interface ISore<E> { | |||
void iSee(E anE); | |||
} | |||
class UglyBuilding implements ISore<String> { | |||
public void iSee(String s) {} | |||
} |
@@ -0,0 +1,55 @@ | |||
public aspect ThisAndTargetPointcutMatchingRuntime { | |||
// rule 2) a raw type pattern matches all jps within a generic type | |||
pointcut setAndThis() : set(* *) && this(Generic); | |||
pointcut setAndTarget() : set(* *) && target(Generic); | |||
pointcut executionAndThis() : execution(* *(..)) && this(Generic); | |||
pointcut executionAndTarget() : execution(* *(..)) && target(Generic); | |||
pointcut callAndTarget() : call(* *(..)) && target(Generic); | |||
// rule 3) a raw type pattern matches all jps within a parameterized type | |||
pointcut pCallAndThis() : call(* *(..)) && this(ISore); | |||
pointcut pCallAndTarget() : call(* *(..)) && target(ISore); | |||
before() : setAndThis() { System.out.println("set and this matched ok"); } | |||
before() : setAndTarget() { System.out.println("set and target matched ok"); } | |||
before() : executionAndThis() { System.out.println("execution and this matched ok"); } | |||
before() : executionAndTarget() { System.out.println("execution and target matched ok"); } | |||
before() : callAndTarget() { System.out.println("call and target matched ok"); } | |||
before() : pCallAndThis() { System.out.println("parameterized call and this matched ok"); } | |||
before() : pCallAndTarget() { System.out.println("parameterized call and target matched ok"); } | |||
public static void main(String[] args) { | |||
Generic<String> gs = new Generic<String>(); | |||
gs.getFoo(); | |||
UglyBuilding theIBMBuilding = new UglyBuilding(); | |||
theIBMBuilding.iSee("you"); | |||
} | |||
} | |||
class Generic<T> { | |||
T foo = null; | |||
public T getFoo() { | |||
return foo; | |||
} | |||
} | |||
interface ISore<E> { | |||
void iSee(E anE); | |||
} | |||
class UglyBuilding implements ISore<String> { | |||
public void iSee(String s) { | |||
noop(); | |||
} | |||
private void noop() {} | |||
} |
@@ -0,0 +1,31 @@ | |||
public aspect WithinPointcutMatching { | |||
// rule 1) you can't use generic or parameterized type patterns with within | |||
pointcut tryGeneric() : within(Generic<T>); // CE L 4 | |||
pointcut tryParameterized() : within(ISore<String>); // CE L5 | |||
pointcut tryBeingSneaky() : within(String || (Number || Generic<Double>)); // CE L6 | |||
} | |||
class Generic<T> { | |||
T foo = null; | |||
T getFoo() { | |||
return foo; | |||
} | |||
} | |||
interface ISore<E> { | |||
void iSee(E anE); | |||
} | |||
class UglyBuilding implements ISore<String> { | |||
public void iSee(String s) {} | |||
} |
@@ -0,0 +1,34 @@ | |||
public aspect WithinPointcutMatchingWarnings { | |||
// rule 2) a raw type pattern matches all jps within a generic type | |||
declare warning : set(* *) && within(Generic) : "matched set correctly"; | |||
declare warning : execution(* *(..)) && within(Generic) : "matched execution correctly"; | |||
// rule 3) a raw type pattern with + matches all jps within a parameterized type | |||
declare warning : within(ISore) : "init matched correctly"; | |||
declare warning : execution(* *(..)) && within(ISore+) : "matched parameterization ok"; | |||
} | |||
class Generic<T> { | |||
T foo = null; | |||
T getFoo() { | |||
return foo; | |||
} | |||
} | |||
interface ISore<E> { | |||
void iSee(E anE); | |||
} | |||
class UglyBuilding implements ISore<String> { | |||
public void iSee(String s) {} | |||
} |
@@ -35,10 +35,10 @@ public class GenericsTests extends XMLBasedAjcTestCase { | |||
* @args PASS | |||
* - does not permit type vars PASS | |||
* - does not permit parameterized type PASS | |||
* @annotation PASS | |||
* @annotation PASS | |||
* - does not permit type vars PASS | |||
* - does not permit parameterized type PASS | |||
* @within, @within code - as above 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 | |||
@@ -54,29 +54,31 @@ public class GenericsTests extends XMLBasedAjcTestCase { | |||
* - generic type with bounds [extends, extends + i/f's] N/A | |||
* - generic type with wrong number of type params N/A | |||
* - wildcards in bounds N/A | |||
* within | |||
* - as above, but allows parameterized type (disallowed is simplified plan) | |||
* within PASS | |||
* - as above, but allows parameterized type (disallowed in simplified plan) | |||
* - wildcards in type parameters N/A | |||
* this | |||
* this PASS | |||
* - no type vars | |||
* - parameterized types - disallowed in simplification plan | |||
* - implements | |||
* - instanceof | |||
* target | |||
* target PASS | |||
* - as this | |||
* args | |||
* args TODO | |||
* - 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 | |||
* get & set PASS | |||
* - parameterized declaring type PASS | |||
* - generic declaring type PASS | |||
* - field type is type variable PASS | |||
* - field type is parameterized PASS | |||
* initialization, preinitialization | |||
* - type variables as type params | |||
* - no join points for parameterized types | |||
* - generic declaring type | |||
* - type variables as params | |||
* - parameterized types as params | |||
* - no join points for init, preinit of parameterized types (as per staticinit) | |||
* execution, withincode | |||
* - wait till we get there! | |||
* call | |||
@@ -297,6 +299,22 @@ public class GenericsTests extends XMLBasedAjcTestCase { | |||
// runTest("staticinitialization with generic types - advanced"); | |||
// } | |||
public void testWithinPointcutErrors() { | |||
runTest("within pcd with various parameterizations and generic types - errors"); | |||
} | |||
public void testWithinPointcutWarnings() { | |||
runTest("within pcd with various parameterizations and generic types - warnings"); | |||
} | |||
public void testThisTargetPointcutErrors() { | |||
runTest("this and target with various parameterizations and generic types - errors"); | |||
} | |||
public void testThisTargetPointcutRuntime() { | |||
runTest("this and target with various parameterizations and generic types - runtime"); | |||
} | |||
public void testExecutionWithRawType() { | |||
runTest("execution pcd with raw type matching"); | |||
} | |||
@@ -305,6 +323,18 @@ public class GenericsTests extends XMLBasedAjcTestCase { | |||
runTest("execution pcd with raw signature matching"); | |||
} | |||
public void testGetAndSetPointcutErrors() { | |||
runTest("get and set with various parameterizations and generic types - errors"); | |||
} | |||
public void testGetAndSetPointcutMatchingWithGenericAndParameterizedTypes() { | |||
runTest("get and set with various parameterizations and generic declaring types"); | |||
} | |||
public void testGetAndSetPointcutMatchingWithGenericAndParameterizedFieldTypes() { | |||
runTest("get and set with various parameterizations and generic field types"); | |||
} | |||
// public void testExecutionWithGenericDeclaringTypeAndErasedParameterTypes() { | |||
// runTest("execution pcd with generic declaring type and erased parameter types"); | |||
// } |
@@ -2542,6 +2542,7 @@ | |||
<message kind="error" line="6" text="no static initialization join points for parameterized types, use raw type instead"/> | |||
<message kind="error" line="9" text="no static initialization join points for parameterized types, use raw type instead"/> | |||
<message kind="error" line="11" text="no static initialization join points for parameterized types, use raw type instead"/> | |||
<message kind="error" line="14" text="no static initialization join points for parameterized types, use raw type instead"/> | |||
</compile> | |||
</ajc-test> | |||
@@ -2585,7 +2586,98 @@ | |||
</compile> | |||
</ajc-test> | |||
<ajc-test dir="java5/generics/pointcuts" title="within pcd with various parameterizations and generic types - errors"> | |||
<compile files="WithinPointcutMatching.aj" options="-1.5"> | |||
<message kind="warning" line="4" text="no match for this type name: T"/> | |||
<message kind="error" line="4" text="parameterized type pattern not supported by 'within', use a raw type pattern instead"/> | |||
<message kind="error" line="5" text="parameterized type pattern not supported by 'within', use a raw type pattern instead"/> | |||
<message kind="error" line="6" text="parameterized type pattern not supported by 'within', use a raw type pattern instead"/> | |||
</compile> | |||
</ajc-test> | |||
<ajc-test dir="java5/generics/pointcuts" title="within pcd with various parameterizations and generic types - warnings"> | |||
<compile files="WithinPointcutMatchingWarnings.aj" options="-1.5"> | |||
<message kind="warning" line="16" text="matched set correctly"/> | |||
<message kind="warning" line="18" text="matched execution correctly"/> | |||
<message kind="warning" line="24" text="init matched correctly"/> | |||
<message kind="warning" line="32" text="matched parameterization ok"/> | |||
</compile> | |||
</ajc-test> | |||
<ajc-test dir="java5/generics/pointcuts" title="this and target with various parameterizations and generic types - errors"> | |||
<compile files="ThisAndTargetPointcutMatching.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="parameterized types not supported for this and target pointcuts (erasure limitation)"/> | |||
<message kind="error" line="5" text="parameterized types not supported for this and target pointcuts (erasure limitation)"/> | |||
<message kind="error" line="6" text="parameterized types not supported for this and target pointcuts (erasure limitation)"/> | |||
<message kind="error" line="7" text="parameterized types not supported for this and target pointcuts (erasure limitation)"/> | |||
</compile> | |||
</ajc-test> | |||
<ajc-test dir="java5/generics/pointcuts" title="this and target with various parameterizations and generic types - runtime"> | |||
<compile files="ThisAndTargetPointcutMatchingRuntime.aj" options="-1.5"> | |||
</compile> | |||
<run class="ThisAndTargetPointcutMatchingRuntime"> | |||
<stdout> | |||
<line text="set and this matched ok"/> | |||
<line text="set and target matched ok"/> | |||
<line text="call and target matched ok"/> | |||
<line text="execution and this matched ok"/> | |||
<line text="execution and target matched ok"/> | |||
<line text="parameterized call and target matched ok"/> | |||
<line text="parameterized call and this matched ok"/> | |||
<line text="parameterized call and target matched ok"/> | |||
</stdout> | |||
</run> | |||
</ajc-test> | |||
<ajc-test dir="java5/generics/pointcuts" title="get and set with various parameterizations and generic types - errors"> | |||
<compile files="GetAndSetPointcutMatching.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="can't use parameterized type patterns for the declaring type of a get or set pointcut expression (use the raw type instead)"/> | |||
<message kind="error" line="5" text="can't use parameterized type patterns for the declaring type of a get or set pointcut expression (use the raw type instead)"/> | |||
<message kind="error" line="6" text="can't use parameterized type patterns for the declaring type of a get or set pointcut expression (use the raw type instead)"/> | |||
<message kind="error" line="7" text="can't use parameterized type patterns for the declaring type of a get or set pointcut expression (use the raw type instead)"/> | |||
<message kind="error" line="8" text="can't use parameterized type patterns for the declaring type of a get or set pointcut expression (use the raw type instead)"/> | |||
</compile> | |||
</ajc-test> | |||
<ajc-test dir="java5/generics/pointcuts" title="get and set with various parameterizations and generic declaring types"> | |||
<compile files="GetAndSetPointcutMatchingDeclaringType.aj" options="-1.5"> | |||
<message kind="warning" line="15" text="generic/param get matching ok"/> | |||
<message kind="warning" line="33" text="generic/param get matching ok"/> | |||
<message kind="warning" line="12" text="generic/param set matching ok"/> | |||
<message kind="warning" line="32" text="generic/param set matching ok"/> | |||
</compile> | |||
</ajc-test> | |||
<ajc-test dir="java5/generics/pointcuts" title="get and set with various parameterizations and generic field types"> | |||
<compile files="GetAndSetPointcutMatchingFieldType.aj" options="-1.5"> | |||
<message kind="warning" line="13" text="raw field type matching in get ok"/> | |||
<message kind="warning" line="14" text="raw field type matching in set ok"/> | |||
<message kind="warning" line="49" text="erasure matching in get ok"/> | |||
<message kind="warning" line="45" text="erasure matching in set ok"/> | |||
<message kind="warning" line="53" text="erasure matching in get with params ok"/> | |||
<message kind="warning" line="46" text="erasure matching in set with params ok"/> | |||
<message kind="warning" line="72" text="parameterized type matching in set ok"/> | |||
<message kind="warning" line="73" text="parameterized type matching in get ok"/> | |||
<message kind="warning" line="74" text="parameterized type matching in set ok x2"/> | |||
<message kind="warning" line="75" text="parameterized type matching in get ok x2"/> | |||
<message kind="warning" line="83" text="wildcard set matching ok"/> | |||
<message kind="warning" line="84" text="wildcard get matching ok"/> | |||
<message kind="warning" line="85" text="wildcard extends set matching ok"/> | |||
<message kind="warning" line="86" text="wildcard extends get matching ok"/> | |||
<message kind="warning" line="87" text="wildcard super set matching ok"/> | |||
<message kind="warning" line="88" text="wildcard super get matching ok"/> | |||
<message kind="warning" line="73" text="the really wild show"/> | |||
<message kind="warning" line="84" text="the really wild show"/> | |||
<message kind="warning" line="86" text="the really wild show"/> | |||
<message kind="warning" line="88" 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.*(..))"/> |