+/* *******************************************************************
+ * Copyright (c) 2008 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://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andy Clement
+ * ******************************************************************/
package org.aspectj.weaver.bcel.asm;
import java.lang.reflect.Method;
/**
- * Determines if a version of asm is around that will enable us to add
- * stack map attributes to classes that we produce.
+ * Determines if a version of asm is around that will enable us to add stack map attributes to classes that we produce.
*
* @author Andy Clement
*/
public class AsmDetector {
public static boolean isAsmAround;
-
+
static {
try {
Class reader = Class.forName("org.objectweb.asm.ClassReader");
Class visitor = Class.forName("org.objectweb.asm.ClassVisitor");
- Method m = reader.getMethod("accept",new Class[]{visitor,Integer.TYPE});
- isAsmAround = m!=null;
- } catch (Exception e ) {
+ Method m = reader.getMethod("accept", new Class[] { visitor, Integer.TYPE });
+ isAsmAround = m != null;
+ } catch (Exception e) {
isAsmAround = false;
}
// System.out.println(isAsmAround?"ASM detected":"No ASM found");
+/* *******************************************************************
+ * Copyright (c) 2008 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://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andy Clement
+ * ******************************************************************/
package org.aspectj.weaver.bcel.asm;
import org.aspectj.weaver.ResolvedType;
import org.objectweb.asm.ClassWriter;
/**
- * Uses asm to add the stack map attribute to methods in a class. The class is passed in as pure byte data
- * and then a reader/writer process it. The writer is wired into the world so that types can be resolved
- * and getCommonSuperClass() can be implemented without class loading using the context class loader.
+ * Uses asm to add the stack map attribute to methods in a class. The class is passed in as pure byte data and then a reader/writer
+ * process it. The writer is wired into the world so that types can be resolved and getCommonSuperClass() can be implemented without
+ * class loading using the context class loader.
*
* @author Andy Clement
*/
try {
ClassReader cr = new ClassReader(data);
ClassWriter cw = new AspectJConnectClassWriter(world);
- cr.accept(cw,0);
- return cw.toByteArray();
+ cr.accept(cw, 0);
+ return cw.toByteArray();
} catch (Throwable t) {
- System.err.println("AspectJ Internal Error: unable to add stackmap attributes. "+t.getMessage());
- AsmDetector.isAsmAround=false;
+ System.err.println("AspectJ Internal Error: unable to add stackmap attributes. " + t.getMessage());
+ AsmDetector.isAsmAround = false;
return data;
}
}
-
+
private static class AspectJConnectClassWriter extends ClassWriter {
- private World world;
+ private final World world;
public AspectJConnectClassWriter(World w) {
super(ClassWriter.COMPUTE_FRAMES);
// Implementation of getCommonSuperClass() that avoids Class.forName()
protected String getCommonSuperClass(final String type1, final String type2) {
-
- ResolvedType resolvedType1 = world.resolve(UnresolvedType.forName(type1.replace('/','.')));
- ResolvedType resolvedType2 = world.resolve(UnresolvedType.forName(type2.replace('/','.')));
-
- if (resolvedType1.isAssignableFrom(resolvedType2)) {
- return type1;
- }
-
- if (resolvedType2.isAssignableFrom(resolvedType1)) {
- return type2;
- }
-
- if (resolvedType1.isInterface() || resolvedType2.isInterface()) {
- return "java/lang/Object";
- } else {
- do {
- resolvedType1 = resolvedType1.getSuperclass();
- } while (!resolvedType1.isAssignableFrom(resolvedType2));
- return resolvedType1.getName().replace('.','/');
- }
- }
+
+ ResolvedType resolvedType1 = world.resolve(UnresolvedType.forName(type1.replace('/', '.')));
+ ResolvedType resolvedType2 = world.resolve(UnresolvedType.forName(type2.replace('/', '.')));
+
+ if (resolvedType1.isAssignableFrom(resolvedType2)) {
+ return type1;
+ }
+
+ if (resolvedType2.isAssignableFrom(resolvedType1)) {
+ return type2;
+ }
+
+ if (resolvedType1.isInterface() || resolvedType2.isInterface()) {
+ return "java/lang/Object";
+ } else {
+ do {
+ resolvedType1 = resolvedType1.getSuperclass();
+ } while (!resolvedType1.isAssignableFrom(resolvedType2));
+ return resolvedType1.getName().replace('.', '/');
+ }
+ }
}
}