]> source.dussan.org Git - aspectj.git/commitdiff
copyright added
authoraclement <aclement>
Thu, 18 Sep 2008 19:41:30 +0000 (19:41 +0000)
committeraclement <aclement>
Thu, 18 Sep 2008 19:41:30 +0000 (19:41 +0000)
weaver/src/org/aspectj/weaver/bcel/asm/AsmDetector.java
weaver/src/org/aspectj/weaver/bcel/asm/StackMapAdder.java

index 415e38efcd6e8f2e04f17427b63a3b935a66ce99..a2cc743554f7ee50cfd043ea71efc27d985bbe88 100644 (file)
@@ -1,24 +1,34 @@
+/* *******************************************************************
+ * 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");
index 96d6a8822cea18feb536795c48b4510b4f6c5cc6..7bdc61dd9772422b5d7f50a19a9c89275e4d0855 100644 (file)
@@ -1,3 +1,14 @@
+/* *******************************************************************
+ * 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;
@@ -7,9 +18,9 @@ import org.objectweb.asm.ClassReader;
 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
  */
@@ -19,17 +30,17 @@ public class StackMapAdder {
                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);
@@ -38,26 +49,26 @@ public class StackMapAdder {
 
                // 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('.', '/');
+                       }
+               }
        }
 }