Search in sources :

Example 6 with Range

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

the class ReferenceSearcher method searchMethodCallReferences.

private static List<Reference> searchMethodCallReferences(Source src, SearchCondition sc) throws IOException {
    List<String> lines = FileUtils.readLines(src.getFile());
    int size = lines.size();
    List<Reference> result = new ArrayList<>(size);
    Collection<MethodCall> methodCalls = src.getMethodCalls();
    for (MethodCall mc : methodCalls) {
        String declaringClass = mc.declaringClass;
        String methodName = mc.name;
        boolean compare = ClassNameUtils.compareArgumentType(mc.getArguments(), sc.arguments);
        if (compare && sc.declaringClass.equals(declaringClass) && sc.name.equals(methodName)) {
            Range range = mc.nameRange;
            long line = range.begin.line;
            long column = range.begin.column;
            String code = StringEscapeUtils.escapeJava(lines.get((int) line - 1));
            Reference ref = new Reference(src.filePath, line, column, code);
            result.add(ref);
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Range(meghanada.analyze.Range) MethodCall(meghanada.analyze.MethodCall)

Example 7 with Range

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

the class JavaVariableCompletionTest method createLocalVariable5.

@Test
public void createLocalVariable5() 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 mcs = new MethodCall("parser", "parse", 0, nameRange, range);
        return completion.createLocalVariable(mcs, "org.apache.commons.cli.CommandLine");
    });
    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 8 with Range

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

the class ReferenceSearcher method searchClassReferences.

private static List<Reference> searchClassReferences(Source src, SearchCondition sc) throws IOException {
    List<String> lines = FileUtils.readLines(src.getFile());
    int size = lines.size();
    List<Reference> result = new ArrayList<>(size);
    Collection<MethodCall> methodCalls = src.getMethodCalls();
    for (MethodCall mc : methodCalls) {
        String declaringClass = mc.declaringClass;
        if (sc.declaringClass.equals(declaringClass) && mc.scope.contains(sc.name)) {
            Range range = mc.nameRange;
            long line = range.begin.line;
            long column = range.begin.column;
            String code = StringEscapeUtils.escapeJava(lines.get((int) line - 1));
            Reference ref = new Reference(src.filePath, line, column, code);
            result.add(ref);
        }
    }
    Collection<FieldAccess> fieldAccesses = src.getFieldAccesses();
    for (FieldAccess fa : fieldAccesses) {
        String declaringClass = fa.declaringClass;
        if (sc.declaringClass.equals(declaringClass) && fa.scope.contains(sc.name)) {
            Range range = fa.range;
            long line = range.begin.line;
            long column = range.begin.column;
            String code = StringEscapeUtils.escapeJava(lines.get((int) line - 1));
            Reference ref = new Reference(src.filePath, line, column, code);
            result.add(ref);
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Range(meghanada.analyze.Range) FieldAccess(meghanada.analyze.FieldAccess) MethodCall(meghanada.analyze.MethodCall)

Aggregations

Range (meghanada.analyze.Range)8 MethodCall (meghanada.analyze.MethodCall)7 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)3 FieldAccess (meghanada.analyze.FieldAccess)2