From: aclement Date: Mon, 14 Sep 2009 20:29:10 +0000 (+0000) Subject: refactoring X-Git-Tag: V1_6_6~51 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=600b4494987ac17c5bfa6e69172f9ec8be3801fe;p=aspectj.git refactoring --- diff --git a/bcel-builder/src/org/aspectj/apache/bcel/Constants.java b/bcel-builder/src/org/aspectj/apache/bcel/Constants.java index 478ceca11..de498b241 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/Constants.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/Constants.java @@ -59,7 +59,7 @@ import org.aspectj.apache.bcel.generic.Type; /** * Constants for the project, mostly defined in the JVM specification. * - * @version $Id: Constants.java,v 1.5 2008/08/27 23:58:58 aclement Exp $ + * @version $Id: Constants.java,v 1.6 2009/09/14 20:29:10 aclement Exp $ * @author M. Dahm */ public interface Constants { @@ -470,7 +470,7 @@ public interface Constants { public static final Type[] types = new Type[256]; public static final long[] instFlags = new long[256]; - public static final Class[][] instExcs = new Class[256][]; + public static final Class[][] instExcs = new Class[256][]; static final Clinit _unused = new Clinit(); @@ -696,8 +696,8 @@ public interface Constants { instExcs[INSTANCEOF] = ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION; instFlags[MULTIANEWARRAY] = CP_INST | LOADCLASS_INST | EXCEPTION_THROWER | INDEXED; instExcs[MULTIANEWARRAY] = ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION_ANEWARRAY; // fixme i think this is a - // stackproducer, old - // bcel says no... + // stackproducer, old + // bcel says no... instFlags[GETFIELD] = EXCEPTION_THROWER | CP_INST | LOADCLASS_INST | INDEXED; instExcs[GETFIELD] = ExceptionConstants.EXCS_FIELD_AND_METHOD_RESOLUTION_GETFIELD_PUTFIELD; diff --git a/bcel-builder/src/org/aspectj/apache/bcel/ExceptionConstants.java b/bcel-builder/src/org/aspectj/apache/bcel/ExceptionConstants.java index 6b41f4d4a..34455be35 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/ExceptionConstants.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/ExceptionConstants.java @@ -56,104 +56,93 @@ package org.aspectj.apache.bcel; /** * Exception constants. - * - * @version $Id: ExceptionConstants.java,v 1.4 2009/09/09 19:56:20 aclement Exp $ - * @author E. Haase + * + * @version $Id: ExceptionConstants.java,v 1.5 2009/09/14 20:29:10 aclement Exp $ + * @author E. Haase */ public interface ExceptionConstants { - /** The mother of all exceptions - */ - public static final Class THROWABLE = Throwable.class; - - /** Super class of any run-time exception - */ - public static final Class RUNTIME_EXCEPTION = RuntimeException.class; - - /** Super class of any linking exception (aka Linkage Error) - */ - public static final Class LINKING_EXCEPTION = LinkageError.class; - - /** Linking Exceptions - */ - public static final Class CLASS_CIRCULARITY_ERROR = ClassCircularityError.class; - public static final Class CLASS_FORMAT_ERROR = ClassFormatError.class; - public static final Class EXCEPTION_IN_INITIALIZER_ERROR = ExceptionInInitializerError.class; - public static final Class INCOMPATIBLE_CLASS_CHANGE_ERROR = IncompatibleClassChangeError.class; - public static final Class ABSTRACT_METHOD_ERROR = AbstractMethodError.class; - public static final Class ILLEGAL_ACCESS_ERROR = IllegalAccessError.class; - public static final Class INSTANTIATION_ERROR = InstantiationError.class; - public static final Class NO_SUCH_FIELD_ERROR = NoSuchFieldError.class; - public static final Class NO_SUCH_METHOD_ERROR = NoSuchMethodError.class; - public static final Class NO_CLASS_DEF_FOUND_ERROR = NoClassDefFoundError.class; - public static final Class UNSATISFIED_LINK_ERROR = UnsatisfiedLinkError.class; - public static final Class VERIFY_ERROR = VerifyError.class; - - /* UnsupportedClassVersionError is new in JDK 1.2 */ - //public static final Class UnsupportedClassVersionError = UnsupportedClassVersionError.class; - - /** Run-Time Exceptions - */ - public static final Class NULL_POINTER_EXCEPTION = NullPointerException.class; - public static final Class ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION = ArrayIndexOutOfBoundsException.class; - public static final Class ARITHMETIC_EXCEPTION = ArithmeticException.class; - public static final Class NEGATIVE_ARRAY_SIZE_EXCEPTION = NegativeArraySizeException.class; - public static final Class CLASS_CAST_EXCEPTION = ClassCastException.class; - public static final Class ILLEGAL_MONITOR_STATE = IllegalMonitorStateException.class; - - /** Pre-defined exception arrays according to chapters 5.1-5.4 of the Java Virtual - * Machine Specification - */ - public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION = { - NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, VERIFY_ERROR, ABSTRACT_METHOD_ERROR, - EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR - }; // Chapter 5.1 - public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION_MULTIANEWARRAY = { - NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, VERIFY_ERROR, ABSTRACT_METHOD_ERROR, - EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR,NEGATIVE_ARRAY_SIZE_EXCEPTION,ILLEGAL_ACCESS_ERROR - }; - public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION_ANEWARRAY = { - NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, VERIFY_ERROR, ABSTRACT_METHOD_ERROR, - EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR,NEGATIVE_ARRAY_SIZE_EXCEPTION - }; // Chapter 5.1 - public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION_CHECKCAST = { - NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, VERIFY_ERROR, ABSTRACT_METHOD_ERROR, - EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR,CLASS_CAST_EXCEPTION - }; // Chapter 5.1 - public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION_FOR_ALLOCATIONS= { - NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, VERIFY_ERROR, ABSTRACT_METHOD_ERROR, - EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR, INSTANTIATION_ERROR,ILLEGAL_ACCESS_ERROR - }; - - public static final Class[] EXCS_FIELD_AND_METHOD_RESOLUTION = { - NO_SUCH_FIELD_ERROR, ILLEGAL_ACCESS_ERROR, NO_SUCH_METHOD_ERROR - }; // Chapter 5.2 - - public static final Class[] EXCS_FIELD_AND_METHOD_RESOLUTION_GETFIELD_PUTFIELD = { - NO_SUCH_FIELD_ERROR, ILLEGAL_ACCESS_ERROR, NO_SUCH_METHOD_ERROR,INCOMPATIBLE_CLASS_CHANGE_ERROR,NULL_POINTER_EXCEPTION - }; - - public static final Class[] EXCS_FIELD_AND_METHOD_RESOLUTION_GETSTATIC_PUTSTATIC = { - NO_SUCH_FIELD_ERROR, ILLEGAL_ACCESS_ERROR, NO_SUCH_METHOD_ERROR,INCOMPATIBLE_CLASS_CHANGE_ERROR - }; - - public static final Class[] EXCS_INTERFACE_METHOD_RESOLUTION_INVOKEINTERFACE = { - INCOMPATIBLE_CLASS_CHANGE_ERROR,ILLEGAL_ACCESS_ERROR,ABSTRACT_METHOD_ERROR,UNSATISFIED_LINK_ERROR - }; - public static final Class[] EXCS_INTERFACE_METHOD_RESOLUTION_INVOKESPECIAL_INVOKEVIRTUAL = { - INCOMPATIBLE_CLASS_CHANGE_ERROR,NULL_POINTER_EXCEPTION,ABSTRACT_METHOD_ERROR,UNSATISFIED_LINK_ERROR - }; - - public static final Class[] EXCS_INTERFACE_METHOD_RESOLUTION_INVOKESTATIC = { - INCOMPATIBLE_CLASS_CHANGE_ERROR,UNSATISFIED_LINK_ERROR - }; - - - public static final Class[] EXCS_INTERFACE_METHOD_RESOLUTION = new Class[0]; // Chapter 5.3 (as below) - public static final Class[] EXCS_STRING_RESOLUTION = new Class[0]; - // Chapter 5.4 (no errors but the ones that _always_ could happen! How stupid.) - - public static final Class[] EXCS_ARRAY_EXCEPTION = { - NULL_POINTER_EXCEPTION, ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION - }; + /** + * The mother of all exceptions + */ + public static final Class THROWABLE = Throwable.class; + + /** + * Super class of any run-time exception + */ + public static final Class RUNTIME_EXCEPTION = RuntimeException.class; + + /** + * Super class of any linking exception (aka Linkage Error) + */ + public static final Class LINKING_EXCEPTION = LinkageError.class; + + /** + * Linking Exceptions + */ + public static final Class CLASS_CIRCULARITY_ERROR = ClassCircularityError.class; + public static final Class CLASS_FORMAT_ERROR = ClassFormatError.class; + public static final Class EXCEPTION_IN_INITIALIZER_ERROR = ExceptionInInitializerError.class; + public static final Class INCOMPATIBLE_CLASS_CHANGE_ERROR = IncompatibleClassChangeError.class; + public static final Class ABSTRACT_METHOD_ERROR = AbstractMethodError.class; + public static final Class ILLEGAL_ACCESS_ERROR = IllegalAccessError.class; + public static final Class INSTANTIATION_ERROR = InstantiationError.class; + public static final Class NO_SUCH_FIELD_ERROR = NoSuchFieldError.class; + public static final Class NO_SUCH_METHOD_ERROR = NoSuchMethodError.class; + public static final Class NO_CLASS_DEF_FOUND_ERROR = NoClassDefFoundError.class; + public static final Class UNSATISFIED_LINK_ERROR = UnsatisfiedLinkError.class; + public static final Class VERIFY_ERROR = VerifyError.class; + + /* UnsupportedClassVersionError is new in JDK 1.2 */ + // public static final Class UnsupportedClassVersionError = UnsupportedClassVersionError.class; + /** + * Run-Time Exceptions + */ + public static final Class NULL_POINTER_EXCEPTION = NullPointerException.class; + public static final Class ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION = ArrayIndexOutOfBoundsException.class; + public static final Class ARITHMETIC_EXCEPTION = ArithmeticException.class; + public static final Class NEGATIVE_ARRAY_SIZE_EXCEPTION = NegativeArraySizeException.class; + public static final Class CLASS_CAST_EXCEPTION = ClassCastException.class; + public static final Class ILLEGAL_MONITOR_STATE = IllegalMonitorStateException.class; + + /** + * Pre-defined exception arrays according to chapters 5.1-5.4 of the Java Virtual Machine Specification + */ + public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION = { NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, VERIFY_ERROR, + ABSTRACT_METHOD_ERROR, EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR }; // Chapter 5.1 + public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION_MULTIANEWARRAY = { NO_CLASS_DEF_FOUND_ERROR, + CLASS_FORMAT_ERROR, VERIFY_ERROR, ABSTRACT_METHOD_ERROR, EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR, + NEGATIVE_ARRAY_SIZE_EXCEPTION, ILLEGAL_ACCESS_ERROR }; + public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION_ANEWARRAY = { NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, + VERIFY_ERROR, ABSTRACT_METHOD_ERROR, EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR, + NEGATIVE_ARRAY_SIZE_EXCEPTION }; // Chapter 5.1 + public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION_CHECKCAST = { NO_CLASS_DEF_FOUND_ERROR, CLASS_FORMAT_ERROR, + VERIFY_ERROR, ABSTRACT_METHOD_ERROR, EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR, CLASS_CAST_EXCEPTION }; // Chapter + // 5.1 + public static final Class[] EXCS_CLASS_AND_INTERFACE_RESOLUTION_FOR_ALLOCATIONS = { NO_CLASS_DEF_FOUND_ERROR, + CLASS_FORMAT_ERROR, VERIFY_ERROR, ABSTRACT_METHOD_ERROR, EXCEPTION_IN_INITIALIZER_ERROR, ILLEGAL_ACCESS_ERROR, + INSTANTIATION_ERROR, ILLEGAL_ACCESS_ERROR }; + + public static final Class[] EXCS_FIELD_AND_METHOD_RESOLUTION = { NO_SUCH_FIELD_ERROR, ILLEGAL_ACCESS_ERROR, + NO_SUCH_METHOD_ERROR }; // Chapter 5.2 + + public static final Class[] EXCS_FIELD_AND_METHOD_RESOLUTION_GETFIELD_PUTFIELD = { NO_SUCH_FIELD_ERROR, ILLEGAL_ACCESS_ERROR, + NO_SUCH_METHOD_ERROR, INCOMPATIBLE_CLASS_CHANGE_ERROR, NULL_POINTER_EXCEPTION }; + + public static final Class[] EXCS_FIELD_AND_METHOD_RESOLUTION_GETSTATIC_PUTSTATIC = { NO_SUCH_FIELD_ERROR, ILLEGAL_ACCESS_ERROR, + NO_SUCH_METHOD_ERROR, INCOMPATIBLE_CLASS_CHANGE_ERROR }; + + public static final Class[] EXCS_INTERFACE_METHOD_RESOLUTION_INVOKEINTERFACE = { INCOMPATIBLE_CLASS_CHANGE_ERROR, + ILLEGAL_ACCESS_ERROR, ABSTRACT_METHOD_ERROR, UNSATISFIED_LINK_ERROR }; + public static final Class[] EXCS_INTERFACE_METHOD_RESOLUTION_INVOKESPECIAL_INVOKEVIRTUAL = { INCOMPATIBLE_CLASS_CHANGE_ERROR, + NULL_POINTER_EXCEPTION, ABSTRACT_METHOD_ERROR, UNSATISFIED_LINK_ERROR }; + + public static final Class[] EXCS_INTERFACE_METHOD_RESOLUTION_INVOKESTATIC = { INCOMPATIBLE_CLASS_CHANGE_ERROR, + UNSATISFIED_LINK_ERROR }; + + public static final Class[] EXCS_INTERFACE_METHOD_RESOLUTION = new Class[0]; // Chapter 5.3 (as below) + public static final Class[] EXCS_STRING_RESOLUTION = new Class[0]; + // Chapter 5.4 (no errors but the ones that _always_ could happen! How stupid.) + + public static final Class[] EXCS_ARRAY_EXCEPTION = { NULL_POINTER_EXCEPTION, ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION }; } diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantPool.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantPool.java index dece36ee4..6a68adc2f 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantPool.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/ConstantPool.java @@ -197,6 +197,10 @@ public class ConstantPool implements Node { return constantToString(c); } + public String constantToString(int index) { + return constantToString(getConstant(index)); + } + public void accept(ClassVisitor v) { v.visitConstantPool(this); } diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/JavaClass.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/JavaClass.java index 1a1ef3c00..f3f6b70b3 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/JavaClass.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/JavaClass.java @@ -80,7 +80,7 @@ import org.aspectj.apache.bcel.util.SyntheticRepository; * The intent of this class is to represent a parsed or otherwise existing class file. Those interested in programatically * generating classes should see the ClassGen class. * - * @version $Id: JavaClass.java,v 1.18 2009/09/10 03:59:33 aclement Exp $ + * @version $Id: JavaClass.java,v 1.19 2009/09/14 20:29:10 aclement Exp $ * @see org.aspectj.apache.bcel.generic.ClassGen * @author M. Dahm */ @@ -387,7 +387,7 @@ public class JavaClass extends Modifiers implements Cloneable, Node { return null; } - public Method getMethod(java.lang.reflect.Constructor c) { + public Method getMethod(java.lang.reflect.Constructor c) { for (int i = 0; i < methods.length; i++) { Method method = methods[i]; if (method.getName().equals("") && c.getModifiers() == method.getModifiers() diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Utility.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Utility.java index 66a0635f4..df6b7f376 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/Utility.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/Utility.java @@ -59,7 +59,6 @@ import java.io.DataOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; -import java.util.Iterator; import java.util.List; import org.aspectj.apache.bcel.Constants; @@ -76,7 +75,7 @@ import org.aspectj.apache.bcel.util.ByteSequence; /** * Utility functions that do not really belong to any class in particular. * - * @version $Id: Utility.java,v 1.10 2009/09/10 03:59:33 aclement Exp $ + * @version $Id: Utility.java,v 1.11 2009/09/14 20:29:10 aclement Exp $ * @author M. Dahm * * modified: Andy Clement 2-mar-05 Removed unnecessary static and optimized @@ -615,10 +614,7 @@ public abstract class Utility { * RuntimeInvisibleParameterAnnotations */ // OPTIMIZE looks heavyweight? - public static Attribute[] getParameterAnnotationAttributes(ConstantPool cp, List[] /* - * Array of lists, array size depends on - * #params - */vec) { + public static Attribute[] getParameterAnnotationAttributes(ConstantPool cp, List[] vec) { int visCount[] = new int[vec.length]; int totalVisCount = 0; @@ -627,10 +623,9 @@ public abstract class Utility { try { for (int i = 0; i < vec.length; i++) { - List l = vec[i]; + List l = vec[i]; if (l != null) { - for (Iterator iter = l.iterator(); iter.hasNext();) { - AnnotationGen element = (AnnotationGen) iter.next(); + for (AnnotationGen element : l) { if (element.isRuntimeVisible()) { visCount[i]++; totalVisCount++; @@ -650,9 +645,8 @@ public abstract class Utility { for (int i = 0; i < vec.length; i++) { rvaDos.writeShort(visCount[i]); if (visCount[i] > 0) { - List l = vec[i]; - for (Iterator iter = l.iterator(); iter.hasNext();) { - AnnotationGen element = (AnnotationGen) iter.next(); + List l = vec[i]; + for (AnnotationGen element : l) { if (element.isRuntimeVisible()) element.dump(rvaDos); } @@ -668,9 +662,8 @@ public abstract class Utility { for (int i = 0; i < vec.length; i++) { riaDos.writeShort(invisCount[i]); if (invisCount[i] > 0) { - List l = vec[i]; - for (Iterator iter = l.iterator(); iter.hasNext();) { - AnnotationGen element = (AnnotationGen) iter.next(); + List l = vec[i]; + for (AnnotationGen element : l) { if (!element.isRuntimeVisible()) element.dump(riaDos); } @@ -963,8 +956,7 @@ public abstract class Utility { buf.append("\t"); case Constants.INSTANCEOF: index = bytes.readUnsignedShort(); - buf.append("\t<" + constant_pool.constantToString(index, Constants.CONSTANT_Class) + ">" - + (verbose ? " (" + index + ")" : "")); + buf.append("\t<" + constant_pool.constantToString(index) + ">" + (verbose ? " (" + index + ")" : "")); break; // Operands are references to methods in constant pool @@ -972,15 +964,14 @@ public abstract class Utility { case Constants.INVOKESTATIC: case Constants.INVOKEVIRTUAL: index = bytes.readUnsignedShort(); - buf.append("\t" + constant_pool.constantToString(index, Constants.CONSTANT_Methodref) - + (verbose ? " (" + index + ")" : "")); + buf.append("\t" + constant_pool.constantToString(index) + (verbose ? " (" + index + ")" : "")); break; case Constants.INVOKEINTERFACE: index = bytes.readUnsignedShort(); int nargs = bytes.readUnsignedByte(); // historical, redundant - buf.append("\t" + constant_pool.constantToString(index, Constants.CONSTANT_InterfaceMethodref) - + (verbose ? " (" + index + ")\t" : "") + nargs + "\t" + bytes.readUnsignedByte()); // Last byte is a reserved + buf.append("\t" + constant_pool.constantToString(index) + (verbose ? " (" + index + ")\t" : "") + nargs + "\t" + + bytes.readUnsignedByte()); // Last byte is a reserved // space break; @@ -988,14 +979,12 @@ public abstract class Utility { case Constants.LDC_W: case Constants.LDC2_W: index = bytes.readUnsignedShort(); - buf.append("\t\t" + constant_pool.constantToString(index, constant_pool.getConstant(index).getTag()) - + (verbose ? " (" + index + ")" : "")); + buf.append("\t\t" + constant_pool.constantToString(index) + (verbose ? " (" + index + ")" : "")); break; case Constants.LDC: index = bytes.readUnsignedByte(); - buf.append("\t\t" + constant_pool.constantToString(index, constant_pool.getConstant(index).getTag()) - + (verbose ? " (" + index + ")" : "")); + buf.append("\t\t" + constant_pool.constantToString(index) + (verbose ? " (" + index + ")" : "")); break; // Array of references diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldGen.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldGen.java index 07f276b12..220844633 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldGen.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldGen.java @@ -72,7 +72,7 @@ import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnotations; * Template class for building up a field. The only extraordinary thing one can do is to add a constant value attribute to a field * (which must of course be compatible with the declared type). * - * @version $Id: FieldGen.java,v 1.7 2009/09/09 21:26:54 aclement Exp $ + * @version $Id: FieldGen.java,v 1.8 2009/09/14 20:29:10 aclement Exp $ * @author M. Dahm * @see Field */ @@ -148,8 +148,8 @@ public class FieldGen extends FieldGenOrMethodGen { */ public Field getField() { String signature = getSignature(); - int name_index = cp.addUtf8(name); - int signature_index = cp.addUtf8(signature); + int nameIndex = cp.addUtf8(name); + int signatureIndex = cp.addUtf8(signature); if (value != null) { checkType(type); @@ -159,7 +159,7 @@ public class FieldGen extends FieldGenOrMethodGen { addAnnotationsAsAttribute(cp); - return new Field(modifiers, name_index, signature_index, getAttributesImmutable(), cp); + return new Field(modifiers, nameIndex, signatureIndex, getAttributesImmutable(), cp); } private int addConstant() { @@ -194,44 +194,27 @@ public class FieldGen extends FieldGenOrMethodGen { } public String getInitialValue() { - if (value != null) { - return value.toString(); - } else - return null; + return (value == null ? null : value.toString()); } /** * Return string representation close to declaration format, `public static final short MAX = 100', e.g.. - * - * @return String representation of field */ @Override public final String toString() { - String name, signature, access; // Short cuts to constant pool - - access = Utility.accessToString(modifiers); + String access = Utility.accessToString(modifiers); access = access.equals("") ? "" : (access + " "); - signature = type.toString(); - name = getName(); + String signature = type.toString(); + String name = getName(); - StringBuffer buf = new StringBuffer(access + signature + " " + name); + StringBuffer buf = new StringBuffer(access).append(signature).append(" ").append(name); String value = getInitialValue(); - if (value != null) - buf.append(" = " + value); - + if (value != null) { + buf.append(" = ").append(value); + } // TODO: Add attributes and annotations to the string - return buf.toString(); } - /** - * @return deep copy of this field - */ - public FieldGen copy(ConstantPool cp) { - FieldGen fg = (FieldGen) clone(); - - fg.setConstantPool(cp); - return fg; - } } diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldGenOrMethodGen.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldGenOrMethodGen.java index 372c7b7b9..74ede06ec 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldGenOrMethodGen.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/FieldGenOrMethodGen.java @@ -68,16 +68,16 @@ import org.aspectj.apache.bcel.classfile.annotation.RuntimeAnnotations; /** * Super class for FieldGen and MethodGen objects, since they have some methods in common! * - * @version $Id: FieldGenOrMethodGen.java,v 1.6 2009/09/09 22:18:20 aclement Exp $ + * @version $Id: FieldGenOrMethodGen.java,v 1.7 2009/09/14 20:29:10 aclement Exp $ * @author M. Dahm */ -public abstract class FieldGenOrMethodGen extends Modifiers implements Cloneable { +public abstract class FieldGenOrMethodGen extends Modifiers { protected String name; protected Type type; protected ConstantPool cp; - private ArrayList/* */ attributeList = new ArrayList(); - private ArrayList annotationList = new ArrayList(); + private ArrayList attributeList = new ArrayList(); + protected ArrayList annotationList = new ArrayList(); protected FieldGenOrMethodGen() { } @@ -118,6 +118,10 @@ public abstract class FieldGenOrMethodGen extends Modifiers implements Cloneable attributeList.clear(); } + public List getAnnotations() { + return annotationList; + } + public void addAnnotation(AnnotationGen ag) { annotationList.add(ag); } @@ -130,7 +134,7 @@ public abstract class FieldGenOrMethodGen extends Modifiers implements Cloneable annotationList.clear(); } - public List/* */ getAttributes() { + public List getAttributes() { return attributeList; } @@ -149,22 +153,6 @@ public abstract class FieldGenOrMethodGen extends Modifiers implements Cloneable } } - public AnnotationGen[] getAnnotations() { - AnnotationGen[] annotations = new AnnotationGen[annotationList.size()]; - annotationList.toArray(annotations); - return annotations; - } - public abstract String getSignature(); - // OPTIMIZE clone any use??? - @Override - public Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException e) { - System.err.println(e); - return null; - } - } } diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/Instruction.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/Instruction.java index 3f7cadc9a..ae85e06a0 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/Instruction.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/Instruction.java @@ -67,15 +67,12 @@ import com.sun.org.apache.bcel.internal.generic.BranchInstruction; /** * Abstract super class for all Java byte codes. * - * @version $Id: Instruction.java,v 1.7 2008/08/28 00:06:23 aclement Exp $ + * @version $Id: Instruction.java,v 1.8 2009/09/14 20:29:10 aclement Exp $ * @author M. Dahm */ public class Instruction implements Cloneable, Serializable, Constants { public short opcode = -1; - private Instruction() { - } - public Instruction(short opcode) { this.opcode = opcode; } @@ -270,6 +267,7 @@ public class Instruction implements Cloneable, Serializable, Constants { void dispose() { } + @Override public boolean equals(Object that) { if (!(that instanceof Instruction)) { return false; @@ -291,6 +289,7 @@ public class Instruction implements Cloneable, Serializable, Constants { return false; } + @Override public int hashCode() { int result = 17 + opcode * 37; if (isConstantInstruction()) { @@ -362,19 +361,10 @@ public class Instruction implements Cloneable, Serializable, Constants { return false; } - public java.lang.Class[] getExceptions() { - // fixme - return Constants.instExcs[opcode]; - } - public boolean containsTarget(InstructionHandle ih) { throw new IllegalStateException("Dont ask!!"); } - public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) { - throw new IllegalStateException("Dont ask!!"); - } - public boolean isJsrInstruction() { return (Constants.instFlags[opcode] & JSR_INSTRUCTION) != 0; } @@ -389,12 +379,10 @@ public class Instruction implements Cloneable, Serializable, Constants { public boolean isStackProducer() { return Constants.stackEntriesProduced[opcode] != 0; - // return ((Constants.instFlags[opcode]&STACK_PRODUCER)!=0); } public boolean isStackConsumer() { return Constants.CONSUME_STACK[opcode] != 0; - // return ((Constants.instFlags[opcode]&STACK_CONSUMER)!=0); } public boolean isIndexedInstruction() { @@ -442,6 +430,7 @@ public class Instruction implements Cloneable, Serializable, Constants { } } + @Override public String toString() { return toString(true); } diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionCP.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionCP.java index d84f5246a..e2b4f9c68 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionCP.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionCP.java @@ -73,7 +73,7 @@ import com.sun.org.apache.bcel.internal.generic.LDC; * @see LDC * @see INVOKEVIRTUAL * - * @version $Id: InstructionCP.java,v 1.4 2009/09/10 15:35:06 aclement Exp $ + * @version $Id: InstructionCP.java,v 1.5 2009/09/14 20:29:10 aclement Exp $ * @author M. Dahm */ public class InstructionCP extends Instruction { @@ -212,8 +212,4 @@ public class InstructionCP extends Instruction { } } - @Override - public Class[] getExceptions() { - return org.aspectj.apache.bcel.ExceptionConstants.EXCS_STRING_RESOLUTION; - } } diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/MethodGen.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/MethodGen.java index 67dfb11a5..b85bf0165 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/MethodGen.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/MethodGen.java @@ -84,7 +84,7 @@ import org.aspectj.apache.bcel.classfile.annotation.RuntimeParameterAnnotations; * While generating code it may be necessary to insert NOP operations. You can use the `removeNOPs' method to get rid off them. The * resulting method object can be obtained via the `getMethod()' method. * - * @version $Id: MethodGen.java,v 1.13 2009/09/10 03:59:34 aclement Exp $ + * @version $Id: MethodGen.java,v 1.14 2009/09/14 20:29:10 aclement Exp $ * @author M. Dahm * @author Patrick C. Beard [setMaxStack()] * @see InstructionList @@ -106,9 +106,9 @@ public class MethodGen extends FieldGenOrMethodGen { private ArrayList localVariablesList = new ArrayList(); private ArrayList lineNumbersList = new ArrayList(); private ArrayList exceptionsList = new ArrayList(); - private ArrayList throws_vec = new ArrayList(); + private ArrayList exceptionsThrown = new ArrayList(); private ArrayList codeAttributesList = new ArrayList(); - private List[] param_annotations; // Array of lists containing AnnotationGen objects + private List[] param_annotations; // Array of lists containing AnnotationGen objects private boolean hasParameterAnnotations = false; private boolean haveUnpackedParameterAnnotations = false; @@ -216,25 +216,24 @@ public class MethodGen extends FieldGenOrMethodGen { Attribute a = attributes[i]; if (a instanceof Code) { - Code c = (Code) a; - setMaxStack(c.getMaxStack()); - setMaxLocals(c.getMaxLocals()); + Code code = (Code) a; + setMaxStack(code.getMaxStack()); + setMaxLocals(code.getMaxLocals()); - CodeException[] ces = c.getExceptionTable(); + CodeException[] ces = code.getExceptionTable(); InstructionHandle[] arrayOfInstructions = il.getInstructionsAsArray(); // process the exception table // - if (ces != null) { - for (int j = 0; j < ces.length; j++) { - CodeException ce = ces[j]; + for (CodeException ce : ces) { int type = ce.getCatchType(); - ObjectType c_type = null; + ObjectType catchType = null; if (type > 0) { String cen = m.getConstantPool().getConstantString_CONSTANTClass(type); - c_type = new ObjectType(cen); + catchType = new ObjectType(cen); } int end_pc = ce.getEndPC(); @@ -250,11 +249,11 @@ public class MethodGen extends FieldGenOrMethodGen { } addExceptionHandler(il.findHandle(ce.getStartPC(), arrayOfInstructions), end, il.findHandle(ce - .getHandlerPC(), arrayOfInstructions), c_type); + .getHandlerPC(), arrayOfInstructions), catchType); } } - Attribute[] codeAttrs = c.getAttributes(); + Attribute[] codeAttrs = code.getAttributes(); for (int j = 0; j < codeAttrs.length; j++) { a = codeAttrs[j]; @@ -333,45 +332,30 @@ public class MethodGen extends FieldGenOrMethodGen { } else if (a instanceof RuntimeAnnotations) { RuntimeAnnotations runtimeAnnotations = (RuntimeAnnotations) a; List l = runtimeAnnotations.getAnnotations(); - for (Iterator it = l.iterator(); it.hasNext();) { - AnnotationGen element = it.next(); - addAnnotation(new AnnotationGen(element, cp, false)); - } + annotationList.addAll(l); + // for (Iterator it = l.iterator(); it.hasNext();) { + // AnnotationGen element = it.next(); + // addAnnotation(new AnnotationGen(element, cp, false)); + // } } else { addAttribute(a); } } } - /** - * Adds a local variable to this method. - * - * @param name variable name - * @param type variable type - * @param slot the index of the local variable, if type is long or double, the next available index is slot+2 - * @param start from where the variable is valid - * @param end until where the variable is valid - * @return new local variable object - * @see LocalVariable - */ public LocalVariableGen addLocalVariable(String name, Type type, int slot, InstructionHandle start, InstructionHandle end) { - // byte t = type.getType(); - // if (t != Constants.T_ADDRESS) { int size = type.getSize(); - if (slot + size > maxLocals) + if (slot + size > maxLocals) { maxLocals = slot + size; + } LocalVariableGen l = new LocalVariableGen(slot, name, type, start, end); int i = localVariablesList.indexOf(l); - if (i >= 0) + if (i >= 0) { localVariablesList.set(i, l); // Overwrite if necessary - else + } else { localVariablesList.add(l); + } return l; - // } else { - // throw new IllegalArgumentException("Can not use " + type + - // " as type for local variable"); - // - // } } /** @@ -587,29 +571,29 @@ public class MethodGen extends FieldGenOrMethodGen { * @param class_name (fully qualified) name of exception */ public void addException(String class_name) { - throws_vec.add(class_name); + exceptionsThrown.add(class_name); } /** * Remove an exception. */ public void removeException(String c) { - throws_vec.remove(c); + exceptionsThrown.remove(c); } /** * Remove all exceptions. */ public void removeExceptions() { - throws_vec.clear(); + exceptionsThrown.clear(); } /* * @return array of thrown exceptions */ public String[] getExceptions() { - String[] e = new String[throws_vec.size()]; - throws_vec.toArray(e); + String[] e = new String[exceptionsThrown.size()]; + exceptionsThrown.toArray(e); return e; } @@ -617,12 +601,12 @@ public class MethodGen extends FieldGenOrMethodGen { * @return `Exceptions' attribute of all the exceptions thrown by this method. */ private ExceptionTable getExceptionTable(ConstantPool cp) { - int size = throws_vec.size(); + int size = exceptionsThrown.size(); int[] ex = new int[size]; try { for (int i = 0; i < size; i++) - ex[i] = cp.addClass(throws_vec.get(i)); + ex[i] = cp.addClass(exceptionsThrown.get(i)); } catch (ArrayIndexOutOfBoundsException e) { } @@ -742,7 +726,7 @@ public class MethodGen extends FieldGenOrMethodGen { ExceptionTable et = null; - if (throws_vec.size() > 0) + if (exceptionsThrown.size() > 0) addAttribute(et = getExceptionTable(cp)); // Add `Exceptions' if there are "throws" clauses Method m = new Method(modifiers, name_index, signature_index, getAttributesImmutable(), cp); @@ -824,7 +808,7 @@ public class MethodGen extends FieldGenOrMethodGen { public String[] getArgumentNames() { if (parameterNames != null) - return (String[]) parameterNames.clone(); + return parameterNames.clone(); else return new String[0]; } @@ -845,6 +829,7 @@ public class MethodGen extends FieldGenOrMethodGen { this.il = il; } + @Override public String getSignature() { return Utility.toMethodSignature(type, parameterTypes); } @@ -1014,6 +999,7 @@ public class MethodGen extends FieldGenOrMethodGen { * * @return String representation of the method. */ + @Override public final String toString() { String access = Utility.accessToString(modifiers); String signature = Utility.toMethodSignature(type, parameterTypes); @@ -1022,29 +1008,14 @@ public class MethodGen extends FieldGenOrMethodGen { StringBuffer buf = new StringBuffer(signature); - if (throws_vec.size() > 0) { - for (Iterator e = throws_vec.iterator(); e.hasNext();) + if (exceptionsThrown.size() > 0) { + for (Iterator e = exceptionsThrown.iterator(); e.hasNext();) buf.append("\n\t\tthrows " + e.next()); } return buf.toString(); } - /** - * @return deep copy of this method - */ - public MethodGen copy(String class_name, ConstantPool cp) { - Method m = ((MethodGen) clone()).getMethod(); - MethodGen mg = new MethodGen(m, class_name, this.cp); - - if (this.cp != cp) { - mg.setConstantPool(cp); - mg.getInstructionList().replaceConstantPool(this.cp, cp); - } - - return mg; - } - // J5TODO: Should param_annotations be an array of arrays? Rather than an array of lists, this // is more likely to suggest to the caller it is readonly (which a List does not). /** @@ -1064,22 +1035,22 @@ public class MethodGen extends FieldGenOrMethodGen { * object out of this MethodGen object). */ private void ensureExistingParameterAnnotationsUnpacked() { - if (haveUnpackedParameterAnnotations) + if (haveUnpackedParameterAnnotations) { return; + } // Find attributes that contain parameter annotation data List attrs = getAttributes(); RuntimeParameterAnnotations paramAnnVisAttr = null; RuntimeParameterAnnotations paramAnnInvisAttr = null; - List accumulatedAnnotations = new ArrayList(); - for (int i = 0; i < attrs.size(); i++) { - Attribute attribute = attrs.get(i); + + for (Attribute attribute : attrs) { if (attribute instanceof RuntimeParameterAnnotations) { - // Initialize param_annotations if (!hasParameterAnnotations) { param_annotations = new List[parameterTypes.length]; - for (int j = 0; j < parameterTypes.length; j++) - param_annotations[j] = new ArrayList(); + for (int j = 0; j < parameterTypes.length; j++) { + param_annotations[j] = new ArrayList(); + } } hasParameterAnnotations = true; @@ -1090,11 +1061,13 @@ public class MethodGen extends FieldGenOrMethodGen { paramAnnInvisAttr = rpa; for (int j = 0; j < parameterTypes.length; j++) { // This returns Annotation[] ... - AnnotationGen[] immutableArray = rpa.getAnnotationsOnParameter(j); + AnnotationGen[] annos = rpa.getAnnotationsOnParameter(j); // ... which needs transforming into an AnnotationGen[] ... - List mutable = makeMutableVersion(immutableArray); + // List mutable = makeMutableVersion(immutableArray); // ... then add these to any we already know about - param_annotations[j].addAll(mutable); + for (AnnotationGen anAnnotation : annos) { + param_annotations[j].add(anAnnotation); + } } } } @@ -1105,7 +1078,7 @@ public class MethodGen extends FieldGenOrMethodGen { haveUnpackedParameterAnnotations = true; } - private List /* AnnotationGen */makeMutableVersion(AnnotationGen[] mutableArray) { + private List /* AnnotationGen */ makeMutableVersion(AnnotationGen[] mutableArray) { List result = new ArrayList(); for (int i = 0; i < mutableArray.length; i++) { result.add(new AnnotationGen(mutableArray[i], getConstantPool(), false)); diff --git a/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util/BCELFactory.java b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util/BCELFactory.java index 5aa954588..e24a4a665 100644 --- a/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util/BCELFactory.java +++ b/bcel-builder/verifier-src/org/aspectj/apache/bcel/verifier/util/BCELFactory.java @@ -85,7 +85,7 @@ import org.aspectj.apache.bcel.verifier.InstructionWalker; * Factory creates il.append() statements, and sets instruction targets. A helper class for BCELifier. * * @see BCELifier - * @version $Id: BCELFactory.java,v 1.5 2009/09/09 19:56:20 aclement Exp $ + * @version $Id: BCELFactory.java,v 1.6 2009/09/14 20:29:10 aclement Exp $ * @author M. Dahm */ class BCELFactory extends org.aspectj.apache.bcel.verifier.EmptyInstVisitor { @@ -99,7 +99,8 @@ class BCELFactory extends org.aspectj.apache.bcel.verifier.EmptyInstVisitor { _out = out; } - private final HashMap branch_map = new HashMap(); // Map + private final HashMap branch_map = new HashMap(); // Map public void start() { if (!_mg.isAbstract() && !_mg.isNative()) { @@ -134,7 +135,7 @@ class BCELFactory extends org.aspectj.apache.bcel.verifier.EmptyInstVisitor { short opcode = i.getOpcode(); if (InstructionConstants.INSTRUCTIONS[opcode] != null && !i.isConstantInstruction() && !i.isReturnInstruction()) { // Handled - // below + // below _out.println("il.append(InstructionConstants." + i.getName().toUpperCase() + ");"); return true; } @@ -154,6 +155,7 @@ class BCELFactory extends org.aspectj.apache.bcel.verifier.EmptyInstVisitor { } } + @Override public void visitArrayInstruction(Instruction i) { short opcode = i.getOpcode(); Type type = i.getType(_cp); @@ -173,6 +175,7 @@ class BCELFactory extends org.aspectj.apache.bcel.verifier.EmptyInstVisitor { + BCELifier.printType(type) + ", " + "Constants." + Constants.OPCODE_NAMES[opcode].toUpperCase() + "));"); } + @Override public void visitInvokeInstruction(InvokeInstruction i) { short opcode = i.getOpcode(); String class_name = i.getClassName(_cp); @@ -185,6 +188,7 @@ class BCELFactory extends org.aspectj.apache.bcel.verifier.EmptyInstVisitor { + Constants.OPCODE_NAMES[opcode].toUpperCase() + "));"); } + @Override public void visitAllocationInstruction(Instruction i) { Type type; @@ -204,7 +208,6 @@ class BCELFactory extends org.aspectj.apache.bcel.verifier.EmptyInstVisitor { case Constants.MULTIANEWARRAY: dim = ((MULTIANEWARRAY) i).getDimensions(); - case Constants.ANEWARRAY: case Constants.NEWARRAY: _out.println("il.append(_factory.createNewArray(" + BCELifier.printType(type) + ", (short) " + dim + "));"); @@ -227,30 +230,36 @@ class BCELFactory extends org.aspectj.apache.bcel.verifier.EmptyInstVisitor { _out.println("il.append(new PUSH(_cp, " + embed + "));"); } + @Override public void visitLDC(Instruction i) { createConstant(i.getValue(_cp)); } + @Override public void visitLDC2_W(Instruction i) { createConstant(i.getValue(_cp)); } + @Override public void visitConstantPushInstruction(Instruction i) { createConstant(i.getValue()); } + @Override public void visitINSTANCEOF(Instruction i) { Type type = i.getType(_cp); _out.println("il.append(new INSTANCEOF(_cp.addClass(" + BCELifier.printType(type) + ")));"); } + @Override public void visitCHECKCAST(Instruction i) { Type type = i.getType(_cp); _out.println("il.append(_factory.createCheckCast(" + BCELifier.printType(type) + "));"); } + @Override public void visitReturnInstruction(Instruction i) { Type type = i.getType(_cp); @@ -260,6 +269,7 @@ class BCELFactory extends org.aspectj.apache.bcel.verifier.EmptyInstVisitor { // Memorize BranchInstructions that need an update private final ArrayList branches = new ArrayList(); + @Override public void visitBranchInstruction(InstructionBranch bi) { BranchHandle bh = (BranchHandle) branch_map.get(bi); int pos = bh.getPosition(); @@ -315,6 +325,7 @@ class BCELFactory extends org.aspectj.apache.bcel.verifier.EmptyInstVisitor { } } + @Override public void visitRET(RET i) { _out.println("il.append(new RET(" + i.getIndex() + ")));"); }