Modified: jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/Method.java
URL: http://svn.apache.org/viewcvs/jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/Method.java?rev=386056&r1=386055&r2=386056&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/Method.java (original)
+++ jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/Method.java Wed Mar 15 03:31:56 2006
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- */
+ */
package org.apache.bcel.classfile;
import java.io.DataInputStream;
@@ -31,226 +31,224 @@
* @author <A HREF="mailto:[email protected]">M. Dahm</A>
*/
public final class Method extends FieldOrMethod {
- private static BCELComparator _cmp = new BCELComparator() {
- public boolean equals(Object o1, Object o2) {
- Method THIS = (Method)o1;
- Method THAT = (Method)o2;
-
- return THIS.getName().equals(THAT.getName())
- && THIS.getSignature().equals(THAT.getSignature());
- }
-
- public int hashCode(Object o) {
- Method THIS = (Method)o;
- return THIS.getSignature().hashCode() ^ THIS.getName().hashCode();
- }
- };
-
- /**
- * Empty constructor, all attributes have to be defined via `setXXX'
- * methods. Use at your own risk.
- */
- public Method() {
- }
-
- /**
- * Initialize from another object. Note that both objects use the same
- * references (shallow copy). Use clone() for a physical copy.
- */
- public Method(Method c) {
- super(c);
- }
-
- /**
- * Construct object from file stream.
- * @param file Input stream
- * @throws IOException
- * @throws ClassFormatException
- */
- Method(DataInputStream file, ConstantPool constant_pool)
- throws IOException, ClassFormatException {
- super(file, constant_pool);
- }
-
- /**
- * @param access_flags Access rights of method
- * @param name_index Points to field name in constant pool
- * @param signature_index Points to encoded signature
- * @param attributes Collection of attributes
- * @param constant_pool Array of constants
- */
- public Method(
- int access_flags,
- int name_index,
- int signature_index,
- Attribute[] attributes,
- ConstantPool constant_pool) {
- super(access_flags, name_index, signature_index, attributes, constant_pool);
- }
-
- /**
- * Called by objects that are traversing the nodes of the tree implicitely
- * defined by the contents of a Java class. I.e., the hierarchy of methods,
- * fields, attributes, etc. spawns a tree of objects.
- *
- * @param v Visitor object
- */
- public void accept(Visitor v) {
- v.visitMethod(this);
- }
-
- /**
- * @return Code attribute of method, if any
- */
- public final Code getCode() {
- for (int i = 0; i < attributes_count; i++)
- if (attributes[i] instanceof Code)
- return (Code)attributes[i];
-
- return null;
- }
-
- /**
- * @return ExceptionTable attribute of method, if any, i.e., list all
- * exceptions the method may throw not exception handlers!
- */
- public final ExceptionTable getExceptionTable() {
- for (int i = 0; i < attributes_count; i++)
- if (attributes[i] instanceof ExceptionTable)
- return (ExceptionTable)attributes[i];
-
- return null;
- }
-
- /** @return LocalVariableTable of code attribute if any, i.e. the call is forwarded
- * to the Code atribute.
- */
- public final LocalVariableTable getLocalVariableTable() {
- Code code = getCode();
-
- if (code == null)
- return null;
-
- return code.getLocalVariableTable();
- }
-
- /** @return LineNumberTable of code attribute if any, i.e. the call is forwarded
- * to the Code atribute.
- */
- public final LineNumberTable getLineNumberTable() {
- Code code = getCode();
-
- if (code == null)
- return null;
-
- return code.getLineNumberTable();
- }
-
- /**
- * Return string representation close to declaration format,
- * `public static void main(String[] args) throws IOException', e.g.
- *
- * @return String representation of the method.
- */
- public final String toString() {
- ConstantUtf8 c;
- String name, signature, access; // Short cuts to constant pool
- StringBuffer buf;
-
- access = Utility.accessToString(access_flags);
-
- // Get name and signature from constant pool
- c =
- (ConstantUtf8)constant_pool.getConstant(
- signature_index,
- Constants.CONSTANT_Utf8);
- signature = c.getBytes();
-
- c =
- (ConstantUtf8)constant_pool.getConstant(
- name_index,
- Constants.CONSTANT_Utf8);
- name = c.getBytes();
-
- signature =
- Utility.methodSignatureToString(
- signature,
- name,
- access,
- true,
- getLocalVariableTable());
- buf = new StringBuffer(signature);
-
- for (int i = 0; i < attributes_count; i++) {
- Attribute a = attributes[i];
-
- if (!((a instanceof Code) || (a instanceof ExceptionTable)))
- buf.append(" [").append(a.toString()).append("]");
- }
-
- ExceptionTable e = getExceptionTable();
- if (e != null) {
- String str = e.toString();
- if (!str.equals(""))
- buf.append("\n\t\tthrows ").append(str);
- }
-
- return buf.toString();
- }
-
- /**
- * @return deep copy of this method
- */
- public final Method copy(ConstantPool _constant_pool) {
- return (Method)copy_(_constant_pool);
- }
-
- /**
- * @return return type of method
- */
- public Type getReturnType() {
- return Type.getReturnType(getSignature());
- }
-
- /**
- * @return array of method argument types
- */
- public Type[] getArgumentTypes() {
- return Type.getArgumentTypes(getSignature());
- }
-
- /**
- * @return Comparison strategy object
- */
- public static BCELComparator getComparator() {
- return _cmp;
- }
-
- /**
- * @param comparator Comparison strategy object
- */
- public static void setComparator(BCELComparator comparator) {
- _cmp = comparator;
- }
-
- /**
- * Return value as defined by given BCELComparator strategy.
- * By default two method objects are said to be equal when
- * their names and signatures are equal.
- *
- * @see java.lang.Object#equals(java.lang.Object)
- */
- public boolean equals(Object obj) {
- return _cmp.equals(this, obj);
- }
-
- /**
- * Return value as defined by given BCELComparator strategy.
- * By default return the hashcode of the method's name XOR signature.
- *
- * @see java.lang.Object#hashCode()
- */
- public int hashCode() {
- return _cmp.hashCode(this);
- }
+
+ private static BCELComparator _cmp = new BCELComparator() {
+
+ public boolean equals( Object o1, Object o2 ) {
+ Method THIS = (Method) o1;
+ Method THAT = (Method) o2;
+ return THIS.getName().equals(THAT.getName())
+ && THIS.getSignature().equals(THAT.getSignature());
+ }
+
+
+ public int hashCode( Object o ) {
+ Method THIS = (Method) o;
+ return THIS.getSignature().hashCode() ^ THIS.getName().hashCode();
+ }
+ };
+
+
+ /**
+ * Empty constructor, all attributes have to be defined via `setXXX'
+ * methods. Use at your own risk.
+ */
+ public Method() {
+ }
+
+
+ /**
+ * Initialize from another object. Note that both objects use the same
+ * references (shallow copy). Use clone() for a physical copy.
+ */
+ public Method(Method c) {
+ super(c);
+ }
+
+
+ /**
+ * Construct object from file stream.
+ * @param file Input stream
+ * @throws IOException
+ * @throws ClassFormatException
+ */
+ Method(DataInputStream file, ConstantPool constant_pool) throws IOException,
+ ClassFormatException {
+ super(file, constant_pool);
+ }
+
+
+ /**
+ * @param access_flags Access rights of method
+ * @param name_index Points to field name in constant pool
+ * @param signature_index Points to encoded signature
+ * @param attributes Collection of attributes
+ * @param constant_pool Array of constants
+ */
+ public Method(int access_flags, int name_index, int signature_index, Attribute[] attributes,
+ ConstantPool constant_pool) {
+ super(access_flags, name_index, signature_index, attributes, constant_pool);
+ }
+
+
+ /**
+ * Called by objects that are traversing the nodes of the tree implicitely
+ * defined by the contents of a Java class. I.e., the hierarchy of methods,
+ * fields, attributes, etc. spawns a tree of objects.
+ *
+ * @param v Visitor object
+ */
+ public void accept( Visitor v ) {
+ v.visitMethod(this);
+ }
+
+
+ /**
+ * @return Code attribute of method, if any
+ */
+ public final Code getCode() {
+ for (int i = 0; i < attributes_count; i++) {
+ if (attributes[i] instanceof Code) {
+ return (Code) attributes[i];
+ }
+ }
+ return null;
+ }
+
+
+ /**
+ * @return ExceptionTable attribute of method, if any, i.e., list all
+ * exceptions the method may throw not exception handlers!
+ */
+ public final ExceptionTable getExceptionTable() {
+ for (int i = 0; i < attributes_count; i++) {
+ if (attributes[i] instanceof ExceptionTable) {
+ return (ExceptionTable) attributes[i];
+ }
+ }
+ return null;
+ }
+
+
+ /** @return LocalVariableTable of code attribute if any, i.e. the call is forwarded
+ * to the Code atribute.
+ */
+ public final LocalVariableTable getLocalVariableTable() {
+ Code code = getCode();
+ if (code == null) {
+ return null;
+ }
+ return code.getLocalVariableTable();
+ }
+
+
+ /** @return LineNumberTable of code attribute if any, i.e. the call is forwarded
+ * to the Code atribute.
+ */
+ public final LineNumberTable getLineNumberTable() {
+ Code code = getCode();
+ if (code == null) {
+ return null;
+ }
+ return code.getLineNumberTable();
+ }
+
+
+ /**
+ * Return string representation close to declaration format,
+ * `public static void main(String[] args) throws IOException', e.g.
+ *
+ * @return String representation of the method.
+ */
+ public final String toString() {
+ ConstantUtf8 c;
+ String name, signature, access; // Short cuts to constant pool
+ StringBuffer buf;
+ access = Utility.accessToString(access_flags);
+ // Get name and signature from constant pool
+ c = (ConstantUtf8) constant_pool.getConstant(signature_index, Constants.CONSTANT_Utf8);
+ signature = c.getBytes();
+ c = (ConstantUtf8) constant_pool.getConstant(name_index, Constants.CONSTANT_Utf8);
+ name = c.getBytes();
+ signature = Utility.methodSignatureToString(signature, name, access, true,
+ getLocalVariableTable());
+ buf = new StringBuffer(signature);
+ for (int i = 0; i < attributes_count; i++) {
+ Attribute a = attributes[i];
+ if (!((a instanceof Code) || (a instanceof ExceptionTable))) {
+ buf.append(" [").append(a.toString()).append("]");
+ }
+ }
+ ExceptionTable e = getExceptionTable();
+ if (e != null) {
+ String str = e.toString();
+ if (!str.equals("")) {
+ buf.append("\n\t\tthrows ").append(str);
+ }
+ }
+ return buf.toString();
+ }
+
+
+ /**
+ * @return deep copy of this method
+ */
+ public final Method copy( ConstantPool _constant_pool ) {
+ return (Method) copy_(_constant_pool);
+ }
+
+
+ /**
+ * @return return type of method
+ */
+ public Type getReturnType() {
+ return Type.getReturnType(getSignature());
+ }
+
+
+ /**
+ * @return array of method argument types
+ */
+ public Type[] getArgumentTypes() {
+ return Type.getArgumentTypes(getSignature());
+ }
+
+
+ /**
+ * @return Comparison strategy object
+ */
+ public static BCELComparator getComparator() {
+ return _cmp;
+ }
+
+
+ /**
+ * @param comparator Comparison strategy object
+ */
+ public static void setComparator( BCELComparator comparator ) {
+ _cmp = comparator;
+ }
+
+
+ /**
+ * Return value as defined by given BCELComparator strategy.
+ * By default two method objects are said to be equal when
+ * their names and signatures are equal.
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals( Object obj ) {
+ return _cmp.equals(this, obj);
+ }
+
+
+ /**
+ * Return value as defined by given BCELComparator strategy.
+ * By default return the hashcode of the method's name XOR signature.
+ *
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode() {
+ return _cmp.hashCode(this);
+ }
}
Modified: jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/Node.java
URL: http://svn.apache.org/viewcvs/jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/Node.java?rev=386056&r1=386055&r2=386056&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/Node.java (original)
+++ jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/Node.java Wed Mar 15 03:31:56 2006
@@ -13,10 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- */
+ */
package org.apache.bcel.classfile;
-
/**
* Denote class to have an accept method();
*
@@ -24,5 +23,6 @@
* @author <A HREF="mailto:[email protected]">M. Dahm</A>
*/
public interface Node {
- public void accept(Visitor obj);
+
+ public void accept( Visitor obj );
}
Modified: jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/PMGClass.java
URL: http://svn.apache.org/viewcvs/jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/PMGClass.java?rev=386056&r1=386055&r2=386056&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/PMGClass.java (original)
+++ jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/PMGClass.java Wed Mar 15 03:31:56 2006
@@ -13,10 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- */
+ */
package org.apache.bcel.classfile;
-
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@@ -31,124 +30,138 @@
* @see Attribute
*/
public final class PMGClass extends Attribute {
- private int pmg_class_index, pmg_index;
- /**
- * Initialize from another object. Note that both objects use the same
- * references (shallow copy). Use clone() for a physical copy.
- */
- public PMGClass(PMGClass c) {
- this(c.getNameIndex(), c.getLength(), c.getPMGIndex(), c.getPMGClassIndex(),
- c.getConstantPool());
- }
-
- /**
- * Construct object from file stream.
- * @param name_index Index in constant pool to CONSTANT_Utf8
- * @param length Content length in bytes
- * @param file Input stream
- * @param constant_pool Array of constants
- * @throws IOException
- */
- PMGClass(int name_index, int length, DataInputStream file,
- ConstantPool constant_pool) throws IOException
- {
- this(name_index, length, file.readUnsignedShort(), file.readUnsignedShort(),
- constant_pool);
- }
-
- /**
- * @param name_index Index in constant pool to CONSTANT_Utf8
- * @param length Content length in bytes
- * @param pmg_index index in constant pool for source file name
- * @param pmg_class_index Index in constant pool to CONSTANT_Utf8
- * @param constant_pool Array of constants
- */
- public PMGClass(int name_index, int length, int pmg_index, int pmg_class_index,
- ConstantPool constant_pool)
- {
- super(Constants.ATTR_PMG, name_index, length, constant_pool);
- this.pmg_index = pmg_index;
- this.pmg_class_index = pmg_class_index;
- }
-
- /**
- * Called by objects that are traversing the nodes of the tree implicitely
- * defined by the contents of a Java class. I.e., the hierarchy of methods,
- * fields, attributes, etc. spawns a tree of objects.
- *
- * @param v Visitor object
- */
- public void accept(Visitor v) {
- System.err.println("Visiting non-standard PMGClass object");
- }
-
- /**
- * Dump source file attribute to file stream in binary format.
- *
- * @param file Output file stream
- * @throws IOException
- */
- public final void dump(DataOutputStream file) throws IOException
- {
- super.dump(file);
- file.writeShort(pmg_index);
- file.writeShort(pmg_class_index);
- }
-
- /**
- * @return Index in constant pool of source file name.
- */
- public final int getPMGClassIndex() { return pmg_class_index; }
-
- /**
- * @param pmg_class_index
- */
- public final void setPMGClassIndex(int pmg_class_index) {
- this.pmg_class_index = pmg_class_index;
- }
-
- /**
- * @return Index in constant pool of source file name.
- */
- public final int getPMGIndex() { return pmg_index; }
-
- /**
- * @param pmg_index
- */
- public final void setPMGIndex(int pmg_index) {
- this.pmg_index = pmg_index;
- }
-
- /**
- * @return PMG name.
- */
- public final String getPMGName() {
- ConstantUtf8 c = (ConstantUtf8)constant_pool.getConstant(pmg_index,
- Constants.CONSTANT_Utf8);
- return c.getBytes();
- }
-
- /**
- * @return PMG class name.
- */
- public final String getPMGClassName() {
- ConstantUtf8 c = (ConstantUtf8)constant_pool.getConstant(pmg_class_index,
- Constants.CONSTANT_Utf8);
- return c.getBytes();
- }
-
- /**
- * @return String representation
- */
- public final String toString() {
- return "PMGClass(" + getPMGName() + ", " + getPMGClassName() + ")";
- }
-
- /**
- * @return deep copy of this attribute
- */
- public Attribute copy(ConstantPool _constant_pool) {
- return (PMGClass)clone();
- }
+ private int pmg_class_index, pmg_index;
+
+
+ /**
+ * Initialize from another object. Note that both objects use the same
+ * references (shallow copy). Use clone() for a physical copy.
+ */
+ public PMGClass(PMGClass c) {
+ this(c.getNameIndex(), c.getLength(), c.getPMGIndex(), c.getPMGClassIndex(), c
+ .getConstantPool());
+ }
+
+
+ /**
+ * Construct object from file stream.
+ * @param name_index Index in constant pool to CONSTANT_Utf8
+ * @param length Content length in bytes
+ * @param file Input stream
+ * @param constant_pool Array of constants
+ * @throws IOException
+ */
+ PMGClass(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
+ throws IOException {
+ this(name_index, length, file.readUnsignedShort(), file.readUnsignedShort(), constant_pool);
+ }
+
+
+ /**
+ * @param name_index Index in constant pool to CONSTANT_Utf8
+ * @param length Content length in bytes
+ * @param pmg_index index in constant pool for source file name
+ * @param pmg_class_index Index in constant pool to CONSTANT_Utf8
+ * @param constant_pool Array of constants
+ */
+ public PMGClass(int name_index, int length, int pmg_index, int pmg_class_index,
+ ConstantPool constant_pool) {
+ super(Constants.ATTR_PMG, name_index, length, constant_pool);
+ this.pmg_index = pmg_index;
+ this.pmg_class_index = pmg_class_index;
+ }
+
+
+ /**
+ * Called by objects that are traversing the nodes of the tree implicitely
+ * defined by the contents of a Java class. I.e., the hierarchy of methods,
+ * fields, attributes, etc. spawns a tree of objects.
+ *
+ * @param v Visitor object
+ */
+ public void accept( Visitor v ) {
+ System.err.println("Visiting non-standard PMGClass object");
+ }
+
+
+ /**
+ * Dump source file attribute to file stream in binary format.
+ *
+ * @param file Output file stream
+ * @throws IOException
+ */
+ public final void dump( DataOutputStream file ) throws IOException {
+ super.dump(file);
+ file.writeShort(pmg_index);
+ file.writeShort(pmg_class_index);
+ }
+
+
+ /**
+ * @return Index in constant pool of source file name.
+ */
+ public final int getPMGClassIndex() {
+ return pmg_class_index;
+ }
+
+
+ /**
+ * @param pmg_class_index
+ */
+ public final void setPMGClassIndex( int pmg_class_index ) {
+ this.pmg_class_index = pmg_class_index;
+ }
+
+
+ /**
+ * @return Index in constant pool of source file name.
+ */
+ public final int getPMGIndex() {
+ return pmg_index;
+ }
+
+
+ /**
+ * @param pmg_index
+ */
+ public final void setPMGIndex( int pmg_index ) {
+ this.pmg_index = pmg_index;
+ }
+
+
+ /**
+ * @return PMG name.
+ */
+ public final String getPMGName() {
+ ConstantUtf8 c = (ConstantUtf8) constant_pool.getConstant(pmg_index,
+ Constants.CONSTANT_Utf8);
+ return c.getBytes();
+ }
+
+
+ /**
+ * @return PMG class name.
+ */
+ public final String getPMGClassName() {
+ ConstantUtf8 c = (ConstantUtf8) constant_pool.getConstant(pmg_class_index,
+ Constants.CONSTANT_Utf8);
+ return c.getBytes();
+ }
+
+
+ /**
+ * @return String representation
+ */
+ public final String toString() {
+ return "PMGClass(" + getPMGName() + ", " + getPMGClassName() + ")";
+ }
+
+
+ /**
+ * @return deep copy of this attribute
+ */
+ public Attribute copy( ConstantPool _constant_pool ) {
+ return (PMGClass) clone();
+ }
}
Modified: jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/ParameterAnnotationEntry.java
URL: http://svn.apache.org/viewcvs/jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/ParameterAnnotationEntry.java?rev=386056&r1=386055&r2=386056&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/ParameterAnnotationEntry.java (original)
+++ jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/ParameterAnnotationEntry.java Wed Mar 15 03:31:56 2006
@@ -20,53 +20,56 @@
import java.io.IOException;
import org.apache.bcel.Constants;
-
/**
* represents one parameter annotation in the parameter annotation table
*
* @version $Id: ParameterAnnotationEntry
* @author <A HREF="mailto:[email protected]">D. Brosius</A>
*/
-public class ParameterAnnotationEntry implements Node, Constants
-{
- private int annotation_table_length;
- private AnnotationEntry[] annotation_table;
-
- /**
- * Construct object from file stream.
- * @param file Input stream
- * @throws IOException
- */
- ParameterAnnotationEntry(DataInputStream file, ConstantPool constant_pool)
- throws IOException
- {
- annotation_table_length = (file.readUnsignedShort());
-
- annotation_table = new AnnotationEntry[annotation_table_length];
- for(int i=0; i < annotation_table_length; i++)
- annotation_table[i] = new AnnotationEntry(file, constant_pool);
- }
-
- /**
- * Called by objects that are traversing the nodes of the tree implicitely
- * defined by the contents of a Java class. I.e., the hierarchy of methods,
- * fields, attributes, etc. spawns a tree of objects.
- *
- * @param v Visitor object
- */
- public void accept(Visitor v) {
-// v.visitParameterAnnotationEntry(this);
- }
-
- /**
- * @return the number of annotation entries in this parameter annotation
- */
- public final int getNumAnnotations() { return annotation_table_length; }
-
- /**
- * returns the array of annotation entries in this annotation
- */
- public AnnotationEntry[] getAnnotationEntries() {
- return annotation_table;
- }
+public class ParameterAnnotationEntry implements Node, Constants {
+
+ private int annotation_table_length;
+ private AnnotationEntry[] annotation_table;
+
+
+ /**
+ * Construct object from file stream.
+ * @param file Input stream
+ * @throws IOException
+ */
+ ParameterAnnotationEntry(DataInputStream file, ConstantPool constant_pool) throws IOException {
+ annotation_table_length = (file.readUnsignedShort());
+ annotation_table = new AnnotationEntry[annotation_table_length];
+ for (int i = 0; i < annotation_table_length; i++) {
+ annotation_table[i] = new AnnotationEntry(file, constant_pool);
+ }
+ }
+
+
+ /**
+ * Called by objects that are traversing the nodes of the tree implicitely
+ * defined by the contents of a Java class. I.e., the hierarchy of methods,
+ * fields, attributes, etc. spawns a tree of objects.
+ *
+ * @param v Visitor object
+ */
+ public void accept( Visitor v ) {
+ // v.visitParameterAnnotationEntry(this);
+ }
+
+
+ /**
+ * @return the number of annotation entries in this parameter annotation
+ */
+ public final int getNumAnnotations() {
+ return annotation_table_length;
+ }
+
+
+ /**
+ * returns the array of annotation entries in this annotation
+ */
+ public AnnotationEntry[] getAnnotationEntries() {
+ return annotation_table;
+ }
}
Modified: jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/ParameterAnnotations.java
URL: http://svn.apache.org/viewcvs/jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/ParameterAnnotations.java?rev=386056&r1=386055&r2=386056&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/ParameterAnnotations.java (original)
+++ jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/ParameterAnnotations.java Wed Mar 15 03:31:56 2006
@@ -27,80 +27,87 @@
*/
public abstract class ParameterAnnotations extends Attribute {
- private int num_parameters;
- private ParameterAnnotationEntry[] parameter_annotation_table; // Table of parameter annotations
+ private int num_parameters;
+ private ParameterAnnotationEntry[] parameter_annotation_table; // Table of parameter annotations
- /**
- * @param parameter_annotation_type the subclass type of the parameter annotation
- * @param name_index Index pointing to the name <em>Code</em>
- * @param length Content length in bytes
- * @param file Input stream
- * @param constant_pool Array of constants
- */
- ParameterAnnotations(byte parameter_annotation_type, int name_index, int length, DataInputStream file,
- ConstantPool constant_pool) throws IOException
- {
- this(parameter_annotation_type, name_index, length, (ParameterAnnotationEntry[]) null, constant_pool);
-
- num_parameters = (file.readUnsignedByte());
- parameter_annotation_table = new ParameterAnnotationEntry[num_parameters];
-
- for(int i=0; i < num_parameters; i++)
- parameter_annotation_table[i] = new ParameterAnnotationEntry(file, constant_pool);
- }
-
- /**
- * @param parameter_annotation_type the subclass type of the parameter annotation
- * @param name_index Index pointing to the name <em>Code</em>
- * @param length Content length in bytes
- * @param parameter_annotation_table the actual parameter annotations
- * @param constant_pool Array of constants
- */
- public ParameterAnnotations(byte parameter_annotation_type, int name_index, int length, ParameterAnnotationEntry[] parameter_annotation_table, ConstantPool constant_pool)
- {
- super(parameter_annotation_type, name_index, length, constant_pool);
- setParameterAnnotationTable(parameter_annotation_table);
-
- }
-
- /**
- * Called by objects that are traversing the nodes of the tree implicitely
- * defined by the contents of a Java class. I.e., the hierarchy of methods,
- * fields, attributes, etc. spawns a tree of objects.
- *
- * @param v Visitor object
- */
- public void accept(Visitor v) {
-// v.visitParameterAnnotation(this);
- }
-
- /**
- * @param parameter_annotation_table the entries to set in this parameter annotation
- */
- public final void setParameterAnnotationTable(ParameterAnnotationEntry[] parameter_annotation_table)
- {
- this.parameter_annotation_table = parameter_annotation_table;
- num_parameters = (parameter_annotation_table == null)? 0 :
- parameter_annotation_table.length;
- }
-
- /**
- * @return the parameter annotation entry table
- */
- public final ParameterAnnotationEntry[] getParameterAnnotationTable()
- {
- return parameter_annotation_table;
- }
-
- /**
- * returns the array of parameter annotation entries in this parameter annotation
- */
- public ParameterAnnotationEntry[] getParameterAnnotationEntries() {
- return parameter_annotation_table;
- }
-
- /**
- * @return the number of parameter annotation entries in this parameter annotation
- */
- public final int getNumParameterAnnotation() { return num_parameters; }
+
+ /**
+ * @param parameter_annotation_type the subclass type of the parameter annotation
+ * @param name_index Index pointing to the name <em>Code</em>
+ * @param length Content length in bytes
+ * @param file Input stream
+ * @param constant_pool Array of constants
+ */
+ ParameterAnnotations(byte parameter_annotation_type, int name_index, int length,
+ DataInputStream file, ConstantPool constant_pool) throws IOException {
+ this(parameter_annotation_type, name_index, length, (ParameterAnnotationEntry[]) null,
+ constant_pool);
+ num_parameters = (file.readUnsignedByte());
+ parameter_annotation_table = new ParameterAnnotationEntry[num_parameters];
+ for (int i = 0; i < num_parameters; i++) {
+ parameter_annotation_table[i] = new ParameterAnnotationEntry(file, constant_pool);
+ }
+ }
+
+
+ /**
+ * @param parameter_annotation_type the subclass type of the parameter annotation
+ * @param name_index Index pointing to the name <em>Code</em>
+ * @param length Content length in bytes
+ * @param parameter_annotation_table the actual parameter annotations
+ * @param constant_pool Array of constants
+ */
+ public ParameterAnnotations(byte parameter_annotation_type, int name_index, int length,
+ ParameterAnnotationEntry[] parameter_annotation_table, ConstantPool constant_pool) {
+ super(parameter_annotation_type, name_index, length, constant_pool);
+ setParameterAnnotationTable(parameter_annotation_table);
+ }
+
+
+ /**
+ * Called by objects that are traversing the nodes of the tree implicitely
+ * defined by the contents of a Java class. I.e., the hierarchy of methods,
+ * fields, attributes, etc. spawns a tree of objects.
+ *
+ * @param v Visitor object
+ */
+ public void accept( Visitor v ) {
+ // v.visitParameterAnnotation(this);
+ }
+
+
+ /**
+ * @param parameter_annotation_table the entries to set in this parameter annotation
+ */
+ public final void setParameterAnnotationTable(
+ ParameterAnnotationEntry[] parameter_annotation_table ) {
+ this.parameter_annotation_table = parameter_annotation_table;
+ num_parameters = (parameter_annotation_table == null)
+ ? 0
+ : parameter_annotation_table.length;
+ }
+
+
+ /**
+ * @return the parameter annotation entry table
+ */
+ public final ParameterAnnotationEntry[] getParameterAnnotationTable() {
+ return parameter_annotation_table;
+ }
+
+
+ /**
+ * returns the array of parameter annotation entries in this parameter annotation
+ */
+ public ParameterAnnotationEntry[] getParameterAnnotationEntries() {
+ return parameter_annotation_table;
+ }
+
+
+ /**
+ * @return the number of parameter annotation entries in this parameter annotation
+ */
+ public final int getNumParameterAnnotation() {
+ return num_parameters;
+ }
}
Modified: jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/RuntimeInvisibleAnnotations.java
URL: http://svn.apache.org/viewcvs/jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/RuntimeInvisibleAnnotations.java?rev=386056&r1=386055&r2=386056&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/RuntimeInvisibleAnnotations.java (original)
+++ jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/RuntimeInvisibleAnnotations.java Wed Mar 15 03:31:56 2006
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- */
+ */
package org.apache.bcel.classfile;
import java.io.DataInputStream;
@@ -27,27 +27,25 @@
* @version $Id: RuntimeInvisibleAnnotations
* @author <A HREF="mailto:[email protected]">D. Brosius</A>
*/
-public class RuntimeInvisibleAnnotations extends Annotations
-{
- /**
- * @param name_index Index pointing to the name <em>Code</em>
- * @param length Content length in bytes
- * @param file Input stream
- * @param constant_pool Array of constants
- */
- RuntimeInvisibleAnnotations(int name_index, int length, DataInputStream file,
- ConstantPool constant_pool) throws IOException
- {
- super(Constants.ATTR_RUNTIMEINVISIBLE_ANNOTATIONS, name_index, length, file, constant_pool);
- }
+public class RuntimeInvisibleAnnotations extends Annotations {
+
+ /**
+ * @param name_index Index pointing to the name <em>Code</em>
+ * @param length Content length in bytes
+ * @param file Input stream
+ * @param constant_pool Array of constants
+ */
+ RuntimeInvisibleAnnotations(int name_index, int length, DataInputStream file,
+ ConstantPool constant_pool) throws IOException {
+ super(Constants.ATTR_RUNTIMEINVISIBLE_ANNOTATIONS, name_index, length, file, constant_pool);
+ }
- /**
- * @return deep copy of this attribute
- */
- public Attribute copy(ConstantPool constant_pool) {
- Annotations c = (Annotations)clone();
-
- return c;
- }
+ /**
+ * @return deep copy of this attribute
+ */
+ public Attribute copy( ConstantPool constant_pool ) {
+ Annotations c = (Annotations) clone();
+ return c;
+ }
}
Modified: jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/RuntimeInvisibleParameterAnnotations.java
URL: http://svn.apache.org/viewcvs/jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/RuntimeInvisibleParameterAnnotations.java?rev=386056&r1=386055&r2=386056&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/RuntimeInvisibleParameterAnnotations.java (original)
+++ jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/RuntimeInvisibleParameterAnnotations.java Wed Mar 15 03:31:56 2006
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- */
+ */
package org.apache.bcel.classfile;
import java.io.DataInputStream;
@@ -27,27 +27,26 @@
* @version $Id: RuntimeInvisibleParameterAnnotations
* @author <A HREF="mailto:[email protected]">D. Brosius</A>
*/
-public class RuntimeInvisibleParameterAnnotations extends ParameterAnnotations
-{
- /**
- * @param name_index Index pointing to the name <em>Code</em>
- * @param length Content length in bytes
- * @param file Input stream
- * @param constant_pool Array of constants
- */
- RuntimeInvisibleParameterAnnotations(int name_index, int length, DataInputStream file,
- ConstantPool constant_pool) throws IOException
- {
- super(Constants.ATTR_RUNTIMEINVISIBLE_PARAMETER_ANNOTATIONS, name_index, length, file, constant_pool);
- }
+public class RuntimeInvisibleParameterAnnotations extends ParameterAnnotations {
+
+ /**
+ * @param name_index Index pointing to the name <em>Code</em>
+ * @param length Content length in bytes
+ * @param file Input stream
+ * @param constant_pool Array of constants
+ */
+ RuntimeInvisibleParameterAnnotations(int name_index, int length, DataInputStream file,
+ ConstantPool constant_pool) throws IOException {
+ super(Constants.ATTR_RUNTIMEINVISIBLE_PARAMETER_ANNOTATIONS, name_index, length, file,
+ constant_pool);
+ }
- /**
- * @return deep copy of this attribute
- */
- public Attribute copy(ConstantPool constant_pool) {
- Annotations c = (Annotations)clone();
-
- return c;
- }
+ /**
+ * @return deep copy of this attribute
+ */
+ public Attribute copy( ConstantPool constant_pool ) {
+ Annotations c = (Annotations) clone();
+ return c;
+ }
}
Modified: jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/RuntimeVisibleAnnotations.java
URL: http://svn.apache.org/viewcvs/jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/RuntimeVisibleAnnotations.java?rev=386056&r1=386055&r2=386056&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/RuntimeVisibleAnnotations.java (original)
+++ jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/RuntimeVisibleAnnotations.java Wed Mar 15 03:31:56 2006
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- */
+ */
package org.apache.bcel.classfile;
import java.io.DataInputStream;
@@ -27,27 +27,25 @@
* @version $Id: RuntimeVisibleAnnotations
* @author <A HREF="mailto:[email protected]">D. Brosius</A>
*/
-public class RuntimeVisibleAnnotations extends Annotations
-{
- /**
- * @param name_index Index pointing to the name <em>Code</em>
- * @param length Content length in bytes
- * @param file Input stream
- * @param constant_pool Array of constants
- */
- RuntimeVisibleAnnotations(int name_index, int length, DataInputStream file,
- ConstantPool constant_pool) throws IOException
- {
- super(Constants.ATTR_RUNTIMEVISIBLE_ANNOTATIONS, name_index, length, file, constant_pool);
- }
+public class RuntimeVisibleAnnotations extends Annotations {
+
+ /**
+ * @param name_index Index pointing to the name <em>Code</em>
+ * @param length Content length in bytes
+ * @param file Input stream
+ * @param constant_pool Array of constants
+ */
+ RuntimeVisibleAnnotations(int name_index, int length, DataInputStream file,
+ ConstantPool constant_pool) throws IOException {
+ super(Constants.ATTR_RUNTIMEVISIBLE_ANNOTATIONS, name_index, length, file, constant_pool);
+ }
- /**
- * @return deep copy of this attribute
- */
- public Attribute copy(ConstantPool constant_pool) {
- Annotations c = (Annotations)clone();
-
- return c;
- }
+ /**
+ * @return deep copy of this attribute
+ */
+ public Attribute copy( ConstantPool constant_pool ) {
+ Annotations c = (Annotations) clone();
+ return c;
+ }
}
Modified: jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/RuntimeVisibleParameterAnnotations.java
URL: http://svn.apache.org/viewcvs/jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/RuntimeVisibleParameterAnnotations.java?rev=386056&r1=386055&r2=386056&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/RuntimeVisibleParameterAnnotations.java (original)
+++ jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/RuntimeVisibleParameterAnnotations.java Wed Mar 15 03:31:56 2006
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- */
+ */
package org.apache.bcel.classfile;
import java.io.DataInputStream;
@@ -27,27 +27,26 @@
* @version $Id: RuntimeVisibleParameterAnnotations
* @author <A HREF="mailto:[email protected]">D. Brosius</A>
*/
-public class RuntimeVisibleParameterAnnotations extends ParameterAnnotations
-{
- /**
- * @param name_index Index pointing to the name <em>Code</em>
- * @param length Content length in bytes
- * @param file Input stream
- * @param constant_pool Array of constants
- */
- RuntimeVisibleParameterAnnotations(int name_index, int length, DataInputStream file,
- ConstantPool constant_pool) throws IOException
- {
- super(Constants.ATTR_RUNTIMEVISIBLE_PARAMETER_ANNOTATIONS, name_index, length, file, constant_pool);
- }
+public class RuntimeVisibleParameterAnnotations extends ParameterAnnotations {
+
+ /**
+ * @param name_index Index pointing to the name <em>Code</em>
+ * @param length Content length in bytes
+ * @param file Input stream
+ * @param constant_pool Array of constants
+ */
+ RuntimeVisibleParameterAnnotations(int name_index, int length, DataInputStream file,
+ ConstantPool constant_pool) throws IOException {
+ super(Constants.ATTR_RUNTIMEVISIBLE_PARAMETER_ANNOTATIONS, name_index, length, file,
+ constant_pool);
+ }
- /**
- * @return deep copy of this attribute
- */
- public Attribute copy(ConstantPool constant_pool) {
- Annotations c = (Annotations)clone();
-
- return c;
- }
+ /**
+ * @return deep copy of this attribute
+ */
+ public Attribute copy( ConstantPool constant_pool ) {
+ Annotations c = (Annotations) clone();
+ return c;
+ }
}
Modified: jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/Signature.java
URL: http://svn.apache.org/viewcvs/jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/Signature.java?rev=386056&r1=386055&r2=386056&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/Signature.java (original)
+++ jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/Signature.java Wed Mar 15 03:31:56 2006
@@ -13,10 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- */
+ */
package org.apache.bcel.classfile;
-
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@@ -32,227 +31,243 @@
* @see Attribute
*/
public final class Signature extends Attribute {
- private int signature_index;
- /**
- * Initialize from another object. Note that both objects use the same
- * references (shallow copy). Use clone() for a physical copy.
- */
- public Signature(Signature c) {
- this(c.getNameIndex(), c.getLength(), c.getSignatureIndex(), c.getConstantPool());
- }
-
- /**
- * Construct object from file stream.
- * @param name_index Index in constant pool to CONSTANT_Utf8
- * @param length Content length in bytes
- * @param file Input stream
- * @param constant_pool Array of constants
- * @throws IOException
- */
- Signature(int name_index, int length, DataInputStream file,
- ConstantPool constant_pool) throws IOException
- {
- this(name_index, length, file.readUnsignedShort(), constant_pool);
- }
-
- /**
- * @param name_index Index in constant pool to CONSTANT_Utf8
- * @param length Content length in bytes
- * @param signature_index Index in constant pool to CONSTANT_Utf8
- * @param constant_pool Array of constants
- */
- public Signature(int name_index, int length, int signature_index,
- ConstantPool constant_pool)
- {
- super(Constants.ATTR_SIGNATURE, name_index, length, constant_pool);
- this.signature_index = signature_index;
- }
-
- /**
- * Called by objects that are traversing the nodes of the tree implicitely
- * defined by the contents of a Java class. I.e., the hierarchy of methods,
- * fields, attributes, etc. spawns a tree of objects.
- *
- * @param v Visitor object
- */
- public void accept(Visitor v) {
- //System.err.println("Visiting non-standard Signature object");
- v.visitSignature(this);
- }
-
- /**
- * Dump source file attribute to file stream in binary format.
- *
- * @param file Output file stream
- * @throws IOException
- */
- public final void dump(DataOutputStream file) throws IOException
- {
- super.dump(file);
- file.writeShort(signature_index);
- }
-
- /**
- * @return Index in constant pool of source file name.
- */
- public final int getSignatureIndex() { return signature_index; }
-
- /**
- * @param signature_index the index info the constant pool of this signature
- */
- public final void setSignatureIndex(int signature_index) {
- this.signature_index = signature_index;
- }
-
- /**
- * @return GJ signature.
- */
- public final String getSignature() {
- ConstantUtf8 c = (ConstantUtf8)constant_pool.getConstant(signature_index,
- Constants.CONSTANT_Utf8);
- return c.getBytes();
- }
-
- /**
- * Extends ByteArrayInputStream to make 'unreading' chars possible.
- */
- private static final class MyByteArrayInputStream extends ByteArrayInputStream {
- MyByteArrayInputStream(String data) { super(data.getBytes()); }
- final int mark() { return pos; }
- final String getData() { return new String(buf); }
- final void reset(int p) { pos = p; }
- final void unread() { if(pos > 0) pos--; }
- }
-
- private static boolean identStart(int ch) {
- return ch == 'T' || ch == 'L';
- }
-
- private static final void matchIdent(MyByteArrayInputStream in, StringBuffer buf) {
- int ch;
-
- if((ch = in.read()) == -1)
- throw new RuntimeException("Illegal signature: " + in.getData() +
- " no ident, reaching EOF");
-
- //System.out.println("return from ident:" + (char)ch);
-
- if(!identStart(ch)) {
- StringBuffer buf2 = new StringBuffer();
-
- int count = 1;
- while(Character.isJavaIdentifierPart((char)ch)) {
- buf2.append((char)ch);
- count++;
- ch = in.read();
- }
-
- if(ch == ':') { // Ok, formal parameter
- in.skip("Ljava/lang/Object".length());
- buf.append(buf2);
+ private int signature_index;
+
+
+ /**
+ * Initialize from another object. Note that both objects use the same
+ * references (shallow copy). Use clone() for a physical copy.
+ */
+ public Signature(Signature c) {
+ this(c.getNameIndex(), c.getLength(), c.getSignatureIndex(), c.getConstantPool());
+ }
+
+
+ /**
+ * Construct object from file stream.
+ * @param name_index Index in constant pool to CONSTANT_Utf8
+ * @param length Content length in bytes
+ * @param file Input stream
+ * @param constant_pool Array of constants
+ * @throws IOException
+ */
+ Signature(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
+ throws IOException {
+ this(name_index, length, file.readUnsignedShort(), constant_pool);
+ }
+
+
+ /**
+ * @param name_index Index in constant pool to CONSTANT_Utf8
+ * @param length Content length in bytes
+ * @param signature_index Index in constant pool to CONSTANT_Utf8
+ * @param constant_pool Array of constants
+ */
+ public Signature(int name_index, int length, int signature_index, ConstantPool constant_pool) {
+ super(Constants.ATTR_SIGNATURE, name_index, length, constant_pool);
+ this.signature_index = signature_index;
+ }
+
+
+ /**
+ * Called by objects that are traversing the nodes of the tree implicitely
+ * defined by the contents of a Java class. I.e., the hierarchy of methods,
+ * fields, attributes, etc. spawns a tree of objects.
+ *
+ * @param v Visitor object
+ */
+ public void accept( Visitor v ) {
+ //System.err.println("Visiting non-standard Signature object");
+ v.visitSignature(this);
+ }
+
+
+ /**
+ * Dump source file attribute to file stream in binary format.
+ *
+ * @param file Output file stream
+ * @throws IOException
+ */
+ public final void dump( DataOutputStream file ) throws IOException {
+ super.dump(file);
+ file.writeShort(signature_index);
+ }
+
+
+ /**
+ * @return Index in constant pool of source file name.
+ */
+ public final int getSignatureIndex() {
+ return signature_index;
+ }
+
+
+ /**
+ * @param signature_index the index info the constant pool of this signature
+ */
+ public final void setSignatureIndex( int signature_index ) {
+ this.signature_index = signature_index;
+ }
+
+
+ /**
+ * @return GJ signature.
+ */
+ public final String getSignature() {
+ ConstantUtf8 c = (ConstantUtf8) constant_pool.getConstant(signature_index,
+ Constants.CONSTANT_Utf8);
+ return c.getBytes();
+ }
+
+ /**
+ * Extends ByteArrayInputStream to make 'unreading' chars possible.
+ */
+ private static final class MyByteArrayInputStream extends ByteArrayInputStream {
+
+ MyByteArrayInputStream(String data) {
+ super(data.getBytes());
+ }
+
+
+ final int mark() {
+ return pos;
+ }
+
+ final String getData() {
+ return new String(buf);
+ }
+
+
+ final void reset( int p ) {
+ pos = p;
+ }
+
+
+ final void unread() {
+ if (pos > 0) {
+ pos--;
+ }
+ }
+ }
+
+
+ private static boolean identStart( int ch ) {
+ return ch == 'T' || ch == 'L';
+ }
+
+
+ private static final void matchIdent( MyByteArrayInputStream in, StringBuffer buf ) {
+ int ch;
+ if ((ch = in.read()) == -1) {
+ throw new RuntimeException("Illegal signature: " + in.getData()
+ + " no ident, reaching EOF");
+ }
+ //System.out.println("return from ident:" + (char)ch);
+ if (!identStart(ch)) {
+ StringBuffer buf2 = new StringBuffer();
+ int count = 1;
+ while (Character.isJavaIdentifierPart((char) ch)) {
+ buf2.append((char) ch);
+ count++;
+ ch = in.read();
+ }
+ if (ch == ':') { // Ok, formal parameter
+ in.skip("Ljava/lang/Object".length());
+ buf.append(buf2);
+ ch = in.read();
+ in.unread();
+ //System.out.println("so far:" + buf2 + ":next:" +(char)ch);
+ } else {
+ for (int i = 0; i < count; i++) {
+ in.unread();
+ }
+ }
+ return;
+ }
+ StringBuffer buf2 = new StringBuffer();
+ ch = in.read();
+ do {
+ buf2.append((char) ch);
+ ch = in.read();
+ //System.out.println("within ident:"+ (char)ch);
+ } while ((ch != -1) && (Character.isJavaIdentifierPart((char) ch) || (ch == '/')));
+ buf.append(buf2.toString().replace('/', '.'));
+ //System.out.println("regular return ident:"+ (char)ch + ":" + buf2);
+ if (ch != -1) {
+ in.unread();
+ }
+ }
+
+
+ private static final void matchGJIdent( MyByteArrayInputStream in, StringBuffer buf ) {
+ int ch;
+ matchIdent(in, buf);
ch = in.read();
- in.unread();
- //System.out.println("so far:" + buf2 + ":next:" +(char)ch);
- } else {
- for(int i=0; i < count; i++)
- in.unread();
- }
-
- return;
- }
-
- StringBuffer buf2 = new StringBuffer();
- ch = in.read();
-
- do {
- buf2.append((char)ch);
- ch = in.read();
- //System.out.println("within ident:"+ (char)ch);
-
- } while((ch != -1) && (Character.isJavaIdentifierPart((char)ch) || (ch == '/')));
-
- buf.append(buf2.toString().replace('/', '.'));
-
- //System.out.println("regular return ident:"+ (char)ch + ":" + buf2);
-
- if(ch != -1)
- in.unread();
- }
-
- private static final void matchGJIdent(MyByteArrayInputStream in,
- StringBuffer buf)
- {
- int ch;
-
- matchIdent(in, buf);
-
- ch = in.read();
- if((ch == '<') || ch == '(') { // Parameterized or method
- //System.out.println("Enter <");
- buf.append((char)ch);
- matchGJIdent(in, buf);
-
- while(((ch = in.read()) != '>') && (ch != ')')) { // List of parameters
- if(ch == -1)
- throw new RuntimeException("Illegal signature: " + in.getData() +
- " reaching EOF");
-
- //System.out.println("Still no >");
- buf.append(", ");
- in.unread();
- matchGJIdent(in, buf); // Recursive call
- }
-
- //System.out.println("Exit >");
-
- buf.append((char)ch);
- } else
- in.unread();
-
- ch = in.read();
- if(identStart(ch)) {
- in.unread();
- matchGJIdent(in, buf);
- } else if(ch == ')') {
- in.unread();
- return;
- } else if(ch != ';')
- throw new RuntimeException("Illegal signature: " + in.getData() + " read " +
- (char)ch);
- }
-
- public static String translate(String s) {
- //System.out.println("Sig:" + s);
- StringBuffer buf = new StringBuffer();
-
- matchGJIdent(new MyByteArrayInputStream(s), buf);
-
- return buf.toString();
- }
-
- public static final boolean isFormalParameterList(String s) {
- return s.startsWith("<") && (s.indexOf(':') > 0);
- }
-
- public static final boolean isActualParameterList(String s) {
- return s.startsWith("L") && s.endsWith(">;");
- }
-
- /**
- * @return String representation
- */
- public final String toString() {
- String s = getSignature();
-
- return "Signature(" + s + ")";
- }
-
- /**
- * @return deep copy of this attribute
- */
- public Attribute copy(ConstantPool _constant_pool) {
- return (Signature)clone();
- }
+ if ((ch == '<') || ch == '(') { // Parameterized or method
+ //System.out.println("Enter <");
+ buf.append((char) ch);
+ matchGJIdent(in, buf);
+ while (((ch = in.read()) != '>') && (ch != ')')) { // List of parameters
+ if (ch == -1) {
+ throw new RuntimeException("Illegal signature: " + in.getData()
+ + " reaching EOF");
+ }
+ //System.out.println("Still no >");
+ buf.append(", ");
+ in.unread();
+ matchGJIdent(in, buf); // Recursive call
+ }
+ //System.out.println("Exit >");
+ buf.append((char) ch);
+ } else {
+ in.unread();
+ }
+ ch = in.read();
+ if (identStart(ch)) {
+ in.unread();
+ matchGJIdent(in, buf);
+ } else if (ch == ')') {
+ in.unread();
+ return;
+ } else if (ch != ';') {
+ throw new RuntimeException("Illegal signature: " + in.getData() + " read " + (char) ch);
+ }
+ }
+
+
+ public static String translate( String s ) {
+ //System.out.println("Sig:" + s);
+ StringBuffer buf = new StringBuffer();
+ matchGJIdent(new MyByteArrayInputStream(s), buf);
+ return buf.toString();
+ }
+
+
+ public static final boolean isFormalParameterList( String s ) {
+ return s.startsWith("<") && (s.indexOf(':') > 0);
+ }
+
+
+ public static final boolean isActualParameterList( String s ) {
+ return s.startsWith("L") && s.endsWith(">;");
+ }
+
+
+ /**
+ * @return String representation
+ */
+ public final String toString() {
+ String s = getSignature();
+ return "Signature(" + s + ")";
+ }
+
+
+ /**
+ * @return deep copy of this attribute
+ */
+ public Attribute copy( ConstantPool _constant_pool ) {
+ return (Signature) clone();
+ }
}
Modified: jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/SourceFile.java
URL: http://svn.apache.org/viewcvs/jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/SourceFile.java?rev=386056&r1=386055&r2=386056&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/SourceFile.java (original)
+++ jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/SourceFile.java Wed Mar 15 03:31:56 2006
@@ -13,10 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- */
+ */
package org.apache.bcel.classfile;
-
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@@ -33,106 +32,114 @@
* @see Attribute
*/
public final class SourceFile extends Attribute {
- private int sourcefile_index;
- /**
- * Initialize from another object. Note that both objects use the same
- * references (shallow copy). Use clone() for a physical copy.
- */
- public SourceFile(SourceFile c) {
- this(c.getNameIndex(), c.getLength(), c.getSourceFileIndex(),
- c.getConstantPool());
- }
-
- /**
- * Construct object from file stream.
- * @param name_index Index in constant pool to CONSTANT_Utf8
- * @param length Content length in bytes
- * @param file Input stream
- * @param constant_pool Array of constants
- * @throws IOException
- */
- SourceFile(int name_index, int length, DataInputStream file,
- ConstantPool constant_pool) throws IOException
- {
- this(name_index, length, file.readUnsignedShort(), constant_pool);
- }
-
- /**
- * @param name_index Index in constant pool to CONSTANT_Utf8, which
- * should represent the string "SourceFile".
- * @param length Content length in bytes, the value should be 2.
- * @param constant_pool The constant pool that this attribute is
- * associated with.
- * @param sourcefile_index Index in constant pool to CONSTANT_Utf8. This
- * string will be interpreted as the name of the file from which this
- * class was compiled. It will not be interpreted as indicating the name
- * of the directory contqining the file or an absolute path; this
- * information has to be supplied the consumer of this attribute - in
- * many cases, the JVM.
- */
- public SourceFile(int name_index, int length, int sourcefile_index,
- ConstantPool constant_pool)
- {
- super(Constants.ATTR_SOURCE_FILE, name_index, length, constant_pool);
- this.sourcefile_index = sourcefile_index;
- }
-
- /**
- * Called by objects that are traversing the nodes of the tree implicitely
- * defined by the contents of a Java class. I.e., the hierarchy of methods,
- * fields, attributes, etc. spawns a tree of objects.
- *
- * @param v Visitor object
- */
- public void accept(Visitor v) {
- v.visitSourceFile(this);
- }
-
- /**
- * Dump source file attribute to file stream in binary format.
- *
- * @param file Output file stream
- * @throws IOException
- */
- public final void dump(DataOutputStream file) throws IOException
- {
- super.dump(file);
- file.writeShort(sourcefile_index);
- }
-
- /**
- * @return Index in constant pool of source file name.
- */
- public final int getSourceFileIndex() { return sourcefile_index; }
-
- /**
- * @param sourcefile_index
- */
- public final void setSourceFileIndex(int sourcefile_index) {
- this.sourcefile_index = sourcefile_index;
- }
-
- /**
- * @return Source file name.
- */
- public final String getSourceFileName() {
- ConstantUtf8 c = (ConstantUtf8)constant_pool.getConstant(sourcefile_index,
- Constants.CONSTANT_Utf8);
- return c.getBytes();
- }
-
- /**
- * @return String representation
- */
- public final String toString() {
- return "SourceFile(" + getSourceFileName() + ")";
- }
-
- /**
- * @return deep copy of this attribute
- */
- public Attribute copy(ConstantPool _constant_pool) {
- return (SourceFile)clone();
- }
+ private int sourcefile_index;
+
+
+ /**
+ * Initialize from another object. Note that both objects use the same
+ * references (shallow copy). Use clone() for a physical copy.
+ */
+ public SourceFile(SourceFile c) {
+ this(c.getNameIndex(), c.getLength(), c.getSourceFileIndex(), c.getConstantPool());
+ }
+
+
+ /**
+ * Construct object from file stream.
+ * @param name_index Index in constant pool to CONSTANT_Utf8
+ * @param length Content length in bytes
+ * @param file Input stream
+ * @param constant_pool Array of constants
+ * @throws IOException
+ */
+ SourceFile(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
+ throws IOException {
+ this(name_index, length, file.readUnsignedShort(), constant_pool);
+ }
+
+
+ /**
+ * @param name_index Index in constant pool to CONSTANT_Utf8, which
+ * should represent the string "SourceFile".
+ * @param length Content length in bytes, the value should be 2.
+ * @param constant_pool The constant pool that this attribute is
+ * associated with.
+ * @param sourcefile_index Index in constant pool to CONSTANT_Utf8. This
+ * string will be interpreted as the name of the file from which this
+ * class was compiled. It will not be interpreted as indicating the name
+ * of the directory contqining the file or an absolute path; this
+ * information has to be supplied the consumer of this attribute - in
+ * many cases, the JVM.
+ */
+ public SourceFile(int name_index, int length, int sourcefile_index, ConstantPool constant_pool) {
+ super(Constants.ATTR_SOURCE_FILE, name_index, length, constant_pool);
+ this.sourcefile_index = sourcefile_index;
+ }
+
+
+ /**
+ * Called by objects that are traversing the nodes of the tree implicitely
+ * defined by the contents of a Java class. I.e., the hierarchy of methods,
+ * fields, attributes, etc. spawns a tree of objects.
+ *
+ * @param v Visitor object
+ */
+ public void accept( Visitor v ) {
+ v.visitSourceFile(this);
+ }
+
+
+ /**
+ * Dump source file attribute to file stream in binary format.
+ *
+ * @param file Output file stream
+ * @throws IOException
+ */
+ public final void dump( DataOutputStream file ) throws IOException {
+ super.dump(file);
+ file.writeShort(sourcefile_index);
+ }
+
+
+ /**
+ * @return Index in constant pool of source file name.
+ */
+ public final int getSourceFileIndex() {
+ return sourcefile_index;
+ }
+
+
+ /**
+ * @param sourcefile_index
+ */
+ public final void setSourceFileIndex( int sourcefile_index ) {
+ this.sourcefile_index = sourcefile_index;
+ }
+
+
+ /**
+ * @return Source file name.
+ */
+ public final String getSourceFileName() {
+ ConstantUtf8 c = (ConstantUtf8) constant_pool.getConstant(sourcefile_index,
+ Constants.CONSTANT_Utf8);
+ return c.getBytes();
+ }
+
+
+ /**
+ * @return String representation
+ */
+ public final String toString() {
+ return "SourceFile(" + getSourceFileName() + ")";
+ }
+
+
+ /**
+ * @return deep copy of this attribute
+ */
+ public Attribute copy( ConstantPool _constant_pool ) {
+ return (SourceFile) clone();
+ }
}
Modified: jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/StackMap.java
URL: http://svn.apache.org/viewcvs/jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/StackMap.java?rev=386056&r1=386055&r2=386056&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/StackMap.java (original)
+++ jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/StackMap.java Wed Mar 15 03:31:56 2006
@@ -13,10 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- */
+ */
package org.apache.bcel.classfile;
-
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@@ -38,113 +37,117 @@
* @see StackMapType
*/
public final class StackMap extends Attribute implements Node {
- private int map_length;
- private StackMapEntry[] map; // Table of stack map entries
- /*
- * @param name_index Index of name
- * @param length Content length in bytes
- * @param map Table of stack map entries
- * @param constant_pool Array of constants
- */
- public StackMap(int name_index, int length, StackMapEntry[] map,
- ConstantPool constant_pool)
- {
- super(Constants.ATTR_STACK_MAP, name_index, length, constant_pool);
-
- setStackMap(map);
- }
-
- /**
- * Construct object from file stream.
- * @param name_index Index of name
- * @param length Content length in bytes
- * @param file Input stream
- * @param constant_pool Array of constants
- * @throws IOException
- */
- StackMap(int name_index, int length, DataInputStream file,
- ConstantPool constant_pool) throws IOException
- {
- this(name_index, length, (StackMapEntry[])null, constant_pool);
-
- map_length = file.readUnsignedShort();
- map = new StackMapEntry[map_length];
-
- for(int i=0; i < map_length; i++)
- map[i] = new StackMapEntry(file, constant_pool);
- }
-
- /**
- * Dump line number table attribute to file stream in binary format.
- *
- * @param file Output file stream
- * @throws IOException
- */
- public final void dump(DataOutputStream file) throws IOException
- {
- super.dump(file);
- file.writeShort(map_length);
- for(int i=0; i < map_length; i++)
- map[i].dump(file);
- }
-
- /**
- * @return Array of stack map entries
- */
- public final StackMapEntry[] getStackMap() { return map; }
-
- /**
- * @param map Array of stack map entries
- */
- public final void setStackMap(StackMapEntry[] map) {
- this.map = map;
-
- map_length = (map == null)? 0 : map.length;
- }
-
- /**
- * @return String representation.
- */
- public final String toString() {
- StringBuffer buf = new StringBuffer("StackMap(");
-
- for(int i=0; i < map_length; i++) {
- buf.append(map[i].toString());
-
- if(i < map_length - 1)
- buf.append(", ");
- }
-
- buf.append(')');
-
- return buf.toString();
- }
-
- /**
- * @return deep copy of this attribute
- */
- public Attribute copy(ConstantPool _constant_pool) {
- StackMap c = (StackMap)clone();
-
- c.map = new StackMapEntry[map_length];
- for(int i=0; i < map_length; i++)
- c.map[i] = map[i].copy();
-
- c.constant_pool = _constant_pool;
- return c;
- }
-
- /**
- * Called by objects that are traversing the nodes of the tree implicitely
- * defined by the contents of a Java class. I.e., the hierarchy of methods,
- * fields, attributes, etc. spawns a tree of objects.
- *
- * @param v Visitor object
- */
- public void accept(Visitor v) {
- v.visitStackMap(this);
- }
+ private int map_length;
+ private StackMapEntry[] map; // Table of stack map entries
+
+
+ /*
+ * @param name_index Index of name
+ * @param length Content length in bytes
+ * @param map Table of stack map entries
+ * @param constant_pool Array of constants
+ */
+ public StackMap(int name_index, int length, StackMapEntry[] map, ConstantPool constant_pool) {
+ super(Constants.ATTR_STACK_MAP, name_index, length, constant_pool);
+ setStackMap(map);
+ }
+
+
+ /**
+ * Construct object from file stream.
+ * @param name_index Index of name
+ * @param length Content length in bytes
+ * @param file Input stream
+ * @param constant_pool Array of constants
+ * @throws IOException
+ */
+ StackMap(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
+ throws IOException {
+ this(name_index, length, (StackMapEntry[]) null, constant_pool);
+ map_length = file.readUnsignedShort();
+ map = new StackMapEntry[map_length];
+ for (int i = 0; i < map_length; i++) {
+ map[i] = new StackMapEntry(file, constant_pool);
+ }
+ }
+
+
+ /**
+ * Dump line number table attribute to file stream in binary format.
+ *
+ * @param file Output file stream
+ * @throws IOException
+ */
+ public final void dump( DataOutputStream file ) throws IOException {
+ super.dump(file);
+ file.writeShort(map_length);
+ for (int i = 0; i < map_length; i++) {
+ map[i].dump(file);
+ }
+ }
+
+
+ /**
+ * @return Array of stack map entries
+ */
+ public final StackMapEntry[] getStackMap() {
+ return map;
+ }
+
+
+ /**
+ * @param map Array of stack map entries
+ */
+ public final void setStackMap( StackMapEntry[] map ) {
+ this.map = map;
+ map_length = (map == null) ? 0 : map.length;
+ }
+
+
+ /**
+ * @return String representation.
+ */
+ public final String toString() {
+ StringBuffer buf = new StringBuffer("StackMap(");
+ for (int i = 0; i < map_length; i++) {
+ buf.append(map[i].toString());
+ if (i < map_length - 1) {
+ buf.append(", ");
+ }
+ }
+ buf.append(')');
+ return buf.toString();
+ }
+
- public final int getMapLength() { return map_length; }
+ /**
+ * @return deep copy of this attribute
+ */
+ public Attribute copy( ConstantPool _constant_pool ) {
+ StackMap c = (StackMap) clone();
+ c.map = new StackMapEntry[map_length];
+ for (int i = 0; i < map_length; i++) {
+ c.map[i] = map[i].copy();
+ }
+ c.constant_pool = _constant_pool;
+ return c;
+ }
+
+
+ /**
+ * Called by objects that are traversing the nodes of the tree implicitely
+ * defined by the contents of a Java class. I.e., the hierarchy of methods,
+ * fields, attributes, etc. spawns a tree of objects.
+ *
+ * @param v Visitor object
+ */
+ public void accept( Visitor v ) {
+ v.visitStackMap(this);
+ }
+
+
+ public final int getMapLength() {
+ return map_length;
+ }
}
Modified: jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/StackMapEntry.java
URL: http://svn.apache.org/viewcvs/jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/StackMapEntry.java?rev=386056&r1=386055&r2=386056&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/StackMapEntry.java (original)
+++ jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/StackMapEntry.java Wed Mar 15 03:31:56 2006
@@ -13,10 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- */
+ */
package org.apache.bcel.classfile;
-
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@@ -32,143 +31,182 @@
* @see StackMapType
*/
public final class StackMapEntry implements Cloneable {
- private int byte_code_offset;
- private int number_of_locals;
- private StackMapType[] types_of_locals;
- private int number_of_stack_items;
- private StackMapType[] types_of_stack_items;
- private ConstantPool constant_pool;
-
- /**
- * Construct object from file stream.
- * @param file Input stream
- * @throws IOException
- */
- StackMapEntry(DataInputStream file, ConstantPool constant_pool) throws IOException
- {
- this(file.readShort(), file.readShort(), null, -1, null, constant_pool);
-
- types_of_locals = new StackMapType[number_of_locals];
- for(int i=0; i < number_of_locals; i++)
- types_of_locals[i] = new StackMapType(file, constant_pool);
-
- number_of_stack_items = file.readShort();
- types_of_stack_items = new StackMapType[number_of_stack_items];
- for(int i=0; i < number_of_stack_items; i++)
- types_of_stack_items[i] = new StackMapType(file, constant_pool);
- }
-
- public StackMapEntry(int byte_code_offset, int number_of_locals,
- StackMapType[] types_of_locals,
- int number_of_stack_items,
- StackMapType[] types_of_stack_items,
- ConstantPool constant_pool) {
- this.byte_code_offset = byte_code_offset;
- this.number_of_locals = number_of_locals;
- this.types_of_locals = types_of_locals;
- this.number_of_stack_items = number_of_stack_items;
- this.types_of_stack_items = types_of_stack_items;
- this.constant_pool = constant_pool;
- }
-
- /**
- * Dump stack map entry
- *
- * @param file Output file stream
- * @throws IOException
- */
- public final void dump(DataOutputStream file) throws IOException
- {
- file.writeShort(byte_code_offset);
-
- file.writeShort(number_of_locals);
- for(int i=0; i < number_of_locals; i++)
- types_of_locals[i].dump(file);
-
- file.writeShort(number_of_stack_items);
- for(int i=0; i < number_of_stack_items; i++)
- types_of_stack_items[i].dump(file);
- }
-
- /**
- * @return String representation.
- */
- public final String toString() {
- StringBuffer buf = new StringBuffer(64);
- buf.append("(offset=").append(byte_code_offset);
-
- if(number_of_locals > 0) {
- buf.append(", locals={");
-
- for(int i=0; i < number_of_locals; i++) {
- buf.append(types_of_locals[i]);
- if(i < number_of_locals - 1)
- buf.append(", ");
- }
-
- buf.append("}");
- }
-
- if(number_of_stack_items > 0) {
- buf.append(", stack items={");
-
- for(int i=0; i < number_of_stack_items; i++) {
- buf.append(types_of_stack_items[i]);
- if(i < number_of_stack_items - 1)
- buf.append(", ");
- }
-
- buf.append("}");
- }
-
- buf.append(")");
-
- return buf.toString();
- }
-
-
- public void setByteCodeOffset(int b) { byte_code_offset = b; }
- public int getByteCodeOffset() { return byte_code_offset; }
- public void setNumberOfLocals(int n) { number_of_locals = n; }
- public int getNumberOfLocals() { return number_of_locals; }
- public void setTypesOfLocals(StackMapType[] t) { types_of_locals = t; }
- public StackMapType[] getTypesOfLocals() { return types_of_locals; }
- public void setNumberOfStackItems(int n) { number_of_stack_items = n; }
- public int getNumberOfStackItems() { return number_of_stack_items; }
- public void setTypesOfStackItems(StackMapType[] t) { types_of_stack_items = t; }
- public StackMapType[] getTypesOfStackItems() { return types_of_stack_items; }
-
- /**
- * @return deep copy of this object
- */
- public StackMapEntry copy() {
- try {
- return (StackMapEntry)clone();
- } catch(CloneNotSupportedException e) {}
-
- return null;
- }
-
- /**
- * Called by objects that are traversing the nodes of the tree implicitely
- * defined by the contents of a Java class. I.e., the hierarchy of methods,
- * fields, attributes, etc. spawns a tree of objects.
- *
- * @param v Visitor object
- */
- public void accept(Visitor v) {
- v.visitStackMapEntry(this);
- }
-
- /**
- * @return Constant pool used by this object.
- */
- public final ConstantPool getConstantPool() { return constant_pool; }
-
- /**
- * @param constant_pool Constant pool to be used for this object.
- */
- public final void setConstantPool(ConstantPool constant_pool) {
- this.constant_pool = constant_pool;
- }
+
+ private int byte_code_offset;
+ private int number_of_locals;
+ private StackMapType[] types_of_locals;
+ private int number_of_stack_items;
+ private StackMapType[] types_of_stack_items;
+ private ConstantPool constant_pool;
+
+
+ /**
+ * Construct object from file stream.
+ * @param file Input stream
+ * @throws IOException
+ */
+ StackMapEntry(DataInputStream file, ConstantPool constant_pool) throws IOException {
+ this(file.readShort(), file.readShort(), null, -1, null, constant_pool);
+ types_of_locals = new StackMapType[number_of_locals];
+ for (int i = 0; i < number_of_locals; i++) {
+ types_of_locals[i] = new StackMapType(file, constant_pool);
+ }
+ number_of_stack_items = file.readShort();
+ types_of_stack_items = new StackMapType[number_of_stack_items];
+ for (int i = 0; i < number_of_stack_items; i++) {
+ types_of_stack_items[i] = new StackMapType(file, constant_pool);
+ }
+ }
+
+
+ public StackMapEntry(int byte_code_offset, int number_of_locals,
+ StackMapType[] types_of_locals, int number_of_stack_items,
+ StackMapType[] types_of_stack_items, ConstantPool constant_pool) {
+ this.byte_code_offset = byte_code_offset;
+ this.number_of_locals = number_of_locals;
+ this.types_of_locals = types_of_locals;
+ this.number_of_stack_items = number_of_stack_items;
+ this.types_of_stack_items = types_of_stack_items;
+ this.constant_pool = constant_pool;
+ }
+
+
+ /**
+ * Dump stack map entry
+ *
+ * @param file Output file stream
+ * @throws IOException
+ */
+ public final void dump( DataOutputStream file ) throws IOException {
+ file.writeShort(byte_code_offset);
+ file.writeShort(number_of_locals);
+ for (int i = 0; i < number_of_locals; i++) {
+ types_of_locals[i].dump(file);
+ }
+ file.writeShort(number_of_stack_items);
+ for (int i = 0; i < number_of_stack_items; i++) {
+ types_of_stack_items[i].dump(file);
+ }
+ }
+
+
+ /**
+ * @return String representation.
+ */
+ public final String toString() {
+ StringBuffer buf = new StringBuffer(64);
+ buf.append("(offset=").append(byte_code_offset);
+ if (number_of_locals > 0) {
+ buf.append(", locals={");
+ for (int i = 0; i < number_of_locals; i++) {
+ buf.append(types_of_locals[i]);
+ if (i < number_of_locals - 1) {
+ buf.append(", ");
+ }
+ }
+ buf.append("}");
+ }
+ if (number_of_stack_items > 0) {
+ buf.append(", stack items={");
+ for (int i = 0; i < number_of_stack_items; i++) {
+ buf.append(types_of_stack_items[i]);
+ if (i < number_of_stack_items - 1) {
+ buf.append(", ");
+ }
+ }
+ buf.append("}");
+ }
+ buf.append(")");
+ return buf.toString();
+ }
+
+
+ public void setByteCodeOffset( int b ) {
+ byte_code_offset = b;
+ }
+
+
+ public int getByteCodeOffset() {
+ return byte_code_offset;
+ }
+
+
+ public void setNumberOfLocals( int n ) {
+ number_of_locals = n;
+ }
+
+
+ public int getNumberOfLocals() {
+ return number_of_locals;
+ }
+
+
+ public void setTypesOfLocals( StackMapType[] t ) {
+ types_of_locals = t;
+ }
+
+
+ public StackMapType[] getTypesOfLocals() {
+ return types_of_locals;
+ }
+
+
+ public void setNumberOfStackItems( int n ) {
+ number_of_stack_items = n;
+ }
+
+
+ public int getNumberOfStackItems() {
+ return number_of_stack_items;
+ }
+
+
+ public void setTypesOfStackItems( StackMapType[] t ) {
+ types_of_stack_items = t;
+ }
+
+
+ public StackMapType[] getTypesOfStackItems() {
+ return types_of_stack_items;
+ }
+
+
+ /**
+ * @return deep copy of this object
+ */
+ public StackMapEntry copy() {
+ try {
+ return (StackMapEntry) clone();
+ } catch (CloneNotSupportedException e) {
+ }
+ return null;
+ }
+
+
+ /**
+ * Called by objects that are traversing the nodes of the tree implicitely
+ * defined by the contents of a Java class. I.e., the hierarchy of methods,
+ * fields, attributes, etc. spawns a tree of objects.
+ *
+ * @param v Visitor object
+ */
+ public void accept( Visitor v ) {
+ v.visitStackMapEntry(this);
+ }
+
+
+ /**
+ * @return Constant pool used by this object.
+ */
+ public final ConstantPool getConstantPool() {
+ return constant_pool;
+ }
+
+
+ /**
+ * @param constant_pool Constant pool to be used for this object.
+ */
+ public final void setConstantPool( ConstantPool constant_pool ) {
+ this.constant_pool = constant_pool;
+ }
}
Modified: jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/StackMapType.java
URL: http://svn.apache.org/viewcvs/jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/StackMapType.java?rev=386056&r1=386055&r2=386056&view=diff
==============================================================================
--- jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/StackMapType.java (original)
+++ jakarta/bcel/trunk/src/java/org/apache/bcel/classfile/StackMapType.java Wed Mar 15 03:31:56 2006
@@ -13,10 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
- */
+ */
package org.apache.bcel.classfile;
-
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@@ -33,107 +32,130 @@
* @see Constants
*/
public final class StackMapType implements Cloneable {
- private byte type;
- private int index = -1; // Index to CONSTANT_Class or offset
- private ConstantPool constant_pool;
-
- /**
- * Construct object from file stream.
- * @param file Input stream
- * @throws IOException
- */
- StackMapType(DataInputStream file, ConstantPool constant_pool) throws IOException
- {
- this(file.readByte(), -1, constant_pool);
-
- if(hasIndex())
- setIndex(file.readShort());
-
- setConstantPool(constant_pool);
- }
-
- /**
- * @param type type tag as defined in the Constants interface
- * @param index index to constant pool, or byte code offset
- */
- public StackMapType(byte type, int index, ConstantPool constant_pool) {
- setType(type);
- setIndex(index);
- setConstantPool(constant_pool);
- }
-
- public void setType(byte t) {
- if((t < Constants.ITEM_Bogus) || (t > Constants.ITEM_NewObject))
- throw new RuntimeException("Illegal type for StackMapType: " + t);
- type = t;
- }
-
- public byte getType() { return type; }
- public void setIndex(int t) { index = t; }
-
- /** @return index to constant pool if type == ITEM_Object, or offset
- * in byte code, if type == ITEM_NewObject, and -1 otherwise
- */
- public int getIndex() { return index; }
-
- /**
- * Dump type entries to file.
- *
- * @param file Output file stream
- * @throws IOException
- */
- public final void dump(DataOutputStream file) throws IOException
- {
- file.writeByte(type);
- if(hasIndex())
- file.writeShort(getIndex());
- }
-
- /** @return true, if type is either ITEM_Object or ITEM_NewObject
- */
- public final boolean hasIndex() {
- return ((type == Constants.ITEM_Object) ||
- (type == Constants.ITEM_NewObject));
- }
-
- private String printIndex() {
- if(type == Constants.ITEM_Object) {
- if (index < 0)
- return ", class=<unknown>";
- return ", class=" + constant_pool.constantToString(index, Constants.CONSTANT_Class);
- } else if(type == Constants.ITEM_NewObject)
- return ", offset=" + index;
- else
- return "";
- }
-
- /**
- * @return String representation
- */
- public final String toString() {
- return "(type=" + Constants.ITEM_NAMES[type] + printIndex() + ")";
- }
-
- /**
- * @return deep copy of this object
- */
- public StackMapType copy() {
- try {
- return (StackMapType)clone();
- } catch(CloneNotSupportedException e) {}
-
- return null;
- }
-
- /**
- * @return Constant pool used by this object.
- */
- public final ConstantPool getConstantPool() { return constant_pool; }
-
- /**
- * @param constant_pool Constant pool to be used for this object.
- */
- public final void setConstantPool(ConstantPool constant_pool) {
- this.constant_pool = constant_pool;
- }
+
+ private byte type;
+ private int index = -1; // Index to CONSTANT_Class or offset
+ private ConstantPool constant_pool;
+
+
+ /**
+ * Construct object from file stream.
+ * @param file Input stream
+ * @throws IOException
+ */
+ StackMapType(DataInputStream file, ConstantPool constant_pool) throws IOException {
+ this(file.readByte(), -1, constant_pool);
+ if (hasIndex()) {
+ setIndex(file.readShort());
+ }
+ setConstantPool(constant_pool);
+ }
+
+
+ /**
+ * @param type type tag as defined in the Constants interface
+ * @param index index to constant pool, or byte code offset
+ */
+ public StackMapType(byte type, int index, ConstantPool constant_pool) {
+ setType(type);
+ setIndex(index);
+ setConstantPool(constant_pool);
+ }
+
+
+ public void setType( byte t ) {
+ if ((t < Constants.ITEM_Bogus) || (t > Constants.ITEM_NewObject)) {
+ throw new RuntimeException("Illegal type for StackMapType: " + t);
+ }
+ type = t;
+ }
+
+
+ public byte getType() {
+ return type;
+ }
+
+
+ public void setIndex( int t ) {
+ index = t;
+ }
+
+
+ /** @return index to constant pool if type == ITEM_Object, or offset
+ * in byte code, if type == ITEM_NewObject, and -1 otherwise
+ */
+ public int getIndex() {
+ return index;
+ }
+
+
+ /**
+ * Dump type entries to file.
+ *
+ * @param file Output file stream
+ * @throws IOException
+ */
+ public final void dump( DataOutputStream file ) throws IOException {
+ file.writeByte(type);
+ if (hasIndex()) {
+ file.writeShort(getIndex());
+ }
+ }
+
+
+ /** @return true, if type is either ITEM_Object or ITEM_NewObject
+ */
+ public final boolean hasIndex() {
+ return ((type == Constants.ITEM_Object) || (type == Constants.ITEM_NewObject));
+ }
+
+
+ private String printIndex() {
+ if (type == Constants.ITEM_Object) {
+ if (index < 0) {
+ return ", class=<unknown>";
+ }
+ return ", class=" + constant_pool.constantToString(index, Constants.CONSTANT_Class);
+ } else if (type == Constants.ITEM_NewObject) {
+ return ", offset=" + index;
+ } else {
+ return "";
+ }
+ }
+
+
+ /**
+ * @return String representation
+ */
+ public final String toString() {
+ return "(type=" + Constants.ITEM_NAMES[type] + printIndex() + ")";
+ }
+
+
+ /**
+ * @return deep copy of this object
+ */
+ public StackMapType copy() {
+ try {
+ return (StackMapType) clone();
+ } catch (CloneNotSupportedException e) {
+ }
+ return null;
+ }
+
+
+ /**
+ * @return Constant pool used by this object.
+ */
+ public final ConstantPool getConstantPool() {
+ return constant_pool;
+ }
+
+
+ /**
+ * @param constant_pool Constant pool to be used for this object.
+ */
+ public final void setConstantPool( ConstantPool constant_pool ) {
+ this.constant_pool = constant_pool;
+ }
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.