diff options
author | aclement <aclement> | 2004-11-19 16:52:30 +0000 |
---|---|---|
committer | aclement <aclement> | 2004-11-19 16:52:30 +0000 |
commit | 4345b4b36f5b29b0b6783cb1985a52157c1ce3f5 (patch) | |
tree | 93d002a93f076e26c85fcdd4bd623247a9d47087 /bcel-builder/src/org | |
parent | 1ad46c857bb676ff7237b9b6519b2db3563efb66 (diff) | |
download | aspectj-4345b4b36f5b29b0b6783cb1985a52157c1ce3f5.tar.gz aspectj-4345b4b36f5b29b0b6783cb1985a52157c1ce3f5.zip |
BCEL Java5 Support
Diffstat (limited to 'bcel-builder/src/org')
3 files changed, 277 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; } +} |