fr.umlv.corosol.classfile.bytecode.impl
Class DefaultJBytecodeParser

java.lang.Object
  extended by fr.umlv.corosol.classfile.bytecode.impl.DefaultJBytecodeParser
All Implemented Interfaces:
JBytecodeParser

public class DefaultJBytecodeParser
extends java.lang.Object
implements JBytecodeParser

The default implementation of the bytecode parser JBytecodeParser.

Author:
Christophe Deleray

Field Summary
 
Fields inherited from interface fr.umlv.corosol.classfile.bytecode.JBytecodeParser
AALOAD, AASTORE, ACONST_NULL, ALOAD, ALOAD_0, ALOAD_1, ALOAD_2, ALOAD_3, ANEWARRAY, ARETURN, ARRAYLENGTH, ASTORE, ASTORE_0, ASTORE_1, ASTORE_2, ASTORE_3, ATHROW, BALOAD, BASTORE, BIPUSH, CALOAD, CASTORE, CHECKCAST, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DLOAD_0, DLOAD_1, DLOAD_2, DLOAD_3, DMUL, DNEG, DREM, DRETURN, DSTORE, DSTORE_0, DSTORE_1, DSTORE_2, DSTORE_3, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FLOAD_0, FLOAD_1, FLOAD_2, FLOAD_3, FMUL, FNEG, FREM, FRETURN, FSTORE, FSTORE_0, FSTORE_1, FSTORE_2, FSTORE_3, FSUB, GETFIELD, GETSTATIC, GOTO, GOTO_W, I2B, I2C, I2D, I2F, I2L, I2S, IADD, IALOAD, IAND, IASTORE, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5, ICONST_M1, IDIV, IF_ACMPEQ, IF_ACMPNE, IF_ICMPEQ, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ICMPLT, IF_ICMPNE, IFEQ, IFGE, IFGT, IFLE, IFLT, IFNE, IFNONNULL, IFNULL, IINC, ILOAD, ILOAD_0, ILOAD_1, ILOAD_2, ILOAD_3, IMUL, INEG, INSTANCEOF, INVOKEINTERFACE, INVOKESPECIAL, INVOKESTATIC, INVOKEVIRTUAL, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISTORE_0, ISTORE_1, ISTORE_2, ISTORE_3, ISUB, IUSHR, IXOR, JSR, JSR_W, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDC, LDC_W, LDC2_W, LDIV, LLOAD, LLOAD_0, LLOAD_1, LLOAD_2, LLOAD_3, LMUL, LNEG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSTORE_0, LSTORE_1, LSTORE_2, LSTORE_3, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, POP, POP2, PUTFIELD, PUTSTATIC, RET, RETURN, SALOAD, SASTORE, SIPUSH, SWAP, TABLESWITCH, WIDE
 
Constructor Summary
DefaultJBytecodeParser()
          Creates a new bytecode parser not initialized with a bytecode array.
 
Method Summary
 void fillInput(byte[] b, int off, int len)
          Resets the bytecode parsing and initializes it with the len bytes of the specified bytes array, starting at the off position.
 java.lang.String getMnemonic()
          Returns the mnemonic of the next instruction opcode read from this bytecode parser.
 int getOpcodeCount()
          Calculates the number of times that this bytecode parser's nextOpcode method can be called before it generates an exception.
 int getOperandCount()
          Returns the number of operands of the current instruction read with the nextOpcode method.
 int getPosition()
          Returns the current opcode position in the bytecodes flow.
 boolean hasMoreOpcode()
          Tests if there are more instruction opcode available from this bytecode parser.
 int nextOpcode()
          Returns the next instruction opcode from this bytecode parser.
 int readOperands(byte[] b, int off, int len)
          Reads up to len operand of the current instruction, read with the nextOpcode method, into an array of bytes.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultJBytecodeParser

public DefaultJBytecodeParser()
Creates a new bytecode parser not initialized with a bytecode array.

Method Detail

hasMoreOpcode

public boolean hasMoreOpcode()
Tests if there are more instruction opcode available from this bytecode parser. If this method returns true, then a subsequent call to nextOpcode with no argument will successfully return an instruction opcode.

Specified by:
hasMoreOpcode in interface JBytecodeParser
Returns:
true if and only if there is at least one opcode in the bytecode after the current position; false otherwise.

nextOpcode

public int nextOpcode()
Returns the next instruction opcode from this bytecode parser. If this instruction has operands, they can be read with the readOperands method.

Specified by:
nextOpcode in interface JBytecodeParser
Returns:
the next instruction opcode from this bytecode parser
Throws:
java.util.NoSuchElementException - if there are no more instruction opcode in this bytecode parser
See Also:
readOperands(byte[], int, int)

getMnemonic

public java.lang.String getMnemonic()
Returns the mnemonic of the next instruction opcode read from this bytecode parser. This instructions does not change the instruction opcodes flow.

Specified by:
getMnemonic in interface JBytecodeParser
Returns:
the mnemonic of the instruction opcode read from this bytecode parser

getPosition

public int getPosition()
Returns the current opcode position in the bytecodes flow.

Specified by:
getPosition in interface JBytecodeParser

readOperands

public int readOperands(byte[] b,
                        int off,
                        int len)
Reads up to len operand of the current instruction, read with the nextOpcode method, into an array of bytes. An attempt is made to read as many as len operand bytes, but a smaller number may be read, possibly zero if the current instruction is without operand. The number of operands actually read is returned as an integer.

Specified by:
readOperands in interface JBytecodeParser
Parameters:
b - the buffer into which the operands are read.
off - the start offset in array b at which the operands are written
len - the maximum number of operands to read
Returns:
the total number of bytes read into the buffer, or

getOpcodeCount

public int getOpcodeCount()
Calculates the number of times that this bytecode parser's nextOpcode method can be called before it generates an exception. The current position is not advanced.

Specified by:
getOpcodeCount in interface JBytecodeParser
Returns:
the number of instructions opcode remaining in the bytecode

getOperandCount

public int getOperandCount()
Returns the number of operands of the current instruction read with the nextOpcode method.

Specified by:
getOperandCount in interface JBytecodeParser
Returns:
the number of operands of the current instruction or -1 if there

fillInput

public void fillInput(byte[] b,
                      int off,
                      int len)
Resets the bytecode parsing and initializes it with the len bytes of the specified bytes array, starting at the off position.

Specified by:
fillInput in interface JBytecodeParser
Parameters:
b - the bytecode of a method
off - the start offset in array b at which the parsing is processed
len - the maximum number of bytes to analyse