From 6d6adfc1327fea030f0547737543df96b5447387 Mon Sep 17 00:00:00 2001 From: aclement Date: Thu, 18 Sep 2008 19:41:30 +0000 Subject: [PATCH] copyright added --- .../aspectj/weaver/bcel/asm/AsmDetector.java | 22 ++++-- .../weaver/bcel/asm/StackMapAdder.java | 71 +++++++++++-------- 2 files changed, 57 insertions(+), 36 deletions(-) diff --git a/weaver/src/org/aspectj/weaver/bcel/asm/AsmDetector.java b/weaver/src/org/aspectj/weaver/bcel/asm/AsmDetector.java index 415e38efc..a2cc74355 100644 --- a/weaver/src/org/aspectj/weaver/bcel/asm/AsmDetector.java +++ b/weaver/src/org/aspectj/weaver/bcel/asm/AsmDetector.java @@ -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"); diff --git a/weaver/src/org/aspectj/weaver/bcel/asm/StackMapAdder.java b/weaver/src/org/aspectj/weaver/bcel/asm/StackMapAdder.java index 96d6a8822..7bdc61dd9 100644 --- a/weaver/src/org/aspectj/weaver/bcel/asm/StackMapAdder.java +++ b/weaver/src/org/aspectj/weaver/bcel/asm/StackMapAdder.java @@ -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('.', '/'); + } + } } } -- 2.39.5