use of org.freud.analysed.classbytecode.method.instruction.Instruction in project freud by LMAX-Exchange.
the class ClassByteCodeMethodMatchers method containsInstructions.
public static FreudExtendedMatcher<ClassByteCodeMethod> containsInstructions(final Opcode... opcodes) {
return new FreudExtendedMatcher<ClassByteCodeMethod>() {
private Instruction found = null;
@Override
protected boolean matchesSafely(final ClassByteCodeMethod item) {
item.findInstruction(new AbstractInstructionVisitor() {
@Override
public void noArgInstruction(final Instruction instruction) {
for (int i = 0; i < opcodes.length; i++) {
Opcode opcode = opcodes[i];
if (instruction.getOpcode() == opcode) {
found = instruction;
break;
}
}
}
});
return found != null;
}
@Override
public void describeTo(final Description description) {
description.appendText("containsInstructions(");
for (int i = 0; i < opcodes.length; i++) {
Opcode opcode = opcodes[i];
description.appendText(opcode.name());
description.appendText(", ");
}
description.appendText(") found");
}
};
}
use of org.freud.analysed.classbytecode.method.instruction.Instruction in project freud by LMAX-Exchange.
the class ClassByteCodeMethodMatchers method methodInvokedWithParams.
public static FreudExtendedMatcher<ClassByteCodeMethod> methodInvokedWithParams(final Class expectedOwner, final String expectedMethodName, final Matcher<OperandStack>... expectedParamsPassed) {
return new FreudExtendedMatcher<ClassByteCodeMethod>() {
private String expectedOwnerName;
{
expectedOwnerName = typeEncoding(expectedOwner);
}
@Override
protected boolean matchesSafely(final ClassByteCodeMethod item) {
final boolean[] found = new boolean[1];
found[0] = false;
item.findInstruction(new AbstractInstructionVisitor() {
@Override
public void methodInvocation(final Instruction instruction, final String owner, final String methodName, final String... args) {
if (!found[0] && expectedOwnerName.equals(owner) && expectedMethodName.equals(methodName)) {
Instruction prevInstruction = item.getInstruction(instruction.getInstructionIndex() - 1);
OperandStack operandStack = prevInstruction.getOperandStack();
found[0] = true;
for (int i = expectedParamsPassed.length - 1; i >= 0; i--) {
Matcher<OperandStack> matcher = expectedParamsPassed[i];
if (!matcher.matches(operandStack)) {
found[0] = false;
break;
}
operandStack = operandStack.next();
}
}
}
});
return found[0];
}
@Override
public void describeTo(final Description description) {
description.appendText("methodInvokedWithParams(" + expectedOwner.getName() + ", " + expectedMethodName + ")");
}
};
}
use of org.freud.analysed.classbytecode.method.instruction.Instruction in project freud by LMAX-Exchange.
the class AsmMethod method visitMethodInsn.
public void visitMethodInsn(final int opcode, final String owner, final String name, final String desc) {
final Matcher matcher = METHOD_DESC_PATTERN.matcher(desc);
if (matcher.matches()) {
final String argsAsString = matcher.group(1);
final ArrayList<String> argsContainer = new ArrayList<String>();
String returnType = matcher.group(2);
parseArgs(argsAsString, argsContainer);
String[] args = argsContainer.toArray(new String[argsContainer.size()]);
final Instruction instruction = new MethodInvocationInstruction(instructionList.size(), OPCODES_ARRAY[opcode], currentLineNumber, "L" + owner + ";", name, args, returnType);
updateCurrentState(instruction);
}
}
use of org.freud.analysed.classbytecode.method.instruction.Instruction in project freud by LMAX-Exchange.
the class AsmMethod method visitIntInsn.
public void visitIntInsn(final int opcodeUsed, final int operand) {
final Opcode opcode = OPCODES_ARRAY[opcodeUsed];
final Instruction instruction;
if (opcode == Opcode.NEWARRAY) {
instruction = new ReferenceOperandInstruction(instructionList.size(), opcode, currentLineNumber, NEWARRAY_TYPES[operand]);
} else {
instruction = new IntOperandInstruction(instructionList.size(), opcode, currentLineNumber, operand);
}
updateCurrentState(instruction);
}
use of org.freud.analysed.classbytecode.method.instruction.Instruction in project freud by LMAX-Exchange.
the class AsmMethod method visitIincInsn.
public void visitIincInsn(final int var, final int increment) {
final Instruction instruction = new IntOperandInstruction(instructionList.size(), Opcode.IINC, currentLineNumber, increment);
updateCurrentState(instruction);
}
Aggregations