use of com.github.sevntu.checkstyle.domain.ClassDefinition 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.ClassDefinition 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);
});
}
Aggregations