Search in sources :

Example 1 with RefCall

use of com.github.sevntu.checkstyle.domain.RefCall 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);
    });
}
Also used : ResolvedCall(com.github.sevntu.checkstyle.domain.ResolvedCall) AbstractCheck(com.puppycrawl.tools.checkstyle.api.AbstractCheck) MethodCall(com.github.sevntu.checkstyle.domain.MethodCall) ClassDefinition(com.github.sevntu.checkstyle.domain.ClassDefinition) File(java.io.File) ArrayList(java.util.ArrayList) UnexpectedTokenTypeException(com.github.sevntu.checkstyle.common.UnexpectedTokenTypeException) RefCall(com.github.sevntu.checkstyle.domain.RefCall) TokenTypes(com.puppycrawl.tools.checkstyle.api.TokenTypes) List(java.util.List) TokenUtils(com.puppycrawl.tools.checkstyle.utils.TokenUtils) Optional(java.util.Optional) MethodDefinition(com.github.sevntu.checkstyle.domain.MethodDefinition) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) Dependencies(com.github.sevntu.checkstyle.domain.Dependencies) ResolvedCall(com.github.sevntu.checkstyle.domain.ResolvedCall) RefCall(com.github.sevntu.checkstyle.domain.RefCall) MethodDefinition(com.github.sevntu.checkstyle.domain.MethodDefinition)

Aggregations

UnexpectedTokenTypeException (com.github.sevntu.checkstyle.common.UnexpectedTokenTypeException)1 ClassDefinition (com.github.sevntu.checkstyle.domain.ClassDefinition)1 Dependencies (com.github.sevntu.checkstyle.domain.Dependencies)1 MethodCall (com.github.sevntu.checkstyle.domain.MethodCall)1 MethodDefinition (com.github.sevntu.checkstyle.domain.MethodDefinition)1 RefCall (com.github.sevntu.checkstyle.domain.RefCall)1 ResolvedCall (com.github.sevntu.checkstyle.domain.ResolvedCall)1 AbstractCheck (com.puppycrawl.tools.checkstyle.api.AbstractCheck)1 DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)1 TokenTypes (com.puppycrawl.tools.checkstyle.api.TokenTypes)1 TokenUtils (com.puppycrawl.tools.checkstyle.utils.TokenUtils)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1