Modified: jakarta/bcel/trunk/src/java/org/apache/bcel/generic/LoadInstruction.java URL: http://svn.apache.org/viewcvs/jakarta/bcel/trunk/src/java/org/apache/bcel/generic/LoadInstruction.java?rev=386056&r1=386055&r2=386056&view=diff ============================================================================== --- jakarta/bcel/trunk/src/java/org/apache/bcel/generic/LoadInstruction.java (original) +++ jakarta/bcel/trunk/src/java/org/apache/bcel/generic/LoadInstruction.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.generic; - /** * Denotes an unparameterized instruction to load a value from a local * variable, e.g. ILOAD. @@ -24,41 +23,41 @@ * @version $Id$ * @author <A HREF="mailto:[EMAIL PROTECTED]">M. Dahm</A> */ -public abstract class LoadInstruction extends LocalVariableInstruction - implements PushInstruction -{ - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - * tag and length are defined in readInstruction and initFromFile, respectively. - */ - LoadInstruction(short canon_tag, short c_tag) { - super(canon_tag, c_tag); - } - - /** - * @param opcode Instruction opcode - * @param c_tag Instruction number for compact version, ALOAD_0, e.g. - * @param n local variable index (unsigned short) - */ - protected LoadInstruction(short opcode, short c_tag, int n) { - super(opcode, c_tag, n); - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitStackProducer(this); - v.visitPushInstruction(this); - v.visitTypedInstruction(this); - v.visitLocalVariableInstruction(this); - v.visitLoadInstruction(this); - } -} +public abstract class LoadInstruction extends LocalVariableInstruction implements PushInstruction { + + /** + * Empty constructor needed for the Class.newInstance() statement in + * Instruction.readInstruction(). Not to be used otherwise. + * tag and length are defined in readInstruction and initFromFile, respectively. + */ + LoadInstruction(short canon_tag, short c_tag) { + super(canon_tag, c_tag); + } + + /** + * @param opcode Instruction opcode + * @param c_tag Instruction number for compact version, ALOAD_0, e.g. + * @param n local variable index (unsigned short) + */ + protected LoadInstruction(short opcode, short c_tag, int n) { + super(opcode, c_tag, n); + } + + + /** + * Call corresponding visitor method(s). The order is: + * Call visitor methods of implemented interfaces first, then + * call methods according to the class hierarchy in descending order, + * i.e., the most specific visitXXX() call comes last. + * + * @param v Visitor object + */ + public void accept( Visitor v ) { + v.visitStackProducer(this); + v.visitPushInstruction(this); + v.visitTypedInstruction(this); + v.visitLocalVariableInstruction(this); + v.visitLoadInstruction(this); + } +}
Modified: jakarta/bcel/trunk/src/java/org/apache/bcel/generic/LocalVariableGen.java URL: http://svn.apache.org/viewcvs/jakarta/bcel/trunk/src/java/org/apache/bcel/generic/LocalVariableGen.java?rev=386056&r1=386055&r2=386056&view=diff ============================================================================== --- jakarta/bcel/trunk/src/java/org/apache/bcel/generic/LocalVariableGen.java (original) +++ jakarta/bcel/trunk/src/java/org/apache/bcel/generic/LocalVariableGen.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.generic; - import org.apache.bcel.Constants; import org.apache.bcel.classfile.LocalVariable; @@ -31,144 +30,179 @@ * @see LocalVariable * @see MethodGen */ -public class LocalVariableGen - implements InstructionTargeter, NamedAndTyped, Cloneable, - java.io.Serializable -{ - private int index; - private String name; - private Type type; - private InstructionHandle start, end; - - /** - * Generate a local variable that with index `index'. Note that double and long - * variables need two indexs. Index indices have to be provided by the user. - * - * @param index index of local variable - * @param name its name - * @param type its type - * @param start from where the instruction is valid (null means from the start) - * @param end until where the instruction is valid (null means to the end) - */ - public LocalVariableGen(int index, String name, Type type, - InstructionHandle start, InstructionHandle end) { - if((index < 0) || (index > Constants.MAX_SHORT)) - throw new ClassGenException("Invalid index index: " + index); - - this.name = name; - this.type = type; - this.index = index; - setStart(start); - setEnd(end); - } - - /** - * Get LocalVariable object. - * - * This relies on that the instruction list has already been dumped to byte code or - * or that the `setPositions' methods has been called for the instruction list. - * - * Note that for local variables whose scope end at the last - * instruction of the method's code, the JVM specification is ambiguous: - * both a start_pc+length ending at the last instruction and - * start_pc+length ending at first index beyond the end of the code are - * valid. - * - * @param cp constant pool - */ - public LocalVariable getLocalVariable(ConstantPoolGen cp) { - int start_pc = start.getPosition(); - int length = end.getPosition() - start_pc; - - if(length > 0) - length += end.getInstruction().getLength(); - - int name_index = cp.addUtf8(name); - int signature_index = cp.addUtf8(type.getSignature()); - - return new LocalVariable(start_pc, length, name_index, - signature_index, index, cp.getConstantPool()); - } - - public void setIndex(int index) { this.index = index; } - public int getIndex() { return index; } - public void setName(String name) { this.name = name; } - public String getName() { return name; } - public void setType(Type type) { this.type = type; } - public Type getType() { return type; } - - public InstructionHandle getStart() { return start; } - public InstructionHandle getEnd() { return end; } - - public void setStart(InstructionHandle start) { - BranchInstruction.notifyTarget(this.start, start, this); - this.start = start; - } - - public void setEnd(InstructionHandle end) { - BranchInstruction.notifyTarget(this.end, end, this); - this.end = end; - } - - /** - * @param old_ih old target, either start or end - * @param new_ih new target - */ - public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) { - boolean targeted = false; - - if(start == old_ih) { - targeted = true; - setStart(new_ih); - } - - if(end == old_ih) { - targeted = true; - setEnd(new_ih); - } - - if(!targeted) - throw new ClassGenException("Not targeting " + old_ih + ", but {" + start + ", " + - end + "}"); - } - - /** - * @return true, if ih is target of this variable - */ - public boolean containsTarget(InstructionHandle ih) { - return (start == ih) || (end == ih); - } - - /** @return a hash code value for the object. - */ - public int hashCode() { - //If the user changes the name or type, problems with the targeter hashmap will occur - int hc = index ^ name.hashCode() ^ type.hashCode(); - return hc; - } - - /** - * We consider to local variables to be equal, if the use the same index and - * are valid in the same range. - */ - public boolean equals(Object o) { - if(!(o instanceof LocalVariableGen)) - return false; - - LocalVariableGen l = (LocalVariableGen)o; - return (l.index == index) && (l.start == start) && (l.end == end); - } - - public String toString() { - return "LocalVariableGen(" + name + ", " + type + ", " + start + ", " + end + ")"; - } - - public Object clone() { - try { - return super.clone(); - } catch(CloneNotSupportedException e) { - System.err.println(e); - return null; +public class LocalVariableGen implements InstructionTargeter, NamedAndTyped, Cloneable, + java.io.Serializable { + + private int index; + private String name; + private Type type; + private InstructionHandle start, end; + + + /** + * Generate a local variable that with index `index'. Note that double and long + * variables need two indexs. Index indices have to be provided by the user. + * + * @param index index of local variable + * @param name its name + * @param type its type + * @param start from where the instruction is valid (null means from the start) + * @param end until where the instruction is valid (null means to the end) + */ + public LocalVariableGen(int index, String name, Type type, InstructionHandle start, + InstructionHandle end) { + if ((index < 0) || (index > Constants.MAX_SHORT)) { + throw new ClassGenException("Invalid index index: " + index); + } + this.name = name; + this.type = type; + this.index = index; + setStart(start); + setEnd(end); + } + + + /** + * Get LocalVariable object. + * + * This relies on that the instruction list has already been dumped to byte code or + * or that the `setPositions' methods has been called for the instruction list. + * + * Note that for local variables whose scope end at the last + * instruction of the method's code, the JVM specification is ambiguous: + * both a start_pc+length ending at the last instruction and + * start_pc+length ending at first index beyond the end of the code are + * valid. + * + * @param cp constant pool + */ + public LocalVariable getLocalVariable( ConstantPoolGen cp ) { + int start_pc = start.getPosition(); + int length = end.getPosition() - start_pc; + if (length > 0) { + length += end.getInstruction().getLength(); + } + int name_index = cp.addUtf8(name); + int signature_index = cp.addUtf8(type.getSignature()); + return new LocalVariable(start_pc, length, name_index, signature_index, index, cp + .getConstantPool()); + } + + + public void setIndex( int index ) { + this.index = index; + } + + + public int getIndex() { + return index; + } + + + public void setName( String name ) { + this.name = name; + } + + + public String getName() { + return name; + } + + + public void setType( Type type ) { + this.type = type; + } + + + public Type getType() { + return type; + } + + + public InstructionHandle getStart() { + return start; + } + + + public InstructionHandle getEnd() { + return end; + } + + + public void setStart( InstructionHandle start ) { + BranchInstruction.notifyTarget(this.start, start, this); + this.start = start; + } + + + public void setEnd( InstructionHandle end ) { + BranchInstruction.notifyTarget(this.end, end, this); + this.end = end; + } + + + /** + * @param old_ih old target, either start or end + * @param new_ih new target + */ + public void updateTarget( InstructionHandle old_ih, InstructionHandle new_ih ) { + boolean targeted = false; + if (start == old_ih) { + targeted = true; + setStart(new_ih); + } + if (end == old_ih) { + targeted = true; + setEnd(new_ih); + } + if (!targeted) { + throw new ClassGenException("Not targeting " + old_ih + ", but {" + start + ", " + end + + "}"); + } + } + + + /** + * @return true, if ih is target of this variable + */ + public boolean containsTarget( InstructionHandle ih ) { + return (start == ih) || (end == ih); + } + + + /** @return a hash code value for the object. + */ + public int hashCode() { + //If the user changes the name or type, problems with the targeter hashmap will occur + int hc = index ^ name.hashCode() ^ type.hashCode(); + return hc; + } + + + /** + * We consider to local variables to be equal, if the use the same index and + * are valid in the same range. + */ + public boolean equals( Object o ) { + if (!(o instanceof LocalVariableGen)) { + return false; + } + LocalVariableGen l = (LocalVariableGen) o; + return (l.index == index) && (l.start == start) && (l.end == end); + } + + + public String toString() { + return "LocalVariableGen(" + name + ", " + type + ", " + start + ", " + end + ")"; + } + + + public Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException e) { + System.err.println(e); + return null; + } } - } } Modified: jakarta/bcel/trunk/src/java/org/apache/bcel/generic/LocalVariableInstruction.java URL: http://svn.apache.org/viewcvs/jakarta/bcel/trunk/src/java/org/apache/bcel/generic/LocalVariableInstruction.java?rev=386056&r1=386055&r2=386056&view=diff ============================================================================== --- jakarta/bcel/trunk/src/java/org/apache/bcel/generic/LocalVariableInstruction.java (original) +++ jakarta/bcel/trunk/src/java/org/apache/bcel/generic/LocalVariableInstruction.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.generic; import java.io.DataOutputStream; @@ -27,163 +27,176 @@ * @version $Id$ * @author <A HREF="mailto:[EMAIL PROTECTED]">M. Dahm</A> */ -public abstract class LocalVariableInstruction extends Instruction - implements TypedInstruction, IndexedInstruction { - protected int n = -1; // index of referenced variable - private short c_tag = -1; // compact version, such as ILOAD_0 - private short canon_tag = -1; // canonical tag such as ILOAD - - private final boolean wide() { return n > Constants.MAX_BYTE; } - - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - * tag and length are defined in readInstruction and initFromFile, respectively. - */ - LocalVariableInstruction(short canon_tag, short c_tag) { - super(); - this.canon_tag = canon_tag; - this.c_tag = c_tag; - } - - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Also used by IINC()! - */ - LocalVariableInstruction() { - } - - /** - * @param opcode Instruction opcode - * @param c_tag Instruction number for compact version, ALOAD_0, e.g. - * @param n local variable index (unsigned short) - */ - protected LocalVariableInstruction(short opcode, short c_tag, int n) { - super(opcode, (short)2); - - this.c_tag = c_tag; - canon_tag = opcode; - - setIndex(n); - } - - /** - * Dump instruction as byte code to stream out. - * @param out Output stream - */ - public void dump(DataOutputStream out) throws IOException { - if(wide()) // Need WIDE prefix ? - out.writeByte(Constants.WIDE); - - out.writeByte(opcode); - - if(length > 1) { // Otherwise ILOAD_n, instruction, e.g. - if(wide()) - out.writeShort(n); - else - out.writeByte(n); - } - } - - /** - * Long output format: - * - * <name of opcode> "["<opcode number>"]" - * "("<length of instruction>")" "<"< local variable index>">" - * - * @param verbose long/short format switch - * @return mnemonic for instruction - */ - public String toString(boolean verbose) { - if(((opcode >= Constants.ILOAD_0) && - (opcode <= Constants.ALOAD_3)) || - ((opcode >= Constants.ISTORE_0) && - (opcode <= Constants.ASTORE_3))) - return super.toString(verbose); - else - return super.toString(verbose) + " " + n; - } - - /** - * Read needed data (e.g. index) from file. - * PRE: (ILOAD <= tag <= ALOAD_3) || (ISTORE <= tag <= ASTORE_3) - */ - protected void initFromFile(ByteSequence bytes, boolean wide) - throws IOException - { - if(wide) { - n = bytes.readUnsignedShort(); - length = 4; - } else if(((opcode >= Constants.ILOAD) && - (opcode <= Constants.ALOAD)) || - ((opcode >= Constants.ISTORE) && - (opcode <= Constants.ASTORE))) { - n = bytes.readUnsignedByte(); - length = 2; - } else if(opcode <= Constants.ALOAD_3) { // compact load instruction such as ILOAD_2 - n = (opcode - Constants.ILOAD_0) % 4; - length = 1; - } else { // Assert ISTORE_0 <= tag <= ASTORE_3 - n = (opcode - Constants.ISTORE_0) % 4; - length = 1; - } - } - - /** - * @return local variable index referred by this instruction. - */ - public final int getIndex() { return n; } - - /** - * Set the local variable index - */ - public void setIndex(int n) { - if((n < 0) || (n > Constants.MAX_SHORT)) - throw new ClassGenException("Illegal value: " + n); - - this.n = n; - - if(n >= 0 && n <= 3) { // Use more compact instruction xLOAD_n - opcode = (short)(c_tag + n); - length = 1; - } else { - opcode = canon_tag; - - if(wide()) // Need WIDE prefix ? - length = 4; - else - length = 2; - } - } - - /** @return canonical tag for instruction, e.g., ALOAD for ALOAD_0 - */ - public short getCanonicalTag() { - return canon_tag; - } - - /** - * Returns the type associated with the instruction - - * in case of ALOAD or ASTORE Type.OBJECT is returned. - * This is just a bit incorrect, because ALOAD and ASTORE - * may work on every ReferenceType (including Type.NULL) and - * ASTORE may even work on a ReturnaddressType . - * @return type associated with the instruction - */ - public Type getType(ConstantPoolGen cp) { - switch(canon_tag) { - case Constants.ILOAD: case Constants.ISTORE: - return Type.INT; - case Constants.LLOAD: case Constants.LSTORE: - return Type.LONG; - case Constants.DLOAD: case Constants.DSTORE: - return Type.DOUBLE; - case Constants.FLOAD: case Constants.FSTORE: - return Type.FLOAT; - case Constants.ALOAD: case Constants.ASTORE: - return Type.OBJECT; +public abstract class LocalVariableInstruction extends Instruction implements TypedInstruction, + IndexedInstruction { + + protected int n = -1; // index of referenced variable + private short c_tag = -1; // compact version, such as ILOAD_0 + private short canon_tag = -1; // canonical tag such as ILOAD + + + private final boolean wide() { + return n > Constants.MAX_BYTE; + } + + + /** + * Empty constructor needed for the Class.newInstance() statement in + * Instruction.readInstruction(). Not to be used otherwise. + * tag and length are defined in readInstruction and initFromFile, respectively. + */ + LocalVariableInstruction(short canon_tag, short c_tag) { + super(); + this.canon_tag = canon_tag; + this.c_tag = c_tag; + } + + + /** + * Empty constructor needed for the Class.newInstance() statement in + * Instruction.readInstruction(). Also used by IINC()! + */ + LocalVariableInstruction() { + } + + + /** + * @param opcode Instruction opcode + * @param c_tag Instruction number for compact version, ALOAD_0, e.g. + * @param n local variable index (unsigned short) + */ + protected LocalVariableInstruction(short opcode, short c_tag, int n) { + super(opcode, (short) 2); + this.c_tag = c_tag; + canon_tag = opcode; + setIndex(n); + } + + + /** + * Dump instruction as byte code to stream out. + * @param out Output stream + */ + public void dump( DataOutputStream out ) throws IOException { + if (wide()) { + out.writeByte(Constants.WIDE); + } + out.writeByte(opcode); + if (length > 1) { // Otherwise ILOAD_n, instruction, e.g. + if (wide()) { + out.writeShort(n); + } else { + out.writeByte(n); + } + } + } + + + /** + * Long output format: + * + * <name of opcode> "["<opcode number>"]" + * "("<length of instruction>")" "<"< local variable index>">" + * + * @param verbose long/short format switch + * @return mnemonic for instruction + */ + public String toString( boolean verbose ) { + if (((opcode >= Constants.ILOAD_0) && (opcode <= Constants.ALOAD_3)) + || ((opcode >= Constants.ISTORE_0) && (opcode <= Constants.ASTORE_3))) { + return super.toString(verbose); + } else { + return super.toString(verbose) + " " + n; + } + } + + + /** + * Read needed data (e.g. index) from file. + * PRE: (ILOAD <= tag <= ALOAD_3) || (ISTORE <= tag <= ASTORE_3) + */ + protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException { + if (wide) { + n = bytes.readUnsignedShort(); + length = 4; + } else if (((opcode >= Constants.ILOAD) && (opcode <= Constants.ALOAD)) + || ((opcode >= Constants.ISTORE) && (opcode <= Constants.ASTORE))) { + n = bytes.readUnsignedByte(); + length = 2; + } else if (opcode <= Constants.ALOAD_3) { // compact load instruction such as ILOAD_2 + n = (opcode - Constants.ILOAD_0) % 4; + length = 1; + } else { // Assert ISTORE_0 <= tag <= ASTORE_3 + n = (opcode - Constants.ISTORE_0) % 4; + length = 1; + } + } + + + /** + * @return local variable index referred by this instruction. + */ + public final int getIndex() { + return n; + } + + + /** + * Set the local variable index + */ + public void setIndex( int n ) { + if ((n < 0) || (n > Constants.MAX_SHORT)) { + throw new ClassGenException("Illegal value: " + n); + } + this.n = n; + if (n >= 0 && n <= 3) { // Use more compact instruction xLOAD_n + opcode = (short) (c_tag + n); + length = 1; + } else { + opcode = canon_tag; + if (wide()) { + length = 4; + } else { + length = 2; + } + } + } + + + /** @return canonical tag for instruction, e.g., ALOAD for ALOAD_0 + */ + public short getCanonicalTag() { + return canon_tag; + } + - default: throw new ClassGenException("Oops: unknown case in switch" + canon_tag); + /** + * Returns the type associated with the instruction - + * in case of ALOAD or ASTORE Type.OBJECT is returned. + * This is just a bit incorrect, because ALOAD and ASTORE + * may work on every ReferenceType (including Type.NULL) and + * ASTORE may even work on a ReturnaddressType . + * @return type associated with the instruction + */ + public Type getType( ConstantPoolGen cp ) { + switch (canon_tag) { + case Constants.ILOAD: + case Constants.ISTORE: + return Type.INT; + case Constants.LLOAD: + case Constants.LSTORE: + return Type.LONG; + case Constants.DLOAD: + case Constants.DSTORE: + return Type.DOUBLE; + case Constants.FLOAD: + case Constants.FSTORE: + return Type.FLOAT; + case Constants.ALOAD: + case Constants.ASTORE: + return Type.OBJECT; + default: + throw new ClassGenException("Oops: unknown case in switch" + canon_tag); + } } - } } Modified: jakarta/bcel/trunk/src/java/org/apache/bcel/generic/MONITORENTER.java URL: http://svn.apache.org/viewcvs/jakarta/bcel/trunk/src/java/org/apache/bcel/generic/MONITORENTER.java?rev=386056&r1=386055&r2=386056&view=diff ============================================================================== --- jakarta/bcel/trunk/src/java/org/apache/bcel/generic/MONITORENTER.java (original) +++ jakarta/bcel/trunk/src/java/org/apache/bcel/generic/MONITORENTER.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.generic; - /** * MONITORENTER - Enter monitor for object * <PRE>Stack: ..., objectref -> ...</PRE> @@ -24,28 +23,31 @@ * @version $Id$ * @author <A HREF="mailto:[EMAIL PROTECTED]">M. Dahm</A> */ -public class MONITORENTER extends Instruction - implements ExceptionThrower, StackConsumer { - public MONITORENTER() { - super(org.apache.bcel.Constants.MONITORENTER, (short)1); - } - - public Class[] getExceptions() { - return new Class[] { org.apache.bcel.ExceptionConstants.NULL_POINTER_EXCEPTION }; - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitExceptionThrower(this); - v.visitStackConsumer(this); - v.visitMONITORENTER(this); - } +public class MONITORENTER extends Instruction implements ExceptionThrower, StackConsumer { + + public MONITORENTER() { + super(org.apache.bcel.Constants.MONITORENTER, (short) 1); + } + + + public Class[] getExceptions() { + return new Class[] { + org.apache.bcel.ExceptionConstants.NULL_POINTER_EXCEPTION + }; + } + + + /** + * Call corresponding visitor method(s). The order is: + * Call visitor methods of implemented interfaces first, then + * call methods according to the class hierarchy in descending order, + * i.e., the most specific visitXXX() call comes last. + * + * @param v Visitor object + */ + public void accept( Visitor v ) { + v.visitExceptionThrower(this); + v.visitStackConsumer(this); + v.visitMONITORENTER(this); + } } Modified: jakarta/bcel/trunk/src/java/org/apache/bcel/generic/MONITOREXIT.java URL: http://svn.apache.org/viewcvs/jakarta/bcel/trunk/src/java/org/apache/bcel/generic/MONITOREXIT.java?rev=386056&r1=386055&r2=386056&view=diff ============================================================================== --- jakarta/bcel/trunk/src/java/org/apache/bcel/generic/MONITOREXIT.java (original) +++ jakarta/bcel/trunk/src/java/org/apache/bcel/generic/MONITOREXIT.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.generic; - /** * MONITOREXIT - Exit monitor for object * <PRE>Stack: ..., objectref -> ...</PRE> @@ -24,28 +23,31 @@ * @version $Id$ * @author <A HREF="mailto:[EMAIL PROTECTED]">M. Dahm</A> */ -public class MONITOREXIT extends Instruction - implements ExceptionThrower, StackConsumer { - public MONITOREXIT() { - super(org.apache.bcel.Constants.MONITOREXIT, (short)1); - } - - public Class[] getExceptions() { - return new Class[] { org.apache.bcel.ExceptionConstants.NULL_POINTER_EXCEPTION }; - } - - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitExceptionThrower(this); - v.visitStackConsumer(this); - v.visitMONITOREXIT(this); - } +public class MONITOREXIT extends Instruction implements ExceptionThrower, StackConsumer { + + public MONITOREXIT() { + super(org.apache.bcel.Constants.MONITOREXIT, (short) 1); + } + + + public Class[] getExceptions() { + return new Class[] { + org.apache.bcel.ExceptionConstants.NULL_POINTER_EXCEPTION + }; + } + + + /** + * Call corresponding visitor method(s). The order is: + * Call visitor methods of implemented interfaces first, then + * call methods according to the class hierarchy in descending order, + * i.e., the most specific visitXXX() call comes last. + * + * @param v Visitor object + */ + public void accept( Visitor v ) { + v.visitExceptionThrower(this); + v.visitStackConsumer(this); + v.visitMONITOREXIT(this); + } } Modified: jakarta/bcel/trunk/src/java/org/apache/bcel/generic/MULTIANEWARRAY.java URL: http://svn.apache.org/viewcvs/jakarta/bcel/trunk/src/java/org/apache/bcel/generic/MULTIANEWARRAY.java?rev=386056&r1=386055&r2=386056&view=diff ============================================================================== --- jakarta/bcel/trunk/src/java/org/apache/bcel/generic/MULTIANEWARRAY.java (original) +++ jakarta/bcel/trunk/src/java/org/apache/bcel/generic/MULTIANEWARRAY.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.generic; import java.io.DataOutputStream; @@ -29,108 +29,118 @@ * @version $Id$ * @author <A HREF="mailto:[EMAIL PROTECTED]">M. Dahm</A> */ -public class MULTIANEWARRAY extends CPInstruction implements LoadClass, AllocationInstruction, ExceptionThrower { - private short dimensions; +public class MULTIANEWARRAY extends CPInstruction implements LoadClass, AllocationInstruction, + ExceptionThrower { + + private short dimensions; + + + /** + * Empty constructor needed for the Class.newInstance() statement in + * Instruction.readInstruction(). Not to be used otherwise. + */ + MULTIANEWARRAY() { + } + + + public MULTIANEWARRAY(int index, short dimensions) { + super(org.apache.bcel.Constants.MULTIANEWARRAY, index); + if (dimensions < 1) { + throw new ClassGenException("Invalid dimensions value: " + dimensions); + } + this.dimensions = dimensions; + length = 4; + } + + + /** + * Dump instruction as byte code to stream out. + * @param out Output stream + */ + public void dump( DataOutputStream out ) throws IOException { + out.writeByte(opcode); + out.writeShort(index); + out.writeByte(dimensions); + } + + + /** + * Read needed data (i.e., no. dimension) from file. + */ + protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException { + super.initFromFile(bytes, wide); + dimensions = bytes.readByte(); + length = 4; + } + + + /** + * @return number of dimensions to be created + */ + public final short getDimensions() { + return dimensions; + } - /** - * Empty constructor needed for the Class.newInstance() statement in - * Instruction.readInstruction(). Not to be used otherwise. - */ - MULTIANEWARRAY() {} - - public MULTIANEWARRAY(int index, short dimensions) { - super(org.apache.bcel.Constants.MULTIANEWARRAY, index); - - if(dimensions < 1) - throw new ClassGenException("Invalid dimensions value: " + dimensions); - - this.dimensions = dimensions; - length = 4; - } - - /** - * Dump instruction as byte code to stream out. - * @param out Output stream - */ - public void dump(DataOutputStream out) throws IOException { - out.writeByte(opcode); - out.writeShort(index); - out.writeByte(dimensions); - } - - /** - * Read needed data (i.e., no. dimension) from file. - */ - protected void initFromFile(ByteSequence bytes, boolean wide) - throws IOException - { - super.initFromFile(bytes, wide); - dimensions = bytes.readByte(); - length = 4; - } - - /** - * @return number of dimensions to be created - */ - public final short getDimensions() { return dimensions; } - - /** - * @return mnemonic for instruction - */ - public String toString(boolean verbose) { - return super.toString(verbose) + " " + index + " " + dimensions; - } - - /** - * @return mnemonic for instruction with symbolic references resolved - */ - public String toString(ConstantPool cp) { - return super.toString(cp) + " " + dimensions; - } - - /** - * Also works for instructions whose stack effect depends on the - * constant pool entry they reference. - * @return Number of words consumed from stack by this instruction - */ - public int consumeStack(ConstantPoolGen cpg) { return dimensions; } - - public Class[] getExceptions() { - Class[] cs = new Class[2 + ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length]; - - System.arraycopy(ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION, 0, - cs, 0, ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length); - - cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length+1] = ExceptionConstants.NEGATIVE_ARRAY_SIZE_EXCEPTION; - cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length] = ExceptionConstants.ILLEGAL_ACCESS_ERROR; - - return cs; - } - - public ObjectType getLoadClassType(ConstantPoolGen cpg) { - Type t = getType(cpg); - - if (t instanceof ArrayType){ - t = ((ArrayType) t).getBasicType(); - } - - return (t instanceof ObjectType)? (ObjectType) t : null; - } - - /** - * Call corresponding visitor method(s). The order is: - * Call visitor methods of implemented interfaces first, then - * call methods according to the class hierarchy in descending order, - * i.e., the most specific visitXXX() call comes last. - * - * @param v Visitor object - */ - public void accept(Visitor v) { - v.visitLoadClass(this); - v.visitAllocationInstruction(this); - v.visitExceptionThrower(this); - v.visitTypedInstruction(this); - v.visitCPInstruction(this); - v.visitMULTIANEWARRAY(this); - } + + /** + * @return mnemonic for instruction + */ + public String toString( boolean verbose ) { + return super.toString(verbose) + " " + index + " " + dimensions; + } + + + /** + * @return mnemonic for instruction with symbolic references resolved + */ + public String toString( ConstantPool cp ) { + return super.toString(cp) + " " + dimensions; + } + + + /** + * Also works for instructions whose stack effect depends on the + * constant pool entry they reference. + * @return Number of words consumed from stack by this instruction + */ + public int consumeStack( ConstantPoolGen cpg ) { + return dimensions; + } + + + public Class[] getExceptions() { + Class[] cs = new Class[2 + ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length]; + System.arraycopy(ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION, 0, cs, 0, + ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length); + cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length + 1] = ExceptionConstants.NEGATIVE_ARRAY_SIZE_EXCEPTION; + cs[ExceptionConstants.EXCS_CLASS_AND_INTERFACE_RESOLUTION.length] = ExceptionConstants.ILLEGAL_ACCESS_ERROR; + return cs; + } + + + public ObjectType getLoadClassType( ConstantPoolGen cpg ) { + Type t = getType(cpg); + if (t instanceof ArrayType) { + t = ((ArrayType) t).getBasicType(); + } + return (t instanceof ObjectType) ? (ObjectType) t : null; + } + + + /** + * Call corresponding visitor method(s). The order is: + * Call visitor methods of implemented interfaces first, then + * call methods according to the class hierarchy in descending order, + * i.e., the most specific visitXXX() call comes last. + * + * @param v Visitor object + */ + public void accept( Visitor v ) { + v.visitLoadClass(this); + v.visitAllocationInstruction(this); + v.visitExceptionThrower(this); + v.visitTypedInstruction(this); + v.visitCPInstruction(this); + v.visitMULTIANEWARRAY(this); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]