use of com.github.sevntu.checkstyle.domain.ResolvedCall in project methods-distance by sevntu-checkstyle.
the class MethodCallDependencyCheckstyleModule method buildDependencies.
private static Dependencies buildDependencies(DetailAST topLevelClass, List<DetailAST> methodInvocations) {
final ClassDefinition classDefinition = new ClassDefinition(topLevelClass);
final List<ResolvedCall> callOccurrences = new ArrayList<>();
for (final DetailAST invocation : methodInvocations) {
if (classDefinition.isInsideMethodOfClass(invocation)) {
final Optional<ResolvedCall> occurrence = tryResolveCall(classDefinition, invocation);
occurrence.ifPresent(callOccurrences::add);
}
}
return new Dependencies(classDefinition, callOccurrences);
}
use of com.github.sevntu.checkstyle.domain.ResolvedCall in project methods-distance by sevntu-checkstyle.
the class MethodCallDependencyCheckstyleModule method tryResolveRefCall.
private static Optional<ResolvedCall> tryResolveRefCall(ClassDefinition classDefinition, DetailAST refCallNode) {
final RefCall call = new RefCall(classDefinition, refCallNode);
return Optional.of(call).filter(RefCall::isRefToMethodOfEnclosingClass).map(refCall -> {
return refCall.isRefToStaticMethodOfEnclosingClass() ? classDefinition.getStaticMethodsByName(refCall.getMethodName()) : classDefinition.getInstanceMethodsByName(refCall.getMethodName());
}).filter(list -> !list.isEmpty()).map(possibleMethods -> {
final MethodDefinition callee = possibleMethods.get(0);
final MethodDefinition caller = classDefinition.getMethodByAstNode(call.getEnclosingMethod());
return new ResolvedCall(refCallNode, caller, callee);
});
}
use of com.github.sevntu.checkstyle.domain.ResolvedCall in project methods-distance by sevntu-checkstyle.
the class MethodOrder method getMethodInvocationsNesting.
private static MultiValuedMap<MethodInvocation, MethodInvocation> getMethodInvocationsNesting(Map<ResolvedCall, MethodInvocation> callToInvocation) {
final SetValuedMap<MethodInvocation, MethodInvocation> nestedInside = new HashSetValuedHashMap<>();
callToInvocation.entrySet().stream().forEach(entry -> {
final ResolvedCall resolvedCall = entry.getKey();
final MethodInvocation methodInvocation = entry.getValue();
callToInvocation.keySet().stream().filter(rc -> !rc.equals(resolvedCall)).filter(resolvedCall::isNestedInside).forEach(rc -> nestedInside.put(methodInvocation, callToInvocation.get(rc)));
});
return nestedInside;
}
Aggregations