]> source.dussan.org Git - aspectj.git/commitdiff
tests and fix for pr116229 and pr116755. Also adds support and tests for parseTypePat...
authoracolyer <acolyer>
Sat, 19 Nov 2005 17:08:48 +0000 (17:08 +0000)
committeracolyer <acolyer>
Sat, 19 Nov 2005 17:08:48 +0000 (17:08 +0000)
24 files changed:
tests/java5/ataspectj/annotationGen/RuntimePointcuts.java
tests/java5/reflection/PointcutLibrary.aj [new file with mode: 0644]
tests/java5/reflection/ReflectOnAjcCompiledPointcuts.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java
tests/src/org/aspectj/systemtest/ajc150/ajc150.xml
tests/src/org/aspectj/systemtest/ajc150/ataspectj/annotationgen.xml
weaver/src/org/aspectj/weaver/bcel/BcelWorld.java
weaver/src/org/aspectj/weaver/internal/tools/TypePatternMatcherImpl.java [new file with mode: 0644]
weaver/src/org/aspectj/weaver/ltw/LTWWorld.java [new file with mode: 0644]
weaver/src/org/aspectj/weaver/ltw/LTWeaver.java [new file with mode: 0644]
weaver/src/org/aspectj/weaver/reflect/AnnotationFinder.java
weaver/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java
weaver/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegateFactory.java
weaver/src/org/aspectj/weaver/reflect/ReflectionBasedResolvedMemberImpl.java
weaver/src/org/aspectj/weaver/reflect/ReflectionShadow.java
weaver/src/org/aspectj/weaver/reflect/ReflectionVar.java
weaver/src/org/aspectj/weaver/reflect/ReflectionWorld.java
weaver/src/org/aspectj/weaver/tools/PointcutParser.java
weaver/src/org/aspectj/weaver/tools/TypePatternMatcher.java [new file with mode: 0644]
weaver/testsrc/org/aspectj/weaver/tools/PointcutParserTest.java
weaver/testsrc/org/aspectj/weaver/tools/ToolsTests.java
weaver/testsrc/org/aspectj/weaver/tools/TypePatternMatcherTest.java [new file with mode: 0644]
weaver5/java5-src/org/aspectj/weaver/reflect/Java15AnnotationFinder.java
weaver5/java5-src/org/aspectj/weaver/reflect/Java15ReflectionBasedReferenceTypeDelegate.java

index 8f9e530d5256123933c36f27cd4ce2f6063b6b4d..171239cd5d2e8880ad7d0fa3e8091bdf44ed1230 100644 (file)
@@ -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 (file)
index 0000000..f3e59e2
--- /dev/null
@@ -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 (file)
index 0000000..9dc9927
--- /dev/null
@@ -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
index 18b73fd8cf47661729c9725a962ecc3364b6da72..253a9fe7215428b5f16da630cdedbc7908fd02e0 100644 (file)
@@ -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
    */
index 7398978850c2e8835100d88831f4f21598d83e8f..c0aa8b9991ead58b9da8500d4d1e19be472e8571 100644 (file)
     <ajc-test dir="bugs150" pr="112756" title="pointcut expression containing 'assert'">
      <compile files="Pr112756.aj" options="-warn:assertIdentifier -Xdev:Pinpoint"/>
     </ajc-test>
-    
+
+       <ajc-test dir="java5/reflection" title="pointcut parsing with ajc compiled pointcut references">
+               <compile files="PointcutLibrary.aj,ReflectOnAjcCompiledPointcuts.java"></compile>
+               <run class="ReflectOnAjcCompiledPointcuts" classpath=".;../lib/aspectj/aspectjtools.jar"/>
+       </ajc-test>
+           
     <ajc-test dir="bugs150/pr114436" title="ClassFormatError binary weaving perthis">
      <compile files="SimpleTrace.aj,ConcreteSimpleTracing.aj" outjar="aspects.jar"/>
      <compile files="TestClass.java" aspectpath="aspects.jar"/>
index 33c28dbb3660eb09fdbe15b0fffee8550a297c49..1ece441170ba52925b33271e29143169cc6e10fa 100644 (file)
    <ajc-test dir="java5/ataspectj/annotationGen" title="runtime pointcut resolution referencing compiled pointcuts">
         <compile files="PCLib.aj,RuntimePointcuts.java" options="-1.5">
         </compile>
-        <run class="RuntimePointcuts" classpath="../lib/bcel/bcel.jar"/>
+        <run class="RuntimePointcuts" classpath=".;../lib/bcel/bcel.jar" ltw=""/>
     </ajc-test>          
 
    <ajc-test dir="java5/ataspectj/annotationGen" title="ann gen for decp">
index 17e70fef527aed11719d1a61ede93ce0e7edaced..63a57792623a96d4fc050708bd9a172d729290a6 100644 (file)
@@ -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 (file)
index 0000000..a498040
--- /dev/null
@@ -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 (file)
index 0000000..7829108
--- /dev/null
@@ -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 (file)
index 0000000..b69cb67
--- /dev/null
@@ -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 {
+
+}
index f2807e4a06f8f8a6c0f7110b8a8c74cfa8becb89..88b2c74508e5722d772492dbcdc7185a3d78e0f3 100644 (file)
@@ -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);
index 622e8c1433d6d611a862df61dd40001c4335b253..2dd8a3d41b4184dbc17a705edfaa014ef9d87cc0 100644 (file)
@@ -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)
index a59d4796e3ff9de2d47f1b7b4dc747856f80ad0c..d552c4e8c608a9417988cd737e733217ce1303a2 100644 (file)
@@ -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);
        }
index 6380e65762e15464659be910be1965a4fe6da1d1..ecdd60d1f0425352c4718da87e9f81ca57776e4b 100644 (file)
@@ -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);
index 35a1ace1050361e37ecd46d16b82cac06d7b871a..a8ce5659dceeb4bf52769e91f1b8ba6ce0b3340c 100644 (file)
@@ -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];
        }
index 5fda4c347b6610cf82d5718af1313d98ddc301fc..93be15ceb97daadce14c75c636ef176af38276c3 100644 (file)
@@ -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;
        }
                        
        
index 6ffc84b5155851ddf0c6ee3aafe6499cd9128a8c..17a35c562329daae951aa03858e6d9390d2e5be6 100644 (file)
@@ -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)
index ef42e89e34d8f9717545667480cf904a470d87f4..533f9938fbd6bdde2c02f5dc0ba36498988cc112 100644 (file)
 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:
+     * <ul>
+     * <li>The <code>if, cflow, and cflowbelow</code> pointcut designators are not supported
+     * <li>Pointcut expressions must be self-contained :- they cannot contain references
+     * to other named pointcuts
+     * <li>The pointcut expression must be anonymous with no formals allowed.
+     * </ul>
+     * @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/*<PointcutPrimitives>*/ 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 (file)
index 0000000..b1659ea
--- /dev/null
@@ -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);
+}
index 131ec197596f1ec2277b9ba6b2fe76ac45127b83..eef456b17204da7b42ccfab726665a7a820ceb8d 100644 (file)
@@ -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 {
index 4abb235321683b85ef8620b8c08c70cbf6673212..aa91c9f65e9a4d97a46407d435f656a5c0d9ac42 100644 (file)
@@ -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 (file)
index 0000000..4cf6568
--- /dev/null
@@ -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+");
+       }
+       
+       
+
+}
index 31abe305654efdbfe4d1a2791f8bbba9a4135828..31de59c62ea65f1541aeab1e7f0710b7314214e1 100644 (file)
@@ -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);
                        }
index c1e2d357a73a97dc596a868ffc234f7d6d241972..c1f3c9fd48137051502952eaceca27b5ef5f67cf 100644 (file)
@@ -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() {