|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.objectweb.asm.tree.analysis.BasicInterpreter
org.unitils.mock.argumentmatcher.ArgumentMatcherPositionFinder.MethodInterpreter
protected static class ArgumentMatcherPositionFinder.MethodInterpreter
Interpreter that implements the argument matcher finder behavior. The analyzer simulates the processing of instructions by the VM and calls methods on this class to determine the result of the processing of an instruction. During this processing, the analyzer simulates the maintenance of the operand stack. For example:
Suppose you have following statement: 1 + 2 The analyzer will first simulate the instruction to load constant 1 on the operand stack, then it does the same for constant 2, finally it simulates the sum instruction on both operands, removes both operands from the operand stack and puts the result back on the stack. All these instructions will pass through this interpreter to determine the result values to put on the operand stack. This interpreter works as follows to find the argument matchers: if a method call instruction is found that is an argument matcher we return an ArugmentMatcherValue. For other instructions an ArugmentMatcherValue is returned if one of its operands was a an ArugmentMatcherValue. When the actual invoked method is found, we then just have to look at the operands: if one of the operands is an ArugmentMatcherValue, we've found the index of the argument matcher. For example:
Field Summary | |
---|---|
protected int |
currentIndex
|
protected int |
currentLineNr
|
protected Method |
currentMatcherMethod
|
protected int |
fromLineNr
|
protected Set<org.objectweb.asm.tree.MethodInsnNode> |
handledMethodInsnNodes
|
protected int |
index
|
protected Class<?> |
interpretedClass
|
protected String |
interpretedMethodName
|
protected String |
invokedMethodDescriptor
|
protected String |
invokedMethodName
|
protected List<Integer> |
resultArgumentMatcherIndexes
|
protected int |
toLineNr
|
Fields inherited from interface org.objectweb.asm.Opcodes |
---|
AALOAD, AASTORE, ACC_ABSTRACT, ACC_ANNOTATION, ACC_BRIDGE, ACC_DEPRECATED, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_VARARGS, ACC_VOLATILE, ACONST_NULL, ALOAD, ANEWARRAY, ARETURN, ARRAYLENGTH, ASTORE, ATHROW, BALOAD, BASTORE, BIPUSH, CALOAD, CASTORE, CHECKCAST, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DMUL, DNEG, DOUBLE, DREM, DRETURN, DSTORE, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F_APPEND, F_CHOP, F_FULL, F_NEW, F_SAME, F_SAME1, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FLOAT, FMUL, FNEG, FREM, FRETURN, FSTORE, FSUB, GETFIELD, GETSTATIC, GOTO, 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, IMUL, INEG, INSTANCEOF, INTEGER, INVOKEINTERFACE, INVOKESPECIAL, INVOKESTATIC, INVOKEVIRTUAL, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISUB, IUSHR, IXOR, JSR, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDC, LDIV, LLOAD, LMUL, LNEG, LONG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, NULL, POP, POP2, PUTFIELD, PUTSTATIC, RET, RETURN, SALOAD, SASTORE, SIPUSH, SWAP, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TABLESWITCH, TOP, UNINITIALIZED_THIS, V1_1, V1_2, V1_3, V1_4, V1_5, V1_6 |
Constructor Summary | |
---|---|
ArgumentMatcherPositionFinder.MethodInterpreter(Class<?> interpretedClass,
String interpretedMethodName,
String invokedMethodName,
String invokedMethodDescriptor,
int fromLineNr,
int toLineNr,
int index)
Creates an interpreter. |
Method Summary | |
---|---|
org.objectweb.asm.tree.analysis.Value |
binaryOperation(org.objectweb.asm.tree.AbstractInsnNode insn,
org.objectweb.asm.tree.analysis.Value value1,
org.objectweb.asm.tree.analysis.Value value2)
|
org.objectweb.asm.tree.analysis.Value |
copyOperation(org.objectweb.asm.tree.AbstractInsnNode insn,
org.objectweb.asm.tree.analysis.Value value)
|
protected ArgumentMatcherPositionFinder.ArgumentMatcherValue |
createArgumentMatcherValue(org.objectweb.asm.tree.analysis.Value resultValue)
|
protected List<Integer> |
getArgumentMatcherIndexes(org.objectweb.asm.tree.MethodInsnNode methodInsnNode,
List values)
|
protected Method |
getMethod(org.objectweb.asm.tree.MethodInsnNode methodNode)
Finds a method using the ASM method node |
protected int |
getNrOfArgumentMacherValues(List<org.objectweb.asm.tree.analysis.Value> values)
|
List<Integer> |
getResultArgumentMatcherIndexes()
Gets the result after the analysis was performed. |
protected org.objectweb.asm.tree.analysis.Value |
getValue(org.objectweb.asm.tree.analysis.Value resultValue,
List<org.objectweb.asm.tree.analysis.Value> values)
|
protected org.objectweb.asm.tree.analysis.Value |
getValue(org.objectweb.asm.tree.analysis.Value resultValue,
org.objectweb.asm.tree.analysis.Value... values)
|
protected boolean |
instructionAlreadyHandled(org.objectweb.asm.tree.MethodInsnNode methodInsnNode)
|
protected boolean |
instructionOutOfRange()
|
protected boolean |
isArgumentMatcherMethod(Method method)
|
protected boolean |
isInvokedMethod(org.objectweb.asm.tree.MethodInsnNode methodInsnNode)
|
protected boolean |
isMatcherMethod(Method method)
|
org.objectweb.asm.tree.analysis.Value |
merge(org.objectweb.asm.tree.analysis.Value value1,
org.objectweb.asm.tree.analysis.Value value2)
Merges two values. |
org.objectweb.asm.tree.analysis.Value |
naryOperation(org.objectweb.asm.tree.AbstractInsnNode instructionNode,
List values)
Handles an instruction of a method call. |
void |
setCurrentLineNr(int currentLineNr)
Sets the line nr that is being analyzed. |
org.objectweb.asm.tree.analysis.Value |
ternaryOperation(org.objectweb.asm.tree.AbstractInsnNode insn,
org.objectweb.asm.tree.analysis.Value value1,
org.objectweb.asm.tree.analysis.Value value2,
org.objectweb.asm.tree.analysis.Value value3)
|
protected void |
throwUnitilsException(String errorMessage)
Throws a UnitilsException with the given error message. |
org.objectweb.asm.tree.analysis.Value |
unaryOperation(org.objectweb.asm.tree.AbstractInsnNode insn,
org.objectweb.asm.tree.analysis.Value value)
|
Methods inherited from class org.objectweb.asm.tree.analysis.BasicInterpreter |
---|
newOperation, newValue |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected Class<?> interpretedClass
protected String interpretedMethodName
protected String invokedMethodName
protected String invokedMethodDescriptor
protected int fromLineNr
protected int toLineNr
protected int index
protected int currentLineNr
protected int currentIndex
protected Method currentMatcherMethod
protected Set<org.objectweb.asm.tree.MethodInsnNode> handledMethodInsnNodes
protected List<Integer> resultArgumentMatcherIndexes
Constructor Detail |
---|
public ArgumentMatcherPositionFinder.MethodInterpreter(Class<?> interpretedClass, String interpretedMethodName, String invokedMethodName, String invokedMethodDescriptor, int fromLineNr, int toLineNr, int index)
interpretedClass
- The current class, not nullinterpretedMethodName
- The current method name, not nullinvokedMethodName
- The method to look for, not nullinvokedMethodDescriptor
- The signature of the method to look for, not nullfromLineNr
- The begin line-nr of the invocationtoLineNr
- The end line-nr of the invocation (could be different from the begin line-nr if the invocation is written on more than 1 line)index
- The index of the matcher on that line, 1 for the first, 2 for the second etcMethod Detail |
---|
public List<Integer> getResultArgumentMatcherIndexes()
public void setCurrentLineNr(int currentLineNr)
currentLineNr
- The line nrpublic org.objectweb.asm.tree.analysis.Value copyOperation(org.objectweb.asm.tree.AbstractInsnNode insn, org.objectweb.asm.tree.analysis.Value value) throws org.objectweb.asm.tree.analysis.AnalyzerException
copyOperation
in interface org.objectweb.asm.tree.analysis.Interpreter
copyOperation
in class org.objectweb.asm.tree.analysis.BasicInterpreter
org.objectweb.asm.tree.analysis.AnalyzerException
public org.objectweb.asm.tree.analysis.Value unaryOperation(org.objectweb.asm.tree.AbstractInsnNode insn, org.objectweb.asm.tree.analysis.Value value) throws org.objectweb.asm.tree.analysis.AnalyzerException
unaryOperation
in interface org.objectweb.asm.tree.analysis.Interpreter
unaryOperation
in class org.objectweb.asm.tree.analysis.BasicInterpreter
org.objectweb.asm.tree.analysis.AnalyzerException
public org.objectweb.asm.tree.analysis.Value binaryOperation(org.objectweb.asm.tree.AbstractInsnNode insn, org.objectweb.asm.tree.analysis.Value value1, org.objectweb.asm.tree.analysis.Value value2) throws org.objectweb.asm.tree.analysis.AnalyzerException
binaryOperation
in interface org.objectweb.asm.tree.analysis.Interpreter
binaryOperation
in class org.objectweb.asm.tree.analysis.BasicInterpreter
org.objectweb.asm.tree.analysis.AnalyzerException
public org.objectweb.asm.tree.analysis.Value ternaryOperation(org.objectweb.asm.tree.AbstractInsnNode insn, org.objectweb.asm.tree.analysis.Value value1, org.objectweb.asm.tree.analysis.Value value2, org.objectweb.asm.tree.analysis.Value value3) throws org.objectweb.asm.tree.analysis.AnalyzerException
ternaryOperation
in interface org.objectweb.asm.tree.analysis.Interpreter
ternaryOperation
in class org.objectweb.asm.tree.analysis.BasicInterpreter
org.objectweb.asm.tree.analysis.AnalyzerException
public org.objectweb.asm.tree.analysis.Value naryOperation(org.objectweb.asm.tree.AbstractInsnNode instructionNode, List values) throws org.objectweb.asm.tree.analysis.AnalyzerException
naryOperation
in interface org.objectweb.asm.tree.analysis.Interpreter
naryOperation
in class org.objectweb.asm.tree.analysis.BasicInterpreter
instructionNode
- The instructionvalues
- The operands
org.objectweb.asm.tree.analysis.AnalyzerException
protected boolean instructionOutOfRange()
protected boolean instructionAlreadyHandled(org.objectweb.asm.tree.MethodInsnNode methodInsnNode)
protected boolean isInvokedMethod(org.objectweb.asm.tree.MethodInsnNode methodInsnNode)
protected List<Integer> getArgumentMatcherIndexes(org.objectweb.asm.tree.MethodInsnNode methodInsnNode, List values)
protected boolean isMatcherMethod(Method method)
protected boolean isArgumentMatcherMethod(Method method)
protected void throwUnitilsException(String errorMessage)
UnitilsException
with the given error message. The stacktrace is modified, to make
it point to the line of code that was analyzed by this class.
errorMessage
- The error messagepublic org.objectweb.asm.tree.analysis.Value merge(org.objectweb.asm.tree.analysis.Value value1, org.objectweb.asm.tree.analysis.Value value2)
merge
in interface org.objectweb.asm.tree.analysis.Interpreter
merge
in class org.objectweb.asm.tree.analysis.BasicInterpreter
value1
- The first valuevalue2
- The second value
protected Method getMethod(org.objectweb.asm.tree.MethodInsnNode methodNode)
methodNode
- The ASM method node, not null
protected org.objectweb.asm.tree.analysis.Value getValue(org.objectweb.asm.tree.analysis.Value resultValue, org.objectweb.asm.tree.analysis.Value... values)
resultValue
- The result valuevalues
- The values that can be ArgumentMatcherValues
protected org.objectweb.asm.tree.analysis.Value getValue(org.objectweb.asm.tree.analysis.Value resultValue, List<org.objectweb.asm.tree.analysis.Value> values)
resultValue
- The result valuevalues
- The values that can be ArgumentMatcherValues
protected int getNrOfArgumentMacherValues(List<org.objectweb.asm.tree.analysis.Value> values)
values
- The values that can be ArgumentMatcherValues
protected ArgumentMatcherPositionFinder.ArgumentMatcherValue createArgumentMatcherValue(org.objectweb.asm.tree.analysis.Value resultValue)
resultValue
- The result value
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |