use of org.freud.analysed.javasource.MethodCall in project freud by LMAX-Exchange.
the class CodeBlockJdom method getMethodCallByMethodNameMap.
@Override
@SuppressWarnings("unchecked")
public Map<String, List<MethodCall>> getMethodCallByMethodNameMap() {
if (methodCallByMethodNameMap == null) {
methodCallByMethodNameMap = new HashMap<String, List<MethodCall>>();
JXPathContext context = JXPathContext.newContext(codeBlockElement);
List<Element> methodCallElementList = context.selectNodes("//" + JavaSourceTokenType.METHOD_CALL.getName());
for (Element methodCallElement : methodCallElementList) {
final MethodCall methodCall = new MethodCallJdom(methodCallElement);
List<MethodCall> methodCallList = methodCallByMethodNameMap.get(methodCall.getMethodName());
if (methodCallList == null) {
methodCallList = new LinkedList<MethodCall>();
methodCallByMethodNameMap.put(methodCall.getMethodName(), methodCallList);
}
methodCallList.add(methodCall);
}
}
return methodCallByMethodNameMap;
}
use of org.freud.analysed.javasource.MethodCall in project freud by LMAX-Exchange.
the class CodeBlockMatchers method hasMethodCall.
public static FreudExtendedMatcher<CodeBlock> hasMethodCall(final String methodCall) {
return new FreudExtendedMatcher<CodeBlock>() {
private final String methodName;
private final String[] instanceReferences;
{
String[] values = methodCall.split("\\.");
instanceReferences = new String[values.length - 1];
System.arraycopy(values, 0, instanceReferences, 0, instanceReferences.length);
methodName = values[values.length - 1];
}
@Override
protected boolean matchesSafely(final CodeBlock toBeAnalysed) {
List<MethodCall> methodCallList = toBeAnalysed.getMethodCallListByMethodName(methodName);
if (methodCallList != null) {
for (MethodCall methodCall : methodCallList) {
if (Arrays.equals(instanceReferences, methodCall.getInstanceReferences())) {
return true;
}
}
}
return false;
}
@Override
public void describeTo(final Description description) {
description.appendText("HasMethodCall(" + methodCall + ")");
}
};
}
Aggregations