]> source.dussan.org Git - aspectj.git/commitdiff
from branch: perclause support and modified delegate processing for multi-threaded...
authoraclement <aclement>
Tue, 19 Apr 2005 12:24:59 +0000 (12:24 +0000)
committeraclement <aclement>
Tue, 19 Apr 2005 12:24:59 +0000 (12:24 +0000)
weaver/src/org/aspectj/weaver/bcel/BcelWorld.java

index d4e425b054625c550c5748faef120a0b69c2e648..218eed2638ad7564274d0acf0bf2f7af6ace6a17 100644 (file)
@@ -1,13 +1,14 @@
 /* *******************************************************************
  * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
- * 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: 
- *     PARC     initial implementation 
+ * 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:
+ *     PARC     initial implementation
+ *     Alexandre Vasseur    perClause support for @AJ aspects
  * ******************************************************************/
 
 
@@ -34,6 +35,7 @@ import org.aspectj.apache.bcel.generic.PUTSTATIC;
 import org.aspectj.apache.bcel.generic.Type;
 import org.aspectj.apache.bcel.util.ClassPath;
 import org.aspectj.apache.bcel.util.Repository;
+import org.aspectj.apache.bcel.util.ClassLoaderRepository;
 import org.aspectj.bridge.IMessageHandler;
 import org.aspectj.weaver.Advice;
 import org.aspectj.weaver.AdviceKind;
@@ -49,10 +51,13 @@ import org.aspectj.weaver.World;
 import org.aspectj.weaver.patterns.FormalBinding;
 import org.aspectj.weaver.patterns.Pointcut;
 import org.aspectj.weaver.patterns.SimpleScope;
+import org.aspectj.weaver.patterns.PerClause;
 
 public class BcelWorld extends World implements Repository {
        private ClassPathManager classPath;
-       
+
+    private Repository delegate;
+
        //private ClassPathManager aspectPath = null;
        // private List aspectPathEntries;
        
@@ -90,7 +95,9 @@ public class BcelWorld extends World implements Repository {
                setMessageHandler(handler);     
                setXRefHandler(xrefHandler);
                // Tell BCEL to use us for resolving any classes
-               org.aspectj.apache.bcel.Repository.setRepository(this);
+        delegate = this;
+               // TODO Alex do we need to call org.aspectj.apache.bcel.Repository.setRepository(delegate);
+        // if so, how can that be safe in J2EE ?? (static stuff in Bcel)
        }
        
        public BcelWorld(ClassPathManager cpm, IMessageHandler handler, ICrossReferenceHandler xrefHandler) {
@@ -98,9 +105,28 @@ public class BcelWorld extends World implements Repository {
                setMessageHandler(handler);
                setXRefHandler(xrefHandler);
                // Tell BCEL to use us for resolving any classes
-               org.aspectj.apache.bcel.Repository.setRepository(this);
+        delegate = this;
+        // TODO Alex do we need to call org.aspectj.apache.bcel.Repository.setRepository(delegate);
+        // if so, how can that be safe in J2EE ?? (static stuff in Bcel)
        }
-       
+
+    /**
+     * Build a World from a ClassLoader, for LTW support
+     *
+     * @param loader
+     * @param handler
+     * @param xrefHandler
+     */
+    public BcelWorld(ClassLoader loader, IMessageHandler handler, ICrossReferenceHandler xrefHandler) {
+        this.classPath = null;
+        setMessageHandler(handler);
+        setXRefHandler(xrefHandler);
+        // Tell BCEL to use us for resolving any classes
+        delegate = new ClassLoaderRepository(loader);
+        // TODO Alex do we need to call org.aspectj.apache.bcel.Repository.setRepository(delegate);
+        // if so, how can that be safe in J2EE ?? (static stuff in Bcel)
+    }
+
        public void addPath (String name) {
                classPath.addPath(name, this.getMessageHandler());
        }
@@ -217,7 +243,14 @@ public class BcelWorld extends World implements Repository {
        
        
        private JavaClass lookupJavaClass(ClassPathManager classPath, String name) {
-               if (classPath == null) return null;
+        if (classPath == null) {
+            try {
+                return delegate.loadClass(name);
+            } catch (ClassNotFoundException e) {
+                return null;
+            }
+        }
+
                try {
                ClassPathManager.ClassFile file = classPath.find(TypeX.forName(name));
                if (file == null) return null;
@@ -367,6 +400,17 @@ public class BcelWorld extends World implements Repository {
                return new BcelCflowCounterFieldAdder(cflowField);
        }
 
+    /**
+     * Register a munger for perclause @AJ aspect so that we add aspectOf(..) to them as needed
+     *
+     * @param aspect
+     * @param kind
+     * @return
+     */
+    public ConcreteTypeMunger makePerClauseAspect(ResolvedTypeX aspect, PerClause.Kind kind) {
+        return new BcelPerClauseAspectAdder(aspect, kind);
+    }
+
        public static BcelObjectType getBcelObjectType(ResolvedTypeX concreteAspect) {
                //XXX need error checking
                return (BcelObjectType) ((ResolvedTypeX.Name)concreteAspect).getDelegate();