use of org.freud.analysed.classbytecode.method.instruction.OperandStack 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.OperandStack in project freud by LMAX-Exchange.
the class ClassByteCodeDsl method methodInvokedWithParams.
public static boolean methodInvokedWithParams(final ClassByteCodeMethod analysed, final Class expectedOwner, final String expectedMethodName, final Class... expectedParamTypes) {
final String expectedOwnerName = typeEncoding(expectedOwner);
final boolean[] found = new boolean[1];
found[0] = false;
analysed.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 = analysed.getInstruction(instruction.getInstructionIndex() - 1);
OperandStack operandStack = prevInstruction.getOperandStack();
found[0] = true;
for (int i = expectedParamTypes.length - 1; i >= 0; i--) {
final String expectedType = typeEncoding(expectedParamTypes[i]);
if (!expectedType.equals(operandStack.getOperandType())) {
found[0] = false;
break;
}
operandStack = operandStack.next();
}
}
}
});
return found[0];
}
Aggregations