From 103733b9c277f980d30db27710ea359974e45c81 Mon Sep 17 00:00:00 2001 From: acolyer Date: Wed, 8 Mar 2006 10:59:06 +0000 Subject: [PATCH] Progress on: Bug 130869: Pointcut resolution fails against type variables https://bugs.eclipse.org/bugs/show_bug.cgi?id=130869 fix and test case... --- ...enericAspectWithAnnotationTypeParameter.aj | 35 ++++++++++++++++ tests/bugs151/pr130869.aj | 42 +++++++++++++++++++ .../systemtest/ajc151/Ajc151Tests.java | 9 ++++ .../org/aspectj/systemtest/ajc151/ajc151.xml | 18 ++++++++ .../weaver/patterns/ReferencePointcut.java | 27 ++++++++++-- 5 files changed, 128 insertions(+), 3 deletions(-) create mode 100644 tests/bugs151/GenericAspectWithAnnotationTypeParameter.aj create mode 100644 tests/bugs151/pr130869.aj diff --git a/tests/bugs151/GenericAspectWithAnnotationTypeParameter.aj b/tests/bugs151/GenericAspectWithAnnotationTypeParameter.aj new file mode 100644 index 000000000..e4cc3f1be --- /dev/null +++ b/tests/bugs151/GenericAspectWithAnnotationTypeParameter.aj @@ -0,0 +1,35 @@ +import java.lang.annotation.Annotation; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +public class GenericAspectWithAnnotationTypeParameter { + + @AnnOne + @AnnTwo + public static void main(String[] args) { + System.out.println("hello"); + } + + +} + +@Retention(RetentionPolicy.RUNTIME) +@interface AnnOne {} +@interface AnnTwo {} + +abstract aspect AnnotationMatcher { + + before() : execution(* *(..)) && @annotation(A) { + System.out.println("annotation match - no binding"); + } + + before() : execution(@A * *(..)) { + System.out.println("execution with annotation match"); + } + + before(A anAnnotation) : execution(* *(..)) && @annotation(anAnnotation) { + System.out.println("annotation match - binding"); + } +} + +aspect AnnOneMatcher extends AnnotationMatcher {} \ No newline at end of file diff --git a/tests/bugs151/pr130869.aj b/tests/bugs151/pr130869.aj new file mode 100644 index 000000000..c46e21640 --- /dev/null +++ b/tests/bugs151/pr130869.aj @@ -0,0 +1,42 @@ +abstract aspect AbstractSystemArchitecture { + + public abstract pointcut inMyApplication(); + + // more pointcuts below... + +} + +aspect MySystemArchitecture extends AbstractSystemArchitecture { + + public pointcut inMyApplication() : within(SomeClass); + +} + +abstract aspect NoDirectlyRunnableClasses { + + declare warning : execution(public static void main(String[])) && + A.inMyApplication() + : "no directly runnable classes"; + +} + +aspect NoRunnablesInMyApp extends NoDirectlyRunnableClasses { + +} + + +class SomeClass { + + public static void main(String[] args) { // CW L30 + System.out.println("hello"); + } + +} + +class SomeOtherClass { + + public static void main(String[] args) { // no warning + System.out.println("hello"); + } + +} \ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java b/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java index e3d763666..49ccd33c5 100644 --- a/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc151/Ajc151Tests.java @@ -210,6 +210,14 @@ public class Ajc151Tests extends org.aspectj.testing.XMLBasedAjcTestCase { runTest("aop.xml aspect inherits abstract method that has concrete implementation in parent"); } + public void testGenericAspectsWithAnnotationTypeParameters() { + runTest("Generic aspects with annotation type parameters"); + } + + public void testPointcutInterfaces_pr130869() { + runTest("Pointcut interfaces"); + } + ///////////////////////////////////////// public static Test suite() { return XMLBasedAjcTestCase.loadSuite(Ajc151Tests.class); @@ -218,5 +226,6 @@ public class Ajc151Tests extends org.aspectj.testing.XMLBasedAjcTestCase { protected File getSpecFile() { return new File("../tests/src/org/aspectj/systemtest/ajc151/ajc151.xml"); } + } \ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml b/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml index ddb69ae37..f935c4da9 100644 --- a/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml +++ b/tests/src/org/aspectj/systemtest/ajc151/ajc151.xml @@ -228,6 +228,24 @@ + + + + + + + + + + + + + + + + + + diff --git a/weaver/src/org/aspectj/weaver/patterns/ReferencePointcut.java b/weaver/src/org/aspectj/weaver/patterns/ReferencePointcut.java index 4110eec92..170ef58b2 100644 --- a/weaver/src/org/aspectj/weaver/patterns/ReferencePointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/ReferencePointcut.java @@ -138,6 +138,9 @@ public class ReferencePointcut extends Pointcut { } else { searchType = scope.getEnclosingType(); } + if (searchType.isTypeVariableReference()) { + searchType = ((TypeVariableReference)searchType).getTypeVariable().getUpperBound().resolve(scope.getWorld()); + } arguments.resolveBindings(scope, bindings, true, true); @@ -173,7 +176,7 @@ public class ReferencePointcut extends Pointcut { } if (Modifier.isAbstract(pointcutDef.getModifiers())) { - if (onType != null) { + if (onType != null && !onType.isTypeVariableReference()) { scope.message(IMessage.ERROR, this, "can't make static reference to abstract pointcut"); return; @@ -209,7 +212,7 @@ public class ReferencePointcut extends Pointcut { } else if (onType.isGenericType()) { scope.message(MessageUtil.error(WeaverMessages.format(WeaverMessages.CANT_REFERENCE_POINTCUT_IN_RAW_TYPE), getSourceLocation())); - } + } } for (int i=0,len=arguments.size(); i < len; i++) { @@ -274,8 +277,26 @@ public class ReferencePointcut extends Pointcut { if (searchStart.isMissing()) { return Pointcut.makeMatchesNothing(Pointcut.CONCRETE); } - } + if (onType.isTypeVariableReference()) { + // need to replace on type with the binding for the type variable + // in the declaring type + if (declaringType.isParameterizedType()) { + TypeVariable[] tvs = declaringType.getGenericType().getTypeVariables(); + String typeVariableName = ((TypeVariableReference)onType).getTypeVariable().getName(); + for (int i = 0; i < tvs.length; i++) { + if (tvs[i].getName().equals(typeVariableName)) { + ResolvedType realOnType = declaringType.getTypeParameters()[i].resolve(declaringType.getWorld()); + onType = realOnType; + searchStart = realOnType; + break; + } + } + } + } + + } + if (declaringType == null) declaringType = searchStart; pointcutDec = declaringType.findPointcut(name); boolean foundMatchingPointcut = (pointcutDec != null && pointcutDec.isPrivate()); -- 2.39.5