Search in sources :

Example 1 with CodeBlock

use of org.freud.analysed.javasource.CodeBlock 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 + ")");
        }
    };
}
Also used : Description(org.hamcrest.Description) CodeBlock(org.freud.analysed.javasource.CodeBlock) FreudExtendedMatcher(org.freud.java.matcher.FreudExtendedMatcher) MethodCall(org.freud.analysed.javasource.MethodCall)

Aggregations

CodeBlock (org.freud.analysed.javasource.CodeBlock)1 MethodCall (org.freud.analysed.javasource.MethodCall)1 FreudExtendedMatcher (org.freud.java.matcher.FreudExtendedMatcher)1 Description (org.hamcrest.Description)1