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());
}
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());
}
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());
}
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());
}
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;
}
Aggregations