From 522911ec81aeb3ec5b600939d3a2ee6e6297fd0c Mon Sep 17 00:00:00 2001 From: acolyer Date: Sat, 19 Nov 2005 17:08:48 +0000 Subject: [PATCH] tests and fix for pr116229 and pr116755. Also adds support and tests for parseTypePattern in PointcutParser. --- .../annotationGen/RuntimePointcuts.java | 1 + tests/java5/reflection/PointcutLibrary.aj | 14 +++ .../ReflectOnAjcCompiledPointcuts.java | 22 ++++ .../systemtest/ajc150/Ajc150Tests.java | 5 + .../org/aspectj/systemtest/ajc150/ajc150.xml | 7 +- .../ajc150/ataspectj/annotationgen.xml | 2 +- .../org/aspectj/weaver/bcel/BcelWorld.java | 18 ++- .../tools/TypePatternMatcherImpl.java | 34 ++++++ .../src/org/aspectj/weaver/ltw/LTWWorld.java | 76 +++++++++++++ .../src/org/aspectj/weaver/ltw/LTWeaver.java | 22 ++++ .../weaver/reflect/AnnotationFinder.java | 2 + .../ReflectionBasedReferenceTypeDelegate.java | 21 ++-- ...tionBasedReferenceTypeDelegateFactory.java | 49 ++++++-- .../ReflectionBasedResolvedMemberImpl.java | 15 +-- .../weaver/reflect/ReflectionShadow.java | 22 ++-- .../aspectj/weaver/reflect/ReflectionVar.java | 62 ++++++----- .../weaver/reflect/ReflectionWorld.java | 42 ++++++- .../aspectj/weaver/tools/PointcutParser.java | 105 ++++++++++++++++-- .../weaver/tools/TypePatternMatcher.java | 23 ++++ .../weaver/tools/PointcutParserTest.java | 14 +++ .../org/aspectj/weaver/tools/ToolsTests.java | 1 + .../weaver/tools/TypePatternMatcherTest.java | 36 ++++++ .../reflect/Java15AnnotationFinder.java | 14 ++- ...5ReflectionBasedReferenceTypeDelegate.java | 16 ++- 24 files changed, 534 insertions(+), 89 deletions(-) create mode 100644 tests/java5/reflection/PointcutLibrary.aj create mode 100644 tests/java5/reflection/ReflectOnAjcCompiledPointcuts.java create mode 100644 weaver/src/org/aspectj/weaver/internal/tools/TypePatternMatcherImpl.java create mode 100644 weaver/src/org/aspectj/weaver/ltw/LTWWorld.java create mode 100644 weaver/src/org/aspectj/weaver/ltw/LTWeaver.java create mode 100644 weaver/src/org/aspectj/weaver/tools/TypePatternMatcher.java create mode 100644 weaver/testsrc/org/aspectj/weaver/tools/TypePatternMatcherTest.java diff --git a/tests/java5/ataspectj/annotationGen/RuntimePointcuts.java b/tests/java5/ataspectj/annotationGen/RuntimePointcuts.java index 8f9e530d5..171239cd5 100644 --- a/tests/java5/ataspectj/annotationGen/RuntimePointcuts.java +++ b/tests/java5/ataspectj/annotationGen/RuntimePointcuts.java @@ -6,6 +6,7 @@ public class RuntimePointcuts { public static void main(String[] args) throws Exception { PointcutParser parser = new PointcutParser(); + parser.setClassLoader(RuntimePointcuts.class.getClassLoader()); PointcutExpression pc1 = parser.parsePointcutExpression("PCLib.anyMethodExecution()"); PointcutParameter param = parser.createPointcutParameter("s",String.class); PointcutExpression pc2 = parser.parsePointcutExpression("PCLib.joinPointWithStringArg(s)",RuntimePointcuts.class,new PointcutParameter[] {param}); diff --git a/tests/java5/reflection/PointcutLibrary.aj b/tests/java5/reflection/PointcutLibrary.aj new file mode 100644 index 000000000..f3e59e21c --- /dev/null +++ b/tests/java5/reflection/PointcutLibrary.aj @@ -0,0 +1,14 @@ +// random collection of pointcuts to check that +// reflective world and PointcutParser can interpret +// them correctly. + +public aspect PointcutLibrary { + + public pointcut propertyAccess() : get(* *); + public pointcut propertyUpdate() : set(* *); + public pointcut methodExecution() : execution(* *(..)); + public pointcut propertyGet() : execution(!void get*(..)); + public pointcut propertySet(Object newValue) + : execution(void set*(..)) && args(newValue); + +} \ No newline at end of file diff --git a/tests/java5/reflection/ReflectOnAjcCompiledPointcuts.java b/tests/java5/reflection/ReflectOnAjcCompiledPointcuts.java new file mode 100644 index 000000000..9dc9927be --- /dev/null +++ b/tests/java5/reflection/ReflectOnAjcCompiledPointcuts.java @@ -0,0 +1,22 @@ +import org.aspectj.weaver.tools.*; + +public class ReflectOnAjcCompiledPointcuts { + + public static void main(String[] args) { + PointcutParser p = new PointcutParser(); + PointcutExpression pe = null; + pe = p.parsePointcutExpression("PointcutLibrary.propertyAccess()"); + pe = p.parsePointcutExpression("PointcutLibrary.propertyUpdate()"); + pe = p.parsePointcutExpression("PointcutLibrary.methodExecution()"); + pe = p.parsePointcutExpression("PointcutLibrary.propertyGet()"); + pe = p.parsePointcutExpression("PointcutLibrary.propertySet(Object)"); + + PointcutParameter pp = p.createPointcutParameter("foo",String.class); + p.parsePointcutExpression("execution(* *(..)) && PointcutLibrary.propertySet(foo)", + Object.class, + new PointcutParameter[] {pp}); + + } + + +} \ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java index 18b73fd8c..253a9fe72 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java @@ -713,6 +713,11 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase { runTest("no StackOverflowError with circular pcd in generic aspect - 2"); } + +// public void testPointcutParsingOfCompiledPointcuts() { +// runTest("pointcut parsing with ajc compiled pointcut references"); +// } + /* * Load-time weaving bugs */ diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml index 739897885..c0aa8b999 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml @@ -52,7 +52,12 @@ - + + + + + + diff --git a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/annotationgen.xml b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/annotationgen.xml index 33c28dbb3..1ece44117 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/annotationgen.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/annotationgen.xml @@ -146,7 +146,7 @@ - + diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java b/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java index 17e70fef5..63a577926 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java @@ -23,6 +23,7 @@ import java.util.Iterator; import java.util.List; import java.util.StringTokenizer; +import org.aspectj.apache.bcel.classfile.Attribute; import org.aspectj.apache.bcel.classfile.ClassParser; import org.aspectj.apache.bcel.classfile.JavaClass; import org.aspectj.apache.bcel.classfile.Method; @@ -56,6 +57,7 @@ import org.aspectj.weaver.ResolvedType; import org.aspectj.weaver.ResolvedTypeMunger; import org.aspectj.weaver.UnresolvedType; import org.aspectj.weaver.World; +import org.aspectj.weaver.AjAttribute.Aspect; import org.aspectj.weaver.patterns.FormalBinding; import org.aspectj.weaver.patterns.PerClause; import org.aspectj.weaver.patterns.Pointcut; @@ -562,13 +564,25 @@ public class BcelWorld extends World implements Repository { if (anns.length == 0) { return false; } + boolean couldBeAtAspectJStyle = false; for (int i = 0; i < anns.length; i++) { Annotation ann = anns[i]; if ("Lorg/aspectj/lang/annotation/Aspect;".equals(ann.getTypeSignature())) { - return true; + couldBeAtAspectJStyle = true; } } - return false; + + if (!couldBeAtAspectJStyle) return false; + + // ok, so it has the annotation, but it could have been put + // on a code style aspect by the annotation visitor + Attribute[] attributes = jc.getAttributes(); + for (int i = 0; i < attributes.length; i++) { + if (attributes[i].getName().equals(Aspect.AttributeName)) { + return false; + } + } + return true; } catch (IOException e) { // assume it is one as a best effort return true; diff --git a/weaver/src/org/aspectj/weaver/internal/tools/TypePatternMatcherImpl.java b/weaver/src/org/aspectj/weaver/internal/tools/TypePatternMatcherImpl.java new file mode 100644 index 000000000..a49804008 --- /dev/null +++ b/weaver/src/org/aspectj/weaver/internal/tools/TypePatternMatcherImpl.java @@ -0,0 +1,34 @@ +/* ******************************************************************* + * Copyright (c) 2004 IBM Corporation. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * ******************************************************************/ +package org.aspectj.weaver.internal.tools; + +import org.aspectj.weaver.ResolvedType; +import org.aspectj.weaver.World; +import org.aspectj.weaver.patterns.TypePattern; +import org.aspectj.weaver.reflect.ReflectionBasedReferenceTypeDelegateFactory; +import org.aspectj.weaver.tools.TypePatternMatcher; + +public class TypePatternMatcherImpl implements TypePatternMatcher { + + private final TypePattern pattern; + private final World world; + + public TypePatternMatcherImpl(TypePattern pattern, World world) { + this.pattern = pattern; + this.world = world; + } + + public boolean matches(Class aClass) { + ResolvedType rt = + ReflectionBasedReferenceTypeDelegateFactory.resolveTypeInWorld(aClass,world); + return pattern.matchesStatically(rt); + } + +} diff --git a/weaver/src/org/aspectj/weaver/ltw/LTWWorld.java b/weaver/src/org/aspectj/weaver/ltw/LTWWorld.java new file mode 100644 index 000000000..78291089f --- /dev/null +++ b/weaver/src/org/aspectj/weaver/ltw/LTWWorld.java @@ -0,0 +1,76 @@ +/* ******************************************************************* + * Copyright (c) 2005 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: + * Adrian Colyer Initial implementation + * ******************************************************************/ +package org.aspectj.weaver.ltw; + +import org.aspectj.weaver.Advice; +import org.aspectj.weaver.ConcreteTypeMunger; +import org.aspectj.weaver.Member; +import org.aspectj.weaver.ReferenceType; +import org.aspectj.weaver.ReferenceTypeDelegate; +import org.aspectj.weaver.ResolvedMember; +import org.aspectj.weaver.ResolvedType; +import org.aspectj.weaver.ResolvedTypeMunger; +import org.aspectj.weaver.World; +import org.aspectj.weaver.AjAttribute.AdviceAttribute; +import org.aspectj.weaver.patterns.Pointcut; +import org.aspectj.weaver.patterns.PerClause.Kind; + +/** + * @author adrian + * + * For use in LT weaving + * + * Backed by both a BcelWorld and a ReflectionWorld + * + * Needs a callback when a woven class is defined + * This is the trigger for us to ditch the class from + * Bcel and cache it in the reflective world instead. + * + * Problems with classes that are loaded by delegates + * of our classloader + * + * Create by passing in a classloader, message handler + */ +public class LTWWorld extends World { + + protected ReferenceTypeDelegate resolveDelegate(ReferenceType ty) { + // TODO Auto-generated method stub + return null; + + } + + public Advice createAdviceMunger(AdviceAttribute attribute, Pointcut pointcut, Member signature) { + // TODO Auto-generated method stub + return null; + } + + public ConcreteTypeMunger makeCflowStackFieldAdder(ResolvedMember cflowField) { + // TODO Auto-generated method stub + return null; + } + + public ConcreteTypeMunger makeCflowCounterFieldAdder(ResolvedMember cflowField) { + // TODO Auto-generated method stub + return null; + } + + public ConcreteTypeMunger makePerClauseAspect(ResolvedType aspect, Kind kind) { + // TODO Auto-generated method stub + return null; + } + + public ConcreteTypeMunger concreteTypeMunger(ResolvedTypeMunger munger, ResolvedType aspectType) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/weaver/src/org/aspectj/weaver/ltw/LTWeaver.java b/weaver/src/org/aspectj/weaver/ltw/LTWeaver.java new file mode 100644 index 000000000..b69cb671d --- /dev/null +++ b/weaver/src/org/aspectj/weaver/ltw/LTWeaver.java @@ -0,0 +1,22 @@ +/* ******************************************************************* + * Copyright (c) 2005 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: + * Adrian Colyer Initial implementation + * ******************************************************************/ +package org.aspectj.weaver.ltw; + +import org.aspectj.weaver.IWeaver; + +/** + * @author adrian + * + */ +public class LTWeaver implements IWeaver { + +} diff --git a/weaver/src/org/aspectj/weaver/reflect/AnnotationFinder.java b/weaver/src/org/aspectj/weaver/reflect/AnnotationFinder.java index f2807e4a0..88b2c7450 100644 --- a/weaver/src/org/aspectj/weaver/reflect/AnnotationFinder.java +++ b/weaver/src/org/aspectj/weaver/reflect/AnnotationFinder.java @@ -22,6 +22,8 @@ import org.aspectj.weaver.ResolvedType; */ public interface AnnotationFinder { + void setClassLoader(ClassLoader annotationLoader); + Object getAnnotation(ResolvedType annotationType, Object onObject); Object getAnnotationFromMember(ResolvedType annotationType, Member aMember); diff --git a/weaver/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java b/weaver/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java index 622e8c143..2dd8a3d41 100644 --- a/weaver/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java +++ b/weaver/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java @@ -38,23 +38,25 @@ import org.aspectj.weaver.patterns.PerClause; public class ReflectionBasedReferenceTypeDelegate implements ReferenceTypeDelegate { protected Class myClass = null; + protected ClassLoader classLoader = null; private World world; private ReferenceType resolvedType; private ResolvedMember[] fields = null; private ResolvedMember[] methods = null; private ResolvedType[] interfaces = null; - public ReflectionBasedReferenceTypeDelegate(Class forClass, World inWorld, ReferenceType resolvedType) { - initialize(resolvedType,forClass,inWorld); + public ReflectionBasedReferenceTypeDelegate(Class forClass, ClassLoader aClassLoader, World inWorld, ReferenceType resolvedType) { + initialize(resolvedType,forClass, aClassLoader, inWorld); } /** for reflective construction only */ public ReflectionBasedReferenceTypeDelegate() {} - public void initialize(ReferenceType aType, Class aClass, World aWorld) { + public void initialize(ReferenceType aType, Class aClass, ClassLoader aClassLoader, World aWorld) { this.myClass = aClass; this.resolvedType = aType; this.world = aWorld; + this.classLoader = aClassLoader; } protected Class getBaseClass() { @@ -64,12 +66,7 @@ public class ReflectionBasedReferenceTypeDelegate implements ReferenceTypeDelega protected World getWorld() { return this.world; } - - protected ReflectionWorld getReflectionWorld() { - return (ReflectionWorld) this.world; - } - - + public ReferenceType buildGenericType() { throw new UnsupportedOperationException("Shouldn't be asking for generic type at 1.4 source level or lower"); } @@ -215,7 +212,8 @@ public class ReflectionBasedReferenceTypeDelegate implements ReferenceTypeDelega Class[] reflectInterfaces = this.myClass.getInterfaces(); this.interfaces = new ResolvedType[reflectInterfaces.length]; for (int i = 0; i < reflectInterfaces.length; i++) { - this.interfaces[i] = getReflectionWorld().resolve(reflectInterfaces[i]); + this.interfaces[i] = ReflectionBasedReferenceTypeDelegateFactory + .resolveTypeInWorld(reflectInterfaces[i],world); } } return interfaces; @@ -300,7 +298,8 @@ public class ReflectionBasedReferenceTypeDelegate implements ReferenceTypeDelega */ public ResolvedType getSuperclass() { if (this.myClass.getSuperclass() == null) return null; - return getReflectionWorld().resolve(this.myClass.getSuperclass()); + return ReflectionBasedReferenceTypeDelegateFactory + .resolveTypeInWorld(this.myClass.getSuperclass(),world); } /* (non-Javadoc) diff --git a/weaver/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegateFactory.java b/weaver/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegateFactory.java index a59d4796e..d552c4e8c 100644 --- a/weaver/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegateFactory.java +++ b/weaver/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegateFactory.java @@ -34,24 +34,24 @@ import org.aspectj.weaver.World; public class ReflectionBasedReferenceTypeDelegateFactory { public static ReflectionBasedReferenceTypeDelegate - createDelegate(ReferenceType forReferenceType, World inWorld) { + createDelegate(ReferenceType forReferenceType, World inWorld, ClassLoader usingClassLoader) { try { - Class c = Class.forName(forReferenceType.getName()); + Class c = Class.forName(forReferenceType.getName(),false,usingClassLoader); if (LangUtil.is15VMOrGreater()) { - ReflectionBasedReferenceTypeDelegate rbrtd = create15Delegate(forReferenceType,c,inWorld); + ReflectionBasedReferenceTypeDelegate rbrtd = create15Delegate(forReferenceType,c,usingClassLoader,inWorld); if (rbrtd!=null) return rbrtd; // can be null if we didn't find the class the delegate logic loads } - return new ReflectionBasedReferenceTypeDelegate(c,inWorld,forReferenceType); + return new ReflectionBasedReferenceTypeDelegate(c,usingClassLoader,inWorld,forReferenceType); } catch (ClassNotFoundException cnfEx) { return null; } } - private static ReflectionBasedReferenceTypeDelegate create15Delegate(ReferenceType forReferenceType, Class forClass, World inWorld) { + private static ReflectionBasedReferenceTypeDelegate create15Delegate(ReferenceType forReferenceType, Class forClass, ClassLoader usingClassLoader, World inWorld) { try { - Class delegateClass = Class.forName("org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate"); + Class delegateClass = Class.forName("org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate",false,usingClassLoader); ReflectionBasedReferenceTypeDelegate ret = (ReflectionBasedReferenceTypeDelegate) delegateClass.newInstance(); - ret.initialize(forReferenceType,forClass,inWorld); + ret.initialize(forReferenceType,forClass,usingClassLoader,inWorld); return ret; } catch (ClassNotFoundException cnfEx) { return null; @@ -88,11 +88,15 @@ public class ReflectionBasedReferenceTypeDelegateFactory { toResolvedTypeArray(aMethod.getExceptionTypes(),inWorld), aMethod ); + if (inWorld instanceof ReflectionWorld) { + ret.setAnnotationFinder(((ReflectionWorld)inWorld).getAnnotationFinder()); + } return ret; } public static ResolvedMember createResolvedAdviceMember(Method aMethod, World inWorld) { - return new ReflectionBasedResolvedMemberImpl(org.aspectj.weaver.Member.ADVICE, + ReflectionBasedResolvedMemberImpl ret = + new ReflectionBasedResolvedMemberImpl(org.aspectj.weaver.Member.ADVICE, toResolvedType(aMethod.getDeclaringClass(),(ReflectionWorld)inWorld), aMethod.getModifiers(), toResolvedType(aMethod.getReturnType(),(ReflectionWorld)inWorld), @@ -101,6 +105,10 @@ public class ReflectionBasedReferenceTypeDelegateFactory { toResolvedTypeArray(aMethod.getExceptionTypes(),inWorld), aMethod ); + if (inWorld instanceof ReflectionWorld) { + ret.setAnnotationFinder(((ReflectionWorld)inWorld).getAnnotationFinder()); + } + return ret; } public static ResolvedMember createStaticInitMember(Class forType, World inWorld) { @@ -115,7 +123,8 @@ public class ReflectionBasedReferenceTypeDelegateFactory { } public static ResolvedMember createResolvedConstructor(Constructor aConstructor, World inWorld) { - return new ReflectionBasedResolvedMemberImpl(org.aspectj.weaver.Member.CONSTRUCTOR, + ReflectionBasedResolvedMemberImpl ret = + new ReflectionBasedResolvedMemberImpl(org.aspectj.weaver.Member.CONSTRUCTOR, toResolvedType(aConstructor.getDeclaringClass(),(ReflectionWorld)inWorld), aConstructor.getModifiers(), toResolvedType(aConstructor.getDeclaringClass(),(ReflectionWorld)inWorld), @@ -124,16 +133,25 @@ public class ReflectionBasedReferenceTypeDelegateFactory { toResolvedTypeArray(aConstructor.getExceptionTypes(),inWorld), aConstructor ); + if (inWorld instanceof ReflectionWorld) { + ret.setAnnotationFinder(((ReflectionWorld)inWorld).getAnnotationFinder()); + } + return ret; } public static ResolvedMember createResolvedField(Field aField, World inWorld) { - return new ReflectionBasedResolvedMemberImpl(org.aspectj.weaver.Member.FIELD, + ReflectionBasedResolvedMemberImpl ret = + new ReflectionBasedResolvedMemberImpl(org.aspectj.weaver.Member.FIELD, toResolvedType(aField.getDeclaringClass(),(ReflectionWorld)inWorld), aField.getModifiers(), toResolvedType(aField.getType(),(ReflectionWorld)inWorld), aField.getName(), new UnresolvedType[0], aField); + if (inWorld instanceof ReflectionWorld) { + ret.setAnnotationFinder(((ReflectionWorld)inWorld).getAnnotationFinder()); + } + return ret; } public static ResolvedMember createHandlerMember(Class exceptionType, Class inType,World inWorld) { @@ -145,6 +163,17 @@ public class ReflectionBasedReferenceTypeDelegateFactory { "(" + inWorld.resolve(exceptionType.getName()).getSignature() + ")V"); } + public static ResolvedType resolveTypeInWorld(Class aClass, World aWorld) { +// classes that represent arrays return a class name that is the signature of the array type, ho-hum... + String className = aClass.getName(); + if (aClass.isArray()) { + return aWorld.resolve(UnresolvedType.forSignature(className)); + } + else{ + return aWorld.resolve(className); + } + } + private static ResolvedType toResolvedType(Class aClass, ReflectionWorld aWorld) { return aWorld.resolve(aClass); } diff --git a/weaver/src/org/aspectj/weaver/reflect/ReflectionBasedResolvedMemberImpl.java b/weaver/src/org/aspectj/weaver/reflect/ReflectionBasedResolvedMemberImpl.java index 6380e6576..ecdd60d1f 100644 --- a/weaver/src/org/aspectj/weaver/reflect/ReflectionBasedResolvedMemberImpl.java +++ b/weaver/src/org/aspectj/weaver/reflect/ReflectionBasedResolvedMemberImpl.java @@ -25,16 +25,7 @@ import org.aspectj.weaver.UnresolvedType; */ public class ReflectionBasedResolvedMemberImpl extends ResolvedMemberImpl { - private static AnnotationFinder annotationFinder = null; - - static { - try { - Class java15AnnotationFinder = Class.forName("org.aspectj.weaver.reflect.Java15AnnotationFinder"); - annotationFinder = (AnnotationFinder) java15AnnotationFinder.newInstance(); - } catch(Exception ex) { - // must be on 1.4 or earlier - } - } + private AnnotationFinder annotationFinder = null; private Member reflectMember; @@ -110,6 +101,10 @@ public class ReflectionBasedResolvedMemberImpl extends ResolvedMemberImpl { this.reflectMember = reflectMember; } + public void setAnnotationFinder(AnnotationFinder finder) { + this.annotationFinder = finder; + } + public boolean hasAnnotation(UnresolvedType ofType) { unpackAnnotations(); return super.hasAnnotation(ofType); diff --git a/weaver/src/org/aspectj/weaver/reflect/ReflectionShadow.java b/weaver/src/org/aspectj/weaver/reflect/ReflectionShadow.java index 35a1ace10..a8ce5659d 100644 --- a/weaver/src/org/aspectj/weaver/reflect/ReflectionShadow.java +++ b/weaver/src/org/aspectj/weaver/reflect/ReflectionShadow.java @@ -44,6 +44,7 @@ public class ReflectionShadow extends Shadow { private Map withinAnnotationVar = new HashMap(); private Map withinCodeAnnotationVar = new HashMap(); private Map annotationVar = new HashMap(); + private AnnotationFinder annotationFinder; public static Shadow makeExecutionShadow(World inWorld, java.lang.reflect.Member forMethod) { Kind kind = (forMethod instanceof Method) ? Shadow.MethodExecution : Shadow.ConstructorExecution; @@ -157,6 +158,9 @@ public class ReflectionShadow extends Shadow { this.world = world; this.enclosingType = enclosingType; this.enclosingMember = enclosingMember; + if (world instanceof ReflectionWorld) { + this.annotationFinder = ((ReflectionWorld)world).getAnnotationFinder(); + } } /* (non-Javadoc) @@ -171,7 +175,7 @@ public class ReflectionShadow extends Shadow { */ public Var getThisVar() { if (thisVar == null && hasThis()) { - thisVar = ReflectionVar.createThisVar(getThisType().resolve(world)); + thisVar = ReflectionVar.createThisVar(getThisType().resolve(world),this.annotationFinder); } return thisVar; } @@ -181,7 +185,7 @@ public class ReflectionShadow extends Shadow { */ public Var getTargetVar() { if (targetVar == null && hasTarget()) { - targetVar = ReflectionVar.createTargetVar(getThisType().resolve(world)); + targetVar = ReflectionVar.createTargetVar(getThisType().resolve(world),this.annotationFinder); } return targetVar; } @@ -200,7 +204,7 @@ public class ReflectionShadow extends Shadow { if (argsVars == null) { this.argsVars = new Var[this.getArgCount()]; for (int j = 0; j < this.argsVars.length; j++) { - this.argsVars[j] = ReflectionVar.createArgsVar(getArgType(j).resolve(world), j); + this.argsVars[j] = ReflectionVar.createArgsVar(getArgType(j).resolve(world), j,this.annotationFinder); } } if (i < argsVars.length) { @@ -240,7 +244,7 @@ public class ReflectionShadow extends Shadow { public Var getKindedAnnotationVar(UnresolvedType forAnnotationType) { ResolvedType annType = forAnnotationType.resolve(world); if (annotationVar.get(annType) == null) { - Var v = ReflectionVar.createAtAnnotationVar(annType); + Var v = ReflectionVar.createAtAnnotationVar(annType,this.annotationFinder); annotationVar.put(annType,v); } return (Var) annotationVar.get(annType); @@ -252,7 +256,7 @@ public class ReflectionShadow extends Shadow { public Var getWithinAnnotationVar(UnresolvedType forAnnotationType) { ResolvedType annType = forAnnotationType.resolve(world); if (withinAnnotationVar.get(annType) == null) { - Var v = ReflectionVar.createWithinAnnotationVar(annType); + Var v = ReflectionVar.createWithinAnnotationVar(annType,this.annotationFinder); withinAnnotationVar.put(annType,v); } return (Var) withinAnnotationVar.get(annType); @@ -264,7 +268,7 @@ public class ReflectionShadow extends Shadow { public Var getWithinCodeAnnotationVar(UnresolvedType forAnnotationType) { ResolvedType annType = forAnnotationType.resolve(world); if (withinCodeAnnotationVar.get(annType) == null) { - Var v = ReflectionVar.createWithinCodeAnnotationVar(annType); + Var v = ReflectionVar.createWithinCodeAnnotationVar(annType,this.annotationFinder); withinCodeAnnotationVar.put(annType,v); } return (Var) withinCodeAnnotationVar.get(annType); @@ -275,7 +279,7 @@ public class ReflectionShadow extends Shadow { */ public Var getThisAnnotationVar(UnresolvedType forAnnotationType) { if (atThisVar == null) { - atThisVar = ReflectionVar.createThisAnnotationVar(forAnnotationType.resolve(world)); + atThisVar = ReflectionVar.createThisAnnotationVar(forAnnotationType.resolve(world),this.annotationFinder); } return atThisVar; } @@ -285,7 +289,7 @@ public class ReflectionShadow extends Shadow { */ public Var getTargetAnnotationVar(UnresolvedType forAnnotationType) { if (atTargetVar == null) { - atTargetVar = ReflectionVar.createTargetAnnotationVar(forAnnotationType.resolve(world)); + atTargetVar = ReflectionVar.createTargetAnnotationVar(forAnnotationType.resolve(world),this.annotationFinder); } return atTargetVar; } @@ -302,7 +306,7 @@ public class ReflectionShadow extends Shadow { Var[] vars = (Var[]) atArgsVars.get(annType); if (i > (vars.length - 1) ) return null; if (vars[i] == null) { - vars[i] = ReflectionVar.createArgsAnnotationVar(annType, i); + vars[i] = ReflectionVar.createArgsAnnotationVar(annType, i,this.annotationFinder); } return vars[i]; } diff --git a/weaver/src/org/aspectj/weaver/reflect/ReflectionVar.java b/weaver/src/org/aspectj/weaver/reflect/ReflectionVar.java index 5fda4c347..93be15ceb 100644 --- a/weaver/src/org/aspectj/weaver/reflect/ReflectionVar.java +++ b/weaver/src/org/aspectj/weaver/reflect/ReflectionVar.java @@ -31,78 +31,84 @@ public class ReflectionVar extends Var { static final int AT_WITHINCODE_VAR = 7; static final int AT_ANNOTATION_VAR = 8; - private static AnnotationFinder annotationFinder = null; + private AnnotationFinder annotationFinder = null; - static { - try { - Class java15AnnotationFinder = Class.forName("org.aspectj.weaver.reflect.Java15AnnotationFinder"); - annotationFinder = (AnnotationFinder) java15AnnotationFinder.newInstance(); - } catch(Exception ex) { - // must be on 1.4 or earlier - } - } +// static { +// try { +// Class java15AnnotationFinder = Class.forName("org.aspectj.weaver.reflect.Java15AnnotationFinder"); +// annotationFinder = (AnnotationFinder) java15AnnotationFinder.newInstance(); +// } catch(ClassNotFoundException ex) { +// // must be on 1.4 or earlier +// } catch(IllegalAccessException ex) { +// // not so good +// throw new RuntimeException("AspectJ internal error",ex); +// } catch(InstantiationException ex) { +// throw new RuntimeException("AspectJ internal error",ex); +// } +// } private int argsIndex = 0; private int varType; - public static ReflectionVar createThisVar(ResolvedType type) { - ReflectionVar ret = new ReflectionVar(type); + public static ReflectionVar createThisVar(ResolvedType type,AnnotationFinder finder) { + ReflectionVar ret = new ReflectionVar(type,finder); ret.varType = THIS_VAR; return ret; } - public static ReflectionVar createTargetVar(ResolvedType type) { - ReflectionVar ret = new ReflectionVar(type); + public static ReflectionVar createTargetVar(ResolvedType type, AnnotationFinder finder) { + ReflectionVar ret = new ReflectionVar(type,finder); ret.varType = TARGET_VAR; return ret; } - public static ReflectionVar createArgsVar(ResolvedType type, int index) { - ReflectionVar ret = new ReflectionVar(type); + public static ReflectionVar createArgsVar(ResolvedType type, int index, AnnotationFinder finder) { + ReflectionVar ret = new ReflectionVar(type,finder); ret.varType = ARGS_VAR; ret.argsIndex = index; return ret; } - public static ReflectionVar createThisAnnotationVar(ResolvedType type) { - ReflectionVar ret = new ReflectionVar(type); + public static ReflectionVar createThisAnnotationVar(ResolvedType type, AnnotationFinder finder) { + ReflectionVar ret = new ReflectionVar(type,finder); ret.varType = AT_THIS_VAR; return ret; } - public static ReflectionVar createTargetAnnotationVar(ResolvedType type) { - ReflectionVar ret = new ReflectionVar(type); + public static ReflectionVar createTargetAnnotationVar(ResolvedType type, AnnotationFinder finder) { + ReflectionVar ret = new ReflectionVar(type,finder); ret.varType = AT_TARGET_VAR; return ret; } - public static ReflectionVar createArgsAnnotationVar(ResolvedType type, int index) { - ReflectionVar ret = new ReflectionVar(type); + public static ReflectionVar createArgsAnnotationVar(ResolvedType type, int index, AnnotationFinder finder) { + ReflectionVar ret = new ReflectionVar(type,finder); ret.varType = AT_ARGS_VAR; ret.argsIndex = index; return ret; } - public static ReflectionVar createWithinAnnotationVar(ResolvedType annType) { - ReflectionVar ret = new ReflectionVar(annType); + public static ReflectionVar createWithinAnnotationVar(ResolvedType annType, AnnotationFinder finder) { + ReflectionVar ret = new ReflectionVar(annType,finder); ret.varType = AT_WITHIN_VAR; return ret; } - public static ReflectionVar createWithinCodeAnnotationVar(ResolvedType annType) { - ReflectionVar ret = new ReflectionVar(annType); + public static ReflectionVar createWithinCodeAnnotationVar(ResolvedType annType, AnnotationFinder finder) { + ReflectionVar ret = new ReflectionVar(annType,finder); ret.varType = AT_WITHINCODE_VAR; return ret; } - public static ReflectionVar createAtAnnotationVar(ResolvedType annType) { - ReflectionVar ret = new ReflectionVar(annType); + public static ReflectionVar createAtAnnotationVar(ResolvedType annType, AnnotationFinder finder) { + ReflectionVar ret = new ReflectionVar(annType,finder); ret.varType = AT_ANNOTATION_VAR; return ret; } - private ReflectionVar(ResolvedType type) { + private ReflectionVar(ResolvedType type,AnnotationFinder finder) { super(type); + this.annotationFinder = finder; } diff --git a/weaver/src/org/aspectj/weaver/reflect/ReflectionWorld.java b/weaver/src/org/aspectj/weaver/reflect/ReflectionWorld.java index 6ffc84b51..17a35c562 100644 --- a/weaver/src/org/aspectj/weaver/reflect/ReflectionWorld.java +++ b/weaver/src/org/aspectj/weaver/reflect/ReflectionWorld.java @@ -37,10 +37,50 @@ import org.aspectj.weaver.patterns.PerClause.Kind; */ public class ReflectionWorld extends World { + private ClassLoader classLoader; + private AnnotationFinder annotationFinder; + public ReflectionWorld() { super(); this.setMessageHandler(new ExceptionBasedMessageHandler()); setBehaveInJava5Way(LangUtil.is15VMOrGreater()); + this.classLoader = ReflectionWorld.class.getClassLoader(); + if (LangUtil.is15VMOrGreater()) { + initializeAnnotationFinder(this.classLoader); + } + } + + public ReflectionWorld(ClassLoader aClassLoader) { + super(); + this.setMessageHandler(new ExceptionBasedMessageHandler()); + setBehaveInJava5Way(LangUtil.is15VMOrGreater()); + this.classLoader = aClassLoader; + if (LangUtil.is15VMOrGreater()) { + initializeAnnotationFinder(this.classLoader); + } + } + + private void initializeAnnotationFinder(ClassLoader loader) { + try { + Class java15AnnotationFinder = Class.forName("org.aspectj.weaver.reflect.Java15AnnotationFinder"); + this.annotationFinder = (AnnotationFinder) java15AnnotationFinder.newInstance(); + this.annotationFinder.setClassLoader(loader); + } catch(ClassNotFoundException ex) { + // must be on 1.4 or earlier + } catch(IllegalAccessException ex) { + // not so good + throw new RuntimeException("AspectJ internal error",ex); + } catch(InstantiationException ex) { + throw new RuntimeException("AspectJ internal error",ex); + } + } + + public ClassLoader getClassLoader() { + return this.classLoader; + } + + public AnnotationFinder getAnnotationFinder() { + return this.annotationFinder; } public ResolvedType resolve(Class aClass) { @@ -58,7 +98,7 @@ public class ReflectionWorld extends World { * @see org.aspectj.weaver.World#resolveDelegate(org.aspectj.weaver.ReferenceType) */ protected ReferenceTypeDelegate resolveDelegate(ReferenceType ty) { - return ReflectionBasedReferenceTypeDelegateFactory.createDelegate(ty, this); + return ReflectionBasedReferenceTypeDelegateFactory.createDelegate(ty, this, this.classLoader); } /* (non-Javadoc) diff --git a/weaver/src/org/aspectj/weaver/tools/PointcutParser.java b/weaver/src/org/aspectj/weaver/tools/PointcutParser.java index ef42e89e3..533f9938f 100644 --- a/weaver/src/org/aspectj/weaver/tools/PointcutParser.java +++ b/weaver/src/org/aspectj/weaver/tools/PointcutParser.java @@ -11,8 +11,12 @@ package org.aspectj.weaver.tools; import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; import java.util.HashSet; import java.util.Iterator; +import java.util.Properties; import java.util.Set; import org.aspectj.bridge.IMessageHandler; @@ -27,6 +31,7 @@ import org.aspectj.weaver.UnresolvedType; import org.aspectj.weaver.World; import org.aspectj.weaver.bcel.AtAjAttributes; import org.aspectj.weaver.internal.tools.PointcutExpressionImpl; +import org.aspectj.weaver.internal.tools.TypePatternMatcherImpl; import org.aspectj.weaver.patterns.AndPointcut; import org.aspectj.weaver.patterns.CflowPointcut; import org.aspectj.weaver.patterns.FormalBinding; @@ -40,6 +45,7 @@ import org.aspectj.weaver.patterns.Pointcut; import org.aspectj.weaver.patterns.SimpleScope; import org.aspectj.weaver.patterns.ThisOrTargetAnnotationPointcut; import org.aspectj.weaver.patterns.ThisOrTargetPointcut; +import org.aspectj.weaver.patterns.TypePattern; import org.aspectj.weaver.reflect.PointcutParameterImpl; import org.aspectj.weaver.reflect.ReflectionWorld; @@ -49,7 +55,8 @@ import org.aspectj.weaver.reflect.ReflectionWorld; */ public class PointcutParser { - private static World world = new ReflectionWorld(); + private World world; + private ClassLoader classLoader; private Set supportedPrimitives; /** @@ -96,6 +103,7 @@ public class PointcutParser { */ public PointcutParser() { supportedPrimitives = getAllSupportedPointcutPrimitives(); + setClassLoader(PointcutParser.class.getClassLoader()); } /** @@ -123,6 +131,61 @@ public class PointcutParser { throw new UnsupportedOperationException("Cannot handle if, cflow, and cflowbelow primitives"); } } + setClassLoader(PointcutParser.class.getClassLoader()); + } + + /** + * Create a pointcut parser that can parse pointcut expressions built + * from a user-defined subset of AspectJ's supported pointcut primitives. + * The following restrictions apply: + *
    + *
  • The if, cflow, and cflowbelow pointcut designators are not supported + *
  • Pointcut expressions must be self-contained :- they cannot contain references + * to other named pointcuts + *
  • The pointcut expression must be anonymous with no formals allowed. + *
+ * @param supportedPointcutKinds a set of PointcutPrimitives this parser + * should support + * @param classLoader the class loader to use for resolving types + * @throws UnsupportedOperationException if the set contains if, cflow, or + * cflow below + */ + public PointcutParser(Set/**/ supportedPointcutKinds,ClassLoader cl) { + this(supportedPointcutKinds); + setClassLoader(cl); + } + + /** + * Set the classloader that this parser should use for + * type resolution. + * @param aLoader + */ + public void setClassLoader(ClassLoader aLoader) { + this.classLoader = aLoader; + world = new ReflectionWorld(this.classLoader); + } + + /** + * Set the lint properties for this parser from the + * given resource on the classpath. + * @param resourcePath path to a file containing aspectj + * lint properties + */ + public void setLintProperties(String resourcePath)throws IOException { + URL url = this.classLoader.getResource(resourcePath); + InputStream is = url.openStream(); + Properties p = new Properties(); + p.load(is); + setLintProperties(p); + } + + /** + * Set the lint properties for this parser from the + * given properties set. + * @param properties + */ + public void setLintProperties(Properties properties) { + getWorld().getLint().setFromProperties(properties); } public PointcutParameter createPointcutParameter(String name, Class type) { @@ -168,9 +231,9 @@ public class PointcutParser { pc = pc.resolve(resolutionScope); ResolvedType declaringTypeForResolution = null; if (inScope != null) { - declaringTypeForResolution = world.resolve(inScope.getName()); + declaringTypeForResolution = getWorld().resolve(inScope.getName()); } else { - declaringTypeForResolution = ResolvedType.OBJECT.resolve(world); + declaringTypeForResolution = ResolvedType.OBJECT.resolve(getWorld()); } IntMap arity = new IntMap(formalParameters.length); for (int i = 0; i < formalParameters.length; i++) { @@ -178,7 +241,7 @@ public class PointcutParser { } pc = pc.concretize(declaringTypeForResolution, declaringTypeForResolution, arity); validateAgainstSupportedPrimitives(pc,expression); // again, because we have now followed any ref'd pcuts - pcExpr = new PointcutExpressionImpl(pc,expression,formalParameters,world); + pcExpr = new PointcutExpressionImpl(pc,expression,formalParameters,getWorld()); } catch (ParserException pEx) { throw new IllegalArgumentException(buildUserMessageFromParserException(expression,pEx)); } catch (ReflectionWorld.ReflectionWorldException rwEx) { @@ -187,6 +250,32 @@ public class PointcutParser { return pcExpr; } + /** + * Parse the given aspectj type pattern, and return a + * matcher that can be used to match types using it. + * @param typePattern an aspectj type pattern + * @return a type pattern matcher that matches using the given + * pattern + * @throws IllegalArgumentException if the type pattern cannot + * be successfully parsed. + */ + public TypePatternMatcher parseTypePattern(String typePattern) + throws IllegalArgumentException { + try { + TypePattern tp = new PatternParser(typePattern).parseTypePattern(); + tp.resolve(world); + return new TypePatternMatcherImpl(tp,world); + } catch (ParserException pEx) { + throw new IllegalArgumentException(buildUserMessageFromParserException(typePattern,pEx)); + } catch (ReflectionWorld.ReflectionWorldException rwEx) { + throw new IllegalArgumentException(rwEx.getMessage()); + } + } + + private World getWorld() { + return world; + } + /* for testing */ Set getSupportedPrimitives() { return supportedPrimitives; @@ -194,8 +283,8 @@ public class PointcutParser { /* for testing */ IMessageHandler setCustomMessageHandler(IMessageHandler aHandler) { - IMessageHandler current = world.getMessageHandler(); - world.setMessageHandler(aHandler); + IMessageHandler current = getWorld().getMessageHandler(); + getWorld().setMessageHandler(aHandler); return current; } @@ -206,9 +295,9 @@ public class PointcutParser { formalBindings[i] = new FormalBinding(UnresolvedType.forName(formalParameters[i].getType().getName()),formalParameters[i].getName(),i); } if (inScope == null) { - return new SimpleScope(world,formalBindings); + return new SimpleScope(getWorld(),formalBindings); } else { - ResolvedType inType = world.resolve(inScope.getName()); + ResolvedType inType = getWorld().resolve(inScope.getName()); ISourceContext sourceContext = new ISourceContext() { public ISourceLocation makeSourceLocation(IHasPosition position) { return new SourceLocation(new File(""),0); diff --git a/weaver/src/org/aspectj/weaver/tools/TypePatternMatcher.java b/weaver/src/org/aspectj/weaver/tools/TypePatternMatcher.java new file mode 100644 index 000000000..b1659eaf8 --- /dev/null +++ b/weaver/src/org/aspectj/weaver/tools/TypePatternMatcher.java @@ -0,0 +1,23 @@ +/* ******************************************************************* + * Copyright (c) 2004 IBM Corporation. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Common Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * ******************************************************************/ +package org.aspectj.weaver.tools; + +/** + * A compiled AspectJ type pattern that can be used to + * match against types at runtime. + */ +public interface TypePatternMatcher { + + /** + * Does this type pattern matcher match the + * given type (Class). + */ + public boolean matches(Class aClass); +} diff --git a/weaver/testsrc/org/aspectj/weaver/tools/PointcutParserTest.java b/weaver/testsrc/org/aspectj/weaver/tools/PointcutParserTest.java index 131ec1975..eef456b17 100644 --- a/weaver/testsrc/org/aspectj/weaver/tools/PointcutParserTest.java +++ b/weaver/testsrc/org/aspectj/weaver/tools/PointcutParserTest.java @@ -10,6 +10,7 @@ package org.aspectj.weaver.tools; import java.util.HashSet; +import java.util.Properties; import java.util.Set; import org.aspectj.bridge.AbortException; @@ -242,6 +243,19 @@ public class PointcutParserTest extends TestCase { } } + public void testXLintConfiguration() { + PointcutParser p = new PointcutParser(); + try { + p.parsePointcutExpression("this(FooBar)"); + } catch(IllegalArgumentException ex) { + assertTrue("should have xlint:invalidAbsoluteTypeName",ex.getMessage().indexOf("Xlint:invalidAbsoluteTypeName") != -1); + } + Properties props = new Properties(); + props.put("invalidAbsoluteTypeName","ignore"); + p.setLintProperties(props); + p.parsePointcutExpression("this(FooBar)"); + } + private static class IgnoreWarningsMessageHandler implements IMessageHandler { public boolean handleMessage(IMessage message) throws AbortException { diff --git a/weaver/testsrc/org/aspectj/weaver/tools/ToolsTests.java b/weaver/testsrc/org/aspectj/weaver/tools/ToolsTests.java index 4abb23532..aa91c9f65 100644 --- a/weaver/testsrc/org/aspectj/weaver/tools/ToolsTests.java +++ b/weaver/testsrc/org/aspectj/weaver/tools/ToolsTests.java @@ -19,6 +19,7 @@ public class ToolsTests { //$JUnit-BEGIN$ suite.addTestSuite(PointcutParserTest.class); suite.addTestSuite(PointcutExpressionTest.class); + suite.addTestSuite(TypePatternMatcherTest.class); //$JUnit-END$ return suite; } diff --git a/weaver/testsrc/org/aspectj/weaver/tools/TypePatternMatcherTest.java b/weaver/testsrc/org/aspectj/weaver/tools/TypePatternMatcherTest.java new file mode 100644 index 000000000..4cf6568b4 --- /dev/null +++ b/weaver/testsrc/org/aspectj/weaver/tools/TypePatternMatcherTest.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.aspectj.weaver.tools; + +import java.util.HashMap; +import java.util.Map; + +import junit.framework.TestCase; + +public class TypePatternMatcherTest extends TestCase { + + TypePatternMatcher tpm; + + public void testMatching() { + assertTrue("Map+ matches Map",tpm.matches(Map.class)); + assertTrue("Map+ matches HashMap",tpm.matches(HashMap.class)); + assertFalse("Map+ does not match String",tpm.matches(String.class)); + } + + protected void setUp() throws Exception { + super.setUp(); + PointcutParser pp = new PointcutParser(); + tpm = pp.parseTypePattern("java.util.Map+"); + } + + + +} diff --git a/weaver5/java5-src/org/aspectj/weaver/reflect/Java15AnnotationFinder.java b/weaver5/java5-src/org/aspectj/weaver/reflect/Java15AnnotationFinder.java index 31abe3056..31de59c62 100644 --- a/weaver5/java5-src/org/aspectj/weaver/reflect/Java15AnnotationFinder.java +++ b/weaver5/java5-src/org/aspectj/weaver/reflect/Java15AnnotationFinder.java @@ -35,9 +35,15 @@ import org.aspectj.weaver.World; public class Java15AnnotationFinder implements AnnotationFinder { private Repository bcelRepository; + private ClassLoader classLoader; + // must have no-arg constructor for reflective construction public Java15AnnotationFinder() { - this.bcelRepository = new ClassLoaderRepository(getClass().getClassLoader()); + } + + public void setClassLoader(ClassLoader aLoader) { + this.bcelRepository = new ClassLoaderRepository(aLoader); + this.classLoader = aLoader; } /* (non-Javadoc) @@ -45,7 +51,7 @@ public class Java15AnnotationFinder implements AnnotationFinder { */ public Object getAnnotation(ResolvedType annotationType, Object onObject) { try { - Class annotationClass = Class.forName(annotationType.getName()); + Class annotationClass = Class.forName(annotationType.getName(),false,classLoader); if (onObject.getClass().isAnnotationPresent(annotationClass)) { return onObject.getClass().getAnnotation(annotationClass); } @@ -57,7 +63,7 @@ public class Java15AnnotationFinder implements AnnotationFinder { public Object getAnnotationFromClass(ResolvedType annotationType, Class aClass) { try { - Class annotationClass = Class.forName(annotationType.getName()); + Class annotationClass = Class.forName(annotationType.getName(),false,classLoader); if (aClass.isAnnotationPresent(annotationClass)) { return aClass.getAnnotation(annotationClass); } @@ -71,7 +77,7 @@ public class Java15AnnotationFinder implements AnnotationFinder { if (!(aMember instanceof AccessibleObject)) return null; AccessibleObject ao = (AccessibleObject) aMember; try { - Class annotationClass = Class.forName(annotationType.getName()); + Class annotationClass = Class.forName(annotationType.getName(),false,classLoader); if (ao.isAnnotationPresent(annotationClass)) { return ao.getAnnotation(annotationClass); } diff --git a/weaver5/java5-src/org/aspectj/weaver/reflect/Java15ReflectionBasedReferenceTypeDelegate.java b/weaver5/java5-src/org/aspectj/weaver/reflect/Java15ReflectionBasedReferenceTypeDelegate.java index c1e2d357a..c1f3c9fd4 100644 --- a/weaver5/java5-src/org/aspectj/weaver/reflect/Java15ReflectionBasedReferenceTypeDelegate.java +++ b/weaver5/java5-src/org/aspectj/weaver/reflect/Java15ReflectionBasedReferenceTypeDelegate.java @@ -57,14 +57,17 @@ public class Java15ReflectionBasedReferenceTypeDelegate extends private ResolvedType superclass; private ResolvedType[] superInterfaces; private String genericSignature = null; - private Java15AnnotationFinder annotationFinder = new Java15AnnotationFinder(); + private Java15AnnotationFinder annotationFinder = null; public Java15ReflectionBasedReferenceTypeDelegate() {} - public void initialize(ReferenceType aType, Class aClass, World aWorld) { - super.initialize(aType, aClass, aWorld); + @Override + public void initialize(ReferenceType aType, Class aClass, ClassLoader classLoader, World aWorld) { + super.initialize(aType, aClass, classLoader, aWorld); myType = AjTypeSystem.getAjType(aClass); + annotationFinder = new Java15AnnotationFinder(); + annotationFinder.setClassLoader(classLoader); } @@ -169,6 +172,7 @@ public class Java15ReflectionBasedReferenceTypeDelegate extends fromTypes(forMethod.getGenericExceptionTypes()), forMethod ); + ret.setAnnotationFinder(this.annotationFinder); return ret; } @@ -183,11 +187,13 @@ public class Java15ReflectionBasedReferenceTypeDelegate extends fromTypes(forConstructor.getGenericExceptionTypes()), forConstructor ); + ret.setAnnotationFinder(this.annotationFinder); return ret; } private ResolvedMember createGenericFieldMember(Field forField) { - return new ReflectionBasedResolvedMemberImpl( + ReflectionBasedResolvedMemberImpl ret = + new ReflectionBasedResolvedMemberImpl( org.aspectj.weaver.Member.FIELD, getResolvedTypeX(), forField.getModifiers(), @@ -195,6 +201,8 @@ public class Java15ReflectionBasedReferenceTypeDelegate extends forField.getName(), new UnresolvedType[0], forField); + ret.setAnnotationFinder(this.annotationFinder); + return ret; } public ResolvedMember[] getDeclaredPointcuts() { -- 2.39.5