From: acolyer Date: Thu, 11 Aug 2005 15:30:37 +0000 (+0000) Subject: generic aspect testcases - woohoo! X-Git-Tag: V1_5_0M3~153 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=43cf534bfd8f852d85b42b5dd0d7d5fbe2956e69;p=aspectj.git generic aspect testcases - woohoo! --- diff --git a/tests/java5/generics/genericaspects/AnonymousPointcutInGenericAspect.aj b/tests/java5/generics/genericaspects/AnonymousPointcutInGenericAspect.aj new file mode 100644 index 000000000..d8dabf7fb --- /dev/null +++ b/tests/java5/generics/genericaspects/AnonymousPointcutInGenericAspect.aj @@ -0,0 +1,28 @@ +abstract aspect SuperAspect { + + before() : execution(* *(T)) { + System.out.println("I matched at " + thisJoinPointStaticPart); + } + +} + +public aspect AnonymousPointcutInGenericAspect extends SuperAspect { + + public static void main(String[] args) { + C c = new C(); + c.foo("well i never"); + c.bar(5); + } + +} + +class C { + + // should be matched + public void foo(String s) {} + + // should not be matched + public void bar(Number n) {} + + +} \ No newline at end of file diff --git a/tests/java5/generics/genericaspects/DeclareParentsWithTypeVars.aj b/tests/java5/generics/genericaspects/DeclareParentsWithTypeVars.aj new file mode 100644 index 000000000..48b729bf9 --- /dev/null +++ b/tests/java5/generics/genericaspects/DeclareParentsWithTypeVars.aj @@ -0,0 +1,37 @@ +import java.lang.reflect.*; + +abstract aspect GiveMeFoo { + + declare parents : C implements I; + +} + +public aspect DeclareParentsWithTypeVars extends GiveMeFoo { + + public static void main(String[] args) { + C c = new C(); + if (! (c instanceof I)) throw new RuntimeException("C should implement I"); + Type[] superinterfaces = C.class.getGenericInterfaces(); + if (! (superinterfaces[0] instanceof ParameterizedType)) throw new RuntimeException("Expected to get parameterized interface but found " + superinterfaces[0]); + ParameterizedType pt = (ParameterizedType) superinterfaces[0]; + Type[] typeArguments = pt.getActualTypeArguments(); + if (typeArguments[0] != String.class) throw new RuntimeException("Expecting String parameter but found " + typeArguments[0]); + } + +} + +class C { + +// public Object identity(Object o) { return o; } + + public String identity(String aString) { + return aString; + } + +} + +interface I { + + E identity(E anE); + +} diff --git a/tests/java5/generics/genericaspects/DeclareWarningInGenericAspect.aj b/tests/java5/generics/genericaspects/DeclareWarningInGenericAspect.aj new file mode 100644 index 000000000..b0cc510b4 --- /dev/null +++ b/tests/java5/generics/genericaspects/DeclareWarningInGenericAspect.aj @@ -0,0 +1,22 @@ +abstract aspect SuperAspect { + + pointcut takesAT() : execution(* *(T)); + + declare warning : takesAT() : "this method takes a T!"; +} + + +public aspect DeclareWarningInGenericAspect extends SuperAspect { + +} + +class C { + + // should be matched + public void foo(String s) {} + + // should not be matched + public void bar(Number n) {} + + +} \ No newline at end of file diff --git a/tests/java5/generics/genericaspects/ExecutionAdviceInGenericAspect.aj b/tests/java5/generics/genericaspects/ExecutionAdviceInGenericAspect.aj new file mode 100644 index 000000000..27624bc63 --- /dev/null +++ b/tests/java5/generics/genericaspects/ExecutionAdviceInGenericAspect.aj @@ -0,0 +1,31 @@ +abstract aspect SuperAspect { + + pointcut takesAT() : execution(* *(T)); + + before() : takesAT() { + System.out.println("I matched at " + thisJoinPointStaticPart); + } + +} + + +public aspect ExecutionAdviceInGenericAspect extends SuperAspect { + + public static void main(String[] args) { + C c = new C(); + c.foo("well i never"); + c.bar(5); + } + +} + +class C { + + // should be matched + public void foo(String s) {} + + // should not be matched + public void bar(Number n) {} + + +} \ No newline at end of file