diff options
author | acolyer <acolyer> | 2005-08-04 14:41:28 +0000 |
---|---|---|
committer | acolyer <acolyer> | 2005-08-04 14:41:28 +0000 |
commit | 0894d1dd3223cd171b3a1c40e9bc733585cb0c3e (patch) | |
tree | 35aa6d91227f9925762df659837d103af1312427 /tests/java5/generics | |
parent | 64db5cf905f9473c2920bc5a28c96d19d8ba9461 (diff) | |
download | aspectj-0894d1dd3223cd171b3a1c40e9bc733585cb0c3e.tar.gz aspectj-0894d1dd3223cd171b3a1c40e9bc733585cb0c3e.zip |
test cases for execution pointcut with generic and parameterized types. This completes the implementation of the execution pcd with generics. :)
Diffstat (limited to 'tests/java5/generics')
3 files changed, 177 insertions, 0 deletions
diff --git a/tests/java5/generics/pointcuts/ExecutionOverriding.aj b/tests/java5/generics/pointcuts/ExecutionOverriding.aj new file mode 100644 index 000000000..194251a3f --- /dev/null +++ b/tests/java5/generics/pointcuts/ExecutionOverriding.aj @@ -0,0 +1,91 @@ +public aspect ExecutionOverriding { + + // if a type overrides a generic method from a supertype, changing the + // signature in the process (for example, is a generic subtype with a + // narrowed type variable, or extends a parameterized super class, or + // implements a parameterized interface), then a type pattern of + // OriginalDeclaringType.erasureOfOriginalSignature matches, and a + // type pattern of *.erasureOfOriginalSignature matches, but + // a type pattern OverridingType.erasureOfOriginalSignature DOES NOT + // MATCH. + + declare warning : execution(void *.foo(Object)) + : "wildcard declaring type match on erasure"; + + declare warning : execution(void Generic.foo(Object)) + : "base declaring type match on erasure"; + + declare warning : execution(void SubGeneric.foo(Object)) + : "not expecting any matches"; + + declare warning : execution(void SubGeneric.foo(Number)) + : "sub type match on erasure"; + + declare warning : execution(void SubParameterized.foo(Object)) + : "not expecting any matches"; + + declare warning : execution(void SubParameterized.foo(String)) + : "parameterized match on erasure"; +} + +class Generic<T> { + int x = 0; + + // withincode (void Generic.foo(Object)) + // withincode (void *.foo(Object)) + public void foo(T someObject) { + x = 1; + } + +} + +class SubGeneric<N extends Number> extends Generic<N> { + int y = 0; + + // withincode(void Generic.foo(Object)) + // withincode( void *.foo(Object)) + // withincode(void SubGeneric.foo(Number)) + // !withincode(void SubGeneric.foo(Object)) + public void foo(N someObject) { + y = 1; + } + +} + +class SubParameterized extends Generic<String> { + int y = 0; + + // withincode(void Generic.foo(Object)) + // withincode( void *.foo(Object)) + // withincode(void SubParameterized.foo(String)) + // !withincode(void SubGeneric.foo(Object)) + public void foo(String someObject) { + y = 1; + } + +} + +interface I<E> { + void bar(E anElement); +} + +class ParameterizedI implements I<Double> { + int x; + + // withincode(void I.bar(Object)) + // withincode(void *.bar(Object)) + // withincode(void ParameterizedI.bar(Double)) + // !withincode(void ParameterizedI.bar(Object)) + public void bar(Double d) { + x = 1; + } + + static aspect ParameterizedChecker { + + declare warning : execution(void I.bar(Object)) : "erasure match on base interface"; + declare warning : execution(void *.bar(Object)) : "wildcard match on erasure"; + declare warning : execution(void ParameterizedI.bar(Double)) : "parameterized match"; + declare warning : execution(void ParameterizedI.bar(Object)) : "no match expected"; + } +} + diff --git a/tests/java5/generics/pointcuts/ExecutionPointcutMatchingErrorCases.aj b/tests/java5/generics/pointcuts/ExecutionPointcutMatchingErrorCases.aj new file mode 100644 index 000000000..60ed09c94 --- /dev/null +++ b/tests/java5/generics/pointcuts/ExecutionPointcutMatchingErrorCases.aj @@ -0,0 +1,18 @@ +public aspect ExecutionPointcutMatchingErrorCases { + + // rule 1) you can't use generic or parameterized type patterns in the declaring type position + pointcut tryExecutionGeneric() : execution(* Generic<T>.*(..)); // CE L 4 + pointcut tryExecutionParameterized() : execution(* Generic<String>.*(..)); // CE L5 + pointcut badThrows() : execution(* Generic.*(..) throws Ex*<String>); // CE L6 +} + + +class Generic<T> { + + T foo = null; + + T getFoo() { + return foo; + } + +} diff --git a/tests/java5/generics/pointcuts/ExecutionPointcutMatchingParamAndReturnTypes.aj b/tests/java5/generics/pointcuts/ExecutionPointcutMatchingParamAndReturnTypes.aj new file mode 100644 index 000000000..4f120694a --- /dev/null +++ b/tests/java5/generics/pointcuts/ExecutionPointcutMatchingParamAndReturnTypes.aj @@ -0,0 +1,68 @@ +import java.util.*; + +public aspect ExecutionPointcutMatchingParamAndReturnTypes { + + // rule 3) a raw parameter pattern matches any parameterized type + declare warning : execution(Generic.new(List)) + : "raw param type matching in execution ok"; + declare warning : execution(List UglyBuilding.foo()) + : "raw return type matching in execution ok"; + + // rule 4) A param type declared using a type variable is matched by its erasure + declare warning : execution(Generic.new(Object)) + : "erasure type matching in execution ok"; + declare warning : execution(Object Generic.foo()) + : "erasure type matching in execution ok"; + + // rule 5) no join points in bridge methods + declare warning : execution(void UglyBuilding.iSee(String)) + : "execution and parameterized method ok"; + declare warning : execution(* ISore.*(..)) + : "execution and generic interface ok"; + declare warning : execution(* I2.*(..)) + : "execution and interface control test"; + declare warning : execution(void UglyBuilding.iSee(Object)) + : "should be no join points for bridge methods"; + + // rule 6) parameterized types in return and args can be matched exactly + declare warning : execution(Generic.new(List<String>)) : "match on parameterized args"; + declare warning : execution(List<Number> *(..)) : "match on parameterized return type"; +} + + +class Generic<T> { + int x; + public Generic(List<String> ls) { + x = 5; + } + public Generic(T t) { + x = 6; + } + + T foo() { x = 7; return null; } +} + +interface ISore<E> { + + void iSee(E anE); + +} + +interface I2 { + void ic2it(); +} + +class UglyBuilding implements ISore<String>, I2 { + + int y; + + // this class will have a bridge method with signature void iSee(Object), with a cast and call + // to the method below + public void iSee(String s) { + y = 2; + } + + public void ic2it() { y = 4; } + + List<Number> foo() { y = 1; return null; } +}
\ No newline at end of file |