diff options
34 files changed, 493 insertions, 0 deletions
diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/AnnotationDefault.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/AnnotationDefault.java new file mode 100644 index 000000000..45ee9dfee --- /dev/null +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/AnnotationDefault.java @@ -0,0 +1,55 @@ +/* ******************************************************************* + * Copyright (c) 2004 IBM Corporation + * + * 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: + * Andy Clement initial implementation + * ******************************************************************/ +package org.aspectj.apache.bcel.classfile; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +import org.aspectj.apache.bcel.Constants; +import org.aspectj.apache.bcel.classfile.annotation.ElementValue; + +/** + * This attribute is attached to a method and indicates the default + * value for an annotation element. + */ +public class AnnotationDefault extends Attribute { + + private ElementValue value; + + public AnnotationDefault(int nameIndex, int len, DataInputStream dis, ConstantPool cpool) throws IOException { + this(nameIndex, len, ElementValue.readElementValue(dis,cpool), cpool); + } + + private AnnotationDefault(int nameIndex, int len, ElementValue value, ConstantPool cpool) { + super(Constants.ATTR_ANNOTATION_DEFAULT, nameIndex, len, cpool); + this.value = value; + } + + public void accept(Visitor v) { + v.visitAnnotationDefault(this); + } + + public Attribute copy(ConstantPool constant_pool) { + throw new RuntimeException("Not implemented yet!"); + // is this next line sufficient? + // return (EnclosingMethod)clone(); + } + + public final ElementValue getElementValue() { return value; } + + public final void dump(DataOutputStream dos) throws IOException { + super.dump(dos); + value.dump(dos); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/EnclosingMethod.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/EnclosingMethod.java new file mode 100644 index 000000000..a75a89eeb --- /dev/null +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/EnclosingMethod.java @@ -0,0 +1,87 @@ +/* ******************************************************************* + * Copyright (c) 2004 IBM Corporation + * + * 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: + * Andy Clement initial implementation + * ******************************************************************/ +package org.aspectj.apache.bcel.classfile; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +import org.aspectj.apache.bcel.Constants; + +/** + * This attribute exists for local or + * anonymous classes and ... there can be only one. + */ +public class EnclosingMethod extends Attribute { + + // Pointer to the CONSTANT_Class_info structure representing the + // innermost class that encloses the declaration of the current class. + private int classIndex; + + // If the current class is not immediately enclosed by a method or + // constructor, then the value of the method_index item must be zero. + // Otherwise, the value of the method_index item must point to a + // CONSTANT_NameAndType_info structure representing the name and the + // type of a method in the class referenced by the class we point + // to in the class_index. *It is the compiler responsibility* to + // ensure that the method identified by this index is the closest + // lexically enclosing method that includes the local/anonymous class. + private int methodIndex; + + // Ctors - and code to read an attribute in. + public EnclosingMethod(int nameIndex, int len, DataInputStream dis, ConstantPool cpool) throws IOException { + this(nameIndex, len, dis.readUnsignedShort(), dis.readUnsignedShort(), cpool); + } + + private EnclosingMethod(int nameIndex, int len, int classIdx,int methodIdx, ConstantPool cpool) { + super(Constants.ATTR_ENCLOSING_METHOD, nameIndex, len, cpool); + classIndex = classIdx; + methodIndex = methodIdx; + } + + public void accept(Visitor v) { + v.visitEnclosingMethod(this); + } + + public Attribute copy(ConstantPool constant_pool) { + throw new RuntimeException("Not implemented yet!"); + // is this next line sufficient? + // return (EnclosingMethod)clone(); + } + + // Accessors + public final int getEnclosingClassIndex() { return classIndex; } + public final int getEnclosingMethodIndex(){ return methodIndex;} + + public final void setEnclosingClassIndex(int idx) {classIndex = idx;} + public final void setEnclosingMethodIndex(int idx){methodIndex= idx;} + + public final ConstantClass getEnclosingClass() { + ConstantClass c = + (ConstantClass)constant_pool.getConstant(classIndex,Constants.CONSTANT_Class); + return c; + } + + public final ConstantNameAndType getEnclosingMethod() { + if (methodIndex == 0) return null; + ConstantNameAndType nat = + (ConstantNameAndType)constant_pool.getConstant(methodIndex,Constants.CONSTANT_NameAndType); + return nat; + } + + public final void dump(DataOutputStream file) throws IOException { + super.dump(file); + file.writeShort(classIndex); + file.writeShort(methodIndex); + } +} diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/LocalVariableTypeTable.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/LocalVariableTypeTable.java new file mode 100644 index 000000000..0e292b614 --- /dev/null +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/LocalVariableTypeTable.java @@ -0,0 +1,135 @@ +/* ******************************************************************* + * Copyright (c) 2004 IBM Corporation + * + * 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: + * Andy Clement initial implementation + * Heavily based on LocalVariableTable + * ******************************************************************/ +package org.aspectj.apache.bcel.classfile; + + +import org.aspectj.apache.bcel.Constants; +import java.io.*; + +// The new table is used when generic types are about... + +//LocalVariableTable_attribute { +// u2 attribute_name_index; +// u4 attribute_length; +// u2 local_variable_table_length; +// { u2 start_pc; +// u2 length; +// u2 name_index; +// u2 descriptor_index; +// u2 index; +// } local_variable_table[local_variable_table_length]; +// } + +//LocalVariableTypeTable_attribute { +// u2 attribute_name_index; +// u4 attribute_length; +// u2 local_variable_type_table_length; +// { +// u2 start_pc; +// u2 length; +// u2 name_index; +// u2 signature_index; +// u2 index; +// } local_variable_type_table[local_variable_type_table_length]; +// } +// J5TODO: Needs some testing ! +public class LocalVariableTypeTable extends Attribute { + private int local_variable_type_table_length; // Table of local + private LocalVariable[] local_variable_type_table; // variables + + public LocalVariableTypeTable(LocalVariableTypeTable c) { + this(c.getNameIndex(), c.getLength(), c.getLocalVariableTypeTable(), + c.getConstantPool()); + } + + public LocalVariableTypeTable(int name_index, int length, + LocalVariable[] local_variable_table, + ConstantPool constant_pool) + { + super(Constants.ATTR_LOCAL_VARIABLE_TYPE_TABLE, name_index, length, constant_pool); + setLocalVariableTable(local_variable_table); + } + + LocalVariableTypeTable(int nameIdx, int len, DataInputStream dis,ConstantPool cpool) throws IOException { + this(nameIdx, len, (LocalVariable[])null, cpool); + + local_variable_type_table_length = (dis.readUnsignedShort()); + local_variable_type_table = new LocalVariable[local_variable_type_table_length]; + + for(int i=0; i < local_variable_type_table_length; i++) + local_variable_type_table[i] = new LocalVariable(dis, cpool); + } + + public void accept(Visitor v) { + v.visitLocalVariableTypeTable(this); + } + + public final void dump(DataOutputStream file) throws IOException + { + super.dump(file); + file.writeShort(local_variable_type_table_length); + for(int i=0; i < local_variable_type_table_length; i++) + local_variable_type_table[i].dump(file); + } + + public final LocalVariable[] getLocalVariableTypeTable() { + return local_variable_type_table; + } + + public final LocalVariable getLocalVariable(int index) { + for(int i=0; i < local_variable_type_table_length; i++) + if(local_variable_type_table[i].getIndex() == index) + return local_variable_type_table[i]; + + return null; + } + + public final void setLocalVariableTable(LocalVariable[] local_variable_table) + { + this.local_variable_type_table = local_variable_table; + local_variable_type_table_length = (local_variable_table == null)? 0 : + local_variable_table.length; + } + + /** + * @return String representation. + */ + public final String toString() { + StringBuffer buf = new StringBuffer(""); + + for(int i=0; i < local_variable_type_table_length; i++) { + buf.append(local_variable_type_table[i].toString()); + + if(i < local_variable_type_table_length - 1) buf.append('\n'); + } + + return buf.toString(); + } + + /** + * @return deep copy of this attribute + */ + public Attribute copy(ConstantPool constant_pool) { + LocalVariableTypeTable c = (LocalVariableTypeTable)clone(); + + c.local_variable_type_table = new LocalVariable[local_variable_type_table_length]; + for(int i=0; i < local_variable_type_table_length; i++) + c.local_variable_type_table[i] = local_variable_type_table[i].copy(); + + c.constant_pool = constant_pool; + return c; + } + + public final int getTableLength() { return local_variable_type_table_length; } +} diff --git a/bcel-builder/testdata/AnnotatedClass.java b/bcel-builder/testdata/AnnotatedClass.java new file mode 100644 index 000000000..033d2e8e5 --- /dev/null +++ b/bcel-builder/testdata/AnnotatedClass.java @@ -0,0 +1,3 @@ +@AnnotationStringElement(stringval="hello") +public class AnnotatedClass { +} diff --git a/bcel-builder/testdata/AnnotatedFields.java b/bcel-builder/testdata/AnnotatedFields.java new file mode 100644 index 000000000..97fba870a --- /dev/null +++ b/bcel-builder/testdata/AnnotatedFields.java @@ -0,0 +1,5 @@ +public class AnnotatedFields { + @SimpleAnnotation(id=1) int i; + + @SimpleAnnotation(id=2) String s; +} diff --git a/bcel-builder/testdata/AnnotatedMethods.java b/bcel-builder/testdata/AnnotatedMethods.java new file mode 100644 index 000000000..ed1ff3c63 --- /dev/null +++ b/bcel-builder/testdata/AnnotatedMethods.java @@ -0,0 +1,10 @@ +public class AnnotatedMethods { + + @SimpleAnnotation(id=1) + public void method1() { + } + + @SimpleAnnotation(id=2) + public void method2() { + } +} diff --git a/bcel-builder/testdata/AnnotatedParameters.java b/bcel-builder/testdata/AnnotatedParameters.java new file mode 100644 index 000000000..9cfb2b80b --- /dev/null +++ b/bcel-builder/testdata/AnnotatedParameters.java @@ -0,0 +1,15 @@ +public class AnnotatedParameters { + + + public static void main(@SimpleAnnotation(id=1) String args[]) { + } + + public void foo(@SimpleAnnotation(id=2) int arg1, + @SimpleAnnotation(id=3) @AnnotationEnumElement(enumval=SimpleEnum.Red) String arg2) { + try { + throw new RuntimeException("eee"); + } catch (@SimpleAnnotation(id=5) Exception ex) { + } + } + +} diff --git a/bcel-builder/testdata/AnnotatedWithClassClass.java b/bcel-builder/testdata/AnnotatedWithClassClass.java new file mode 100644 index 000000000..a9dc32138 --- /dev/null +++ b/bcel-builder/testdata/AnnotatedWithClassClass.java @@ -0,0 +1,3 @@ +@AnnotationClassElement(clz=Integer.class) +public class AnnotatedWithClassClass { +} diff --git a/bcel-builder/testdata/AnnotatedWithCombinedAnnotation.java b/bcel-builder/testdata/AnnotatedWithCombinedAnnotation.java new file mode 100644 index 000000000..c63e6bcaf --- /dev/null +++ b/bcel-builder/testdata/AnnotatedWithCombinedAnnotation.java @@ -0,0 +1,3 @@ +@CombinedAnnotation({@SimpleAnnotation(id=4)}) +public class AnnotatedWithCombinedAnnotation { +} diff --git a/bcel-builder/testdata/AnnotatedWithEnumClass.java b/bcel-builder/testdata/AnnotatedWithEnumClass.java new file mode 100644 index 000000000..5f532ff6b --- /dev/null +++ b/bcel-builder/testdata/AnnotatedWithEnumClass.java @@ -0,0 +1,3 @@ +@AnnotationEnumElement(enumval=SimpleEnum.Red) +public class AnnotatedWithEnumClass { +} diff --git a/bcel-builder/testdata/AnnotationClassElement.java b/bcel-builder/testdata/AnnotationClassElement.java new file mode 100644 index 000000000..629bd2155 --- /dev/null +++ b/bcel-builder/testdata/AnnotationClassElement.java @@ -0,0 +1,6 @@ +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +public @interface AnnotationClassElement { + Class clz(); +} diff --git a/bcel-builder/testdata/AnnotationEnumElement.java b/bcel-builder/testdata/AnnotationEnumElement.java new file mode 100644 index 000000000..201b34ad2 --- /dev/null +++ b/bcel-builder/testdata/AnnotationEnumElement.java @@ -0,0 +1,6 @@ +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +public @interface AnnotationEnumElement { + SimpleEnum enumval(); +} diff --git a/bcel-builder/testdata/AnnotationStringElement.java b/bcel-builder/testdata/AnnotationStringElement.java new file mode 100644 index 000000000..dc68cf2e9 --- /dev/null +++ b/bcel-builder/testdata/AnnotationStringElement.java @@ -0,0 +1,6 @@ +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +public @interface AnnotationStringElement { + String stringval(); +} diff --git a/bcel-builder/testdata/AttributeTestClassEM01.java b/bcel-builder/testdata/AttributeTestClassEM01.java new file mode 100644 index 000000000..e8bb5c7f5 --- /dev/null +++ b/bcel-builder/testdata/AttributeTestClassEM01.java @@ -0,0 +1,8 @@ +public class AttributeTestClassEM01 { + + public static void main(String[]argv) { + class S { + public void sayhello() { System.err.println("hello");} + } + } +} diff --git a/bcel-builder/testdata/AttributeTestClassEM02.java b/bcel-builder/testdata/AttributeTestClassEM02.java new file mode 100644 index 000000000..b152854a6 --- /dev/null +++ b/bcel-builder/testdata/AttributeTestClassEM02.java @@ -0,0 +1,8 @@ +public class AttributeTestClassEM02 { + + Runnable r = new Runnable() { + public void run() { System.err.println("hello");} + }; + public static void main(String[]argv) { + } +} diff --git a/bcel-builder/testdata/CombinedAnnotation.java b/bcel-builder/testdata/CombinedAnnotation.java new file mode 100644 index 000000000..a262c868f --- /dev/null +++ b/bcel-builder/testdata/CombinedAnnotation.java @@ -0,0 +1,6 @@ +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +public @interface CombinedAnnotation { + public SimpleAnnotation[] value(); +} diff --git a/bcel-builder/testdata/ComplexAnnotatedClass.java b/bcel-builder/testdata/ComplexAnnotatedClass.java new file mode 100644 index 000000000..155e531d0 --- /dev/null +++ b/bcel-builder/testdata/ComplexAnnotatedClass.java @@ -0,0 +1,3 @@ +@ComplexAnnotation(ival=4,bval=2,cval=5,fval=3.0f,dval=33.4,zval=false,jval=56,sval=99) +public class ComplexAnnotatedClass { +} diff --git a/bcel-builder/testdata/ComplexAnnotation.java b/bcel-builder/testdata/ComplexAnnotation.java new file mode 100644 index 000000000..c5a76c71e --- /dev/null +++ b/bcel-builder/testdata/ComplexAnnotation.java @@ -0,0 +1,13 @@ +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +public @interface ComplexAnnotation { + int ival(); + byte bval(); + char cval(); + long jval(); + double dval(); + boolean zval(); + short sval(); + float fval(); +} diff --git a/bcel-builder/testdata/HelloWorld.java b/bcel-builder/testdata/HelloWorld.java new file mode 100644 index 000000000..9146fed8c --- /dev/null +++ b/bcel-builder/testdata/HelloWorld.java @@ -0,0 +1,14 @@ +import java.io.*; + +public class HelloWorld { + public static void main(String[] argv) { + BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + String name = null; + + try { + System.out.print("Please enter your name> "); + name = in.readLine(); + } catch(IOException e) { return; } + System.out.println("Hello, " + name); + } + } diff --git a/bcel-builder/testdata/SimpleAnnotatedClass.java b/bcel-builder/testdata/SimpleAnnotatedClass.java new file mode 100644 index 000000000..8d4e4ac95 --- /dev/null +++ b/bcel-builder/testdata/SimpleAnnotatedClass.java @@ -0,0 +1,3 @@ +@SimpleAnnotation(id=4) +public class SimpleAnnotatedClass { +} diff --git a/bcel-builder/testdata/SimpleAnnotation.java b/bcel-builder/testdata/SimpleAnnotation.java new file mode 100644 index 000000000..5b4303755 --- /dev/null +++ b/bcel-builder/testdata/SimpleAnnotation.java @@ -0,0 +1,7 @@ +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +public @interface SimpleAnnotation { + int id(); + String fruit() default "bananas"; +} diff --git a/bcel-builder/testdata/SimpleClass.java b/bcel-builder/testdata/SimpleClass.java new file mode 100644 index 000000000..9920c4912 --- /dev/null +++ b/bcel-builder/testdata/SimpleClass.java @@ -0,0 +1,5 @@ +public class SimpleClass { + public static void main(String[] argv) { + // Nothing unusual in this class + } +} diff --git a/bcel-builder/testdata/SimpleEnum.java b/bcel-builder/testdata/SimpleEnum.java new file mode 100644 index 000000000..2df536880 --- /dev/null +++ b/bcel-builder/testdata/SimpleEnum.java @@ -0,0 +1 @@ +public enum SimpleEnum { Red,Orange,Yellow,Green,Blue,Indigo,Violet }; diff --git a/bcel-builder/testdata/SimpleGenericsProgram.java b/bcel-builder/testdata/SimpleGenericsProgram.java new file mode 100644 index 000000000..2457a9155 --- /dev/null +++ b/bcel-builder/testdata/SimpleGenericsProgram.java @@ -0,0 +1,26 @@ +import java.util.*; + +class TreasureChest<T> { + + protected Set<T> contents; + + public TreasureChest() { + contents = new HashSet<T>(); + } + + public void add(T o) { + contents.add(o); + } +} + +public class SimpleGenericsProgram { + + public static void main(String []argv) { + TreasureChest<String> tc1 = new TreasureChest<String>(); + TreasureChest<Integer> tc2 = new TreasureChest<Integer>(); + + tc1.add("dubloon"); + tc2.add(new Integer("777")); + + } +} diff --git a/bcel-builder/testdata/SimpleGenericsUsage.java b/bcel-builder/testdata/SimpleGenericsUsage.java new file mode 100644 index 000000000..74a8df574 --- /dev/null +++ b/bcel-builder/testdata/SimpleGenericsUsage.java @@ -0,0 +1,12 @@ +import java.util.*; + +public class SimpleGenericsUsage { + + public static void main(String[]argv) { + ArrayList<String> fruits = new ArrayList<String>(); + fruits.add("Oranges"); + fruits.add("Apples"); + fruits.add("Pears"); + System.err.println(fruits.size()+" fruits defined"); + } +} diff --git a/bcel-builder/testdata/SimpleStringAnnotation.java b/bcel-builder/testdata/SimpleStringAnnotation.java new file mode 100644 index 000000000..af3b5ce36 --- /dev/null +++ b/bcel-builder/testdata/SimpleStringAnnotation.java @@ -0,0 +1,6 @@ +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +public @interface SimpleStringAnnotation { + String fruit(); +} diff --git a/bcel-builder/testdata/SimpleType.java b/bcel-builder/testdata/SimpleType.java new file mode 100644 index 000000000..2b0563bba --- /dev/null +++ b/bcel-builder/testdata/SimpleType.java @@ -0,0 +1,6 @@ +class SimpleType { + public Integer i; + + public void setI(Integer i) { this.i=i;} + public Integer getI() { return i;} +} diff --git a/bcel-builder/testdata/SimpleVarargs.java b/bcel-builder/testdata/SimpleVarargs.java new file mode 100644 index 000000000..3994d2cfb --- /dev/null +++ b/bcel-builder/testdata/SimpleVarargs.java @@ -0,0 +1,12 @@ + +public class SimpleVarargs { + public static void main(String[] argv) { + callfoo("a","b","c","d","e"); + } + + public static void callfoo(Object... args) { + for (int i = 0 ; i<args.length;i++) { + System.err.println(args[i]); + } + } +} diff --git a/bcel-builder/testdata/VarargsClass.java b/bcel-builder/testdata/VarargsClass.java new file mode 100644 index 000000000..c50e45e92 --- /dev/null +++ b/bcel-builder/testdata/VarargsClass.java @@ -0,0 +1,9 @@ +public class VarargsClass { + + public void foo(String abc,String... args) { } + + public void goo(String... args) { } + + public void hoo() {} + +} diff --git a/bcel-builder/testdata/VerySimpleAnnotation.java b/bcel-builder/testdata/VerySimpleAnnotation.java new file mode 100644 index 000000000..375ab3cbf --- /dev/null +++ b/bcel-builder/testdata/VerySimpleAnnotation.java @@ -0,0 +1,6 @@ +import java.lang.annotation.*; + +@Retention(RetentionPolicy.RUNTIME) +public @interface VerySimpleAnnotation { + int id(); +} diff --git a/bcel-builder/testdata/build.xml b/bcel-builder/testdata/build.xml new file mode 100644 index 000000000..6c3543eda --- /dev/null +++ b/bcel-builder/testdata/build.xml @@ -0,0 +1,11 @@ +<project name="Java 5 compilation of covariance test source" default="default" basedir="."> + + <target name="default"> + <delete dir="output" failonerror="false"/> + <mkdir dir="output"/> + <javac destdir="output" debug="on" srcdir="." includes="*.java"/> + <zip file="testcode.jar" basedir="output" includes="*"/> + <delete dir="output"/> + </target> + +</project> diff --git a/bcel-builder/testdata/testcode.jar b/bcel-builder/testdata/testcode.jar Binary files differnew file mode 100644 index 000000000..cbfaa1a2d --- /dev/null +++ b/bcel-builder/testdata/testcode.jar diff --git a/lib/bcel/bcel-src.zip b/lib/bcel/bcel-src.zip Binary files differindex 930222719..f6d173213 100644 --- a/lib/bcel/bcel-src.zip +++ b/lib/bcel/bcel-src.zip diff --git a/lib/bcel/bcel.jar b/lib/bcel/bcel.jar Binary files differindex 037bdbf8a..f6eb80341 100644 --- a/lib/bcel/bcel.jar +++ b/lib/bcel/bcel.jar |