/* *******************************************************************
* 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
* ******************************************************************/
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;
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;
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) {
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());
}
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;
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();