Search in sources :

Example 1 with MethodCall

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

the class JavaVariableCompletionTest method createLocalVariable4.

@Test
public void createLocalVariable4() throws Exception {
    JavaVariableCompletion completion = getCompilation();
    Optional<LocalVariable> olv = timeIt(() -> {
        final Range range = new Range(0, 0, 0, 0);
        final Range nameRange = new Range(0, 0, 0, 0);
        final MethodCall mc = new MethodCall("list", "subList", 0, nameRange, range);
        return completion.createLocalVariable(mc, "java.util.List<MemberDescriptor>");
    });
    LocalVariable lv = olv.get();
    System.out.println(lv);
    assertEquals(6, lv.getCandidates().size());
}
Also used : Range(meghanada.analyze.Range) MethodCall(meghanada.analyze.MethodCall) Test(org.junit.Test)

Example 2 with MethodCall

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

the class JavaVariableCompletionTest method createLocalVariable2.

@Test
public void createLocalVariable2() throws Exception {
    JavaVariableCompletion completion = getCompilation();
    Optional<LocalVariable> olv = timeIt(() -> {
        final Range range = new Range(0, 0, 0, 0);
        final Range nameRange = new Range(0, 0, 0, 0);
        final MethodCall mc = new MethodCall("file", "getFileName", 0, nameRange, range);
        return completion.createLocalVariable(mc, "String");
    });
    LocalVariable lv = olv.get();
    System.out.println(lv);
    assertEquals(4, lv.getCandidates().size());
}
Also used : Range(meghanada.analyze.Range) MethodCall(meghanada.analyze.MethodCall) Test(org.junit.Test)

Example 3 with MethodCall

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

the class JavaVariableCompletionTest method createLocalVariable1.

@Test
public void createLocalVariable1() throws Exception {
    JavaVariableCompletion completion = getCompilation();
    Optional<LocalVariable> olv = debugIt(() -> {
        final Range range = new Range(0, 0, 0, 0);
        final Range nameRange = new Range(0, 0, 0, 0);
        final MethodCall mc = new MethodCall("mkdir", 0, nameRange, range);
        return completion.createLocalVariable(mc, "boolean");
    });
    LocalVariable lv = olv.get();
    System.out.println(lv);
    assertEquals(2, lv.getCandidates().size());
}
Also used : Range(meghanada.analyze.Range) MethodCall(meghanada.analyze.MethodCall) Test(org.junit.Test)

Example 4 with MethodCall

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

the class JavaVariableCompletionTest method createLocalVariable3.

@Test
public void createLocalVariable3() throws Exception {
    JavaVariableCompletion completion = getCompilation();
    Optional<LocalVariable> olv = timeIt(() -> {
        final Range range = new Range(0, 0, 0, 0);
        final Range nameRange = new Range(0, 0, 0, 0);
        final MethodCall mc = new MethodCall("list", "subList", 0, nameRange, range);
        return completion.createLocalVariable(mc, "java.util.List<String>");
    });
    LocalVariable lv = olv.get();
    System.out.println(lv);
    assertEquals(5, lv.getCandidates().size());
}
Also used : Range(meghanada.analyze.Range) MethodCall(meghanada.analyze.MethodCall) Test(org.junit.Test)

Example 5 with MethodCall

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

the class DeclarationSearcher method searchMethodCall.

private static Optional<Declaration> searchMethodCall(final Source source, final Integer line, final Integer col, final String symbol) {
    final EntryMessage entryMessage = log.traceEntry("line={} col={} symbol={}", line, col, symbol);
    final Optional<MethodCall> methodCall = source.getMethodCall(line, col, true);
    final Optional<Declaration> result = methodCall.map(mc -> {
        final String methodName = mc.name;
        final List<String> arguments = mc.getArguments();
        final String declaringClass = mc.declaringClass;
        if (declaringClass == null) {
            return null;
        }
        final CachedASMReflector reflector = CachedASMReflector.getInstance();
        final MemberDescriptor method = searchMethod(declaringClass, methodName, arguments).orElseGet(() -> searchConstructor(declaringClass, arguments).orElse(null));
        String declaration;
        if (method != null) {
            declaration = method.getDeclaration();
        } else {
            final String args = Joiner.on(", ").join(arguments);
            declaration = mc.returnType + ' ' + methodName + '(' + args + ')';
        }
        String scope = mc.scope;
        if (scope != null && !scope.isEmpty()) {
            scope = scope + '.' + symbol;
        } else {
            scope = symbol;
        }
        return new Declaration(scope.trim(), declaration, Declaration.Type.METHOD, mc.argumentIndex);
    });
    log.traceExit(entryMessage);
    return result;
}
Also used : CachedASMReflector(meghanada.reflect.asm.CachedASMReflector) MemberDescriptor(meghanada.reflect.MemberDescriptor) EntryMessage(org.apache.logging.log4j.message.EntryMessage) MethodCall(meghanada.analyze.MethodCall)

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