Search in sources :

Example 11 with MethodCall

use of meghanada.analyze.MethodCall in project meghanada-server by mopemope.

the class ReferenceSearcher method searchMethodCallCondition.

private static Optional<SearchCondition> searchMethodCallCondition(Source source, int line, int col, String symbol) {
    EntryMessage msg = log.traceEntry("line={} col={} symbol={}", line, col, symbol);
    Optional<MethodCall> mcResult = source.getMethodCall(line, col, true);
    Optional<SearchCondition> result = mcResult.map(mc -> {
        String methodName = mc.name;
        List<String> arguments = mc.getArguments();
        String declaringClass = mc.declaringClass;
        if (isNull(declaringClass)) {
            return null;
        }
        MemberDescriptor method = searchMatchMethod(declaringClass, methodName, arguments).orElseGet(() -> searchMatchConstructor(declaringClass, arguments).orElse(null));
        if (isNull(method)) {
            // not match
            return null;
        }
        MethodDescriptor md = (MethodDescriptor) method;
        if (md.getMemberType().equals(CandidateUnit.MemberType.CONSTRUCTOR)) {
            return new SearchCondition(mc.declaringClass, mc.name, SearchCondition.Type.CONSTRUCTOR, mc.getArguments());
        }
        return new SearchCondition(mc.declaringClass, mc.name, SearchCondition.Type.METHOD, mc.getArguments());
    });
    log.traceExit(msg);
    return result;
}
Also used : MemberDescriptor(meghanada.reflect.MemberDescriptor) EntryMessage(org.apache.logging.log4j.message.EntryMessage) MethodCall(meghanada.analyze.MethodCall) MethodDescriptor(meghanada.reflect.MethodDescriptor)

Aggregations

MethodCall (meghanada.analyze.MethodCall)11 Range (meghanada.analyze.Range)7 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)3 MemberDescriptor (meghanada.reflect.MemberDescriptor)3 CachedASMReflector (meghanada.reflect.asm.CachedASMReflector)3 EntryMessage (org.apache.logging.log4j.message.EntryMessage)3 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Optional (java.util.Optional)1 ClassScope (meghanada.analyze.ClassScope)1 FieldAccess (meghanada.analyze.FieldAccess)1 Variable (meghanada.analyze.Variable)1 CandidateUnit (meghanada.reflect.CandidateUnit)1 FieldDescriptor (meghanada.reflect.FieldDescriptor)1 MethodDescriptor (meghanada.reflect.MethodDescriptor)1