Search in sources :

Example 1 with FieldAccess

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

the class ReferenceSearcher method searchFieldReferences.

private static List<Reference> searchFieldReferences(Source src, SearchCondition sc) throws IOException {
    List<String> lines = FileUtils.readLines(src.getFile());
    int size = lines.size();
    List<Reference> result = new ArrayList<>(size);
    Collection<FieldAccess> fieldAccesses = src.getFieldAccesses();
    for (FieldAccess fa : fieldAccesses) {
        String declaringClass = fa.declaringClass;
        String methodName = fa.name;
        if (sc.declaringClass.equals(declaringClass) && sc.name.equals(methodName)) {
            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) FieldAccess(meghanada.analyze.FieldAccess) Range(meghanada.analyze.Range)

Example 2 with FieldAccess

use of meghanada.analyze.FieldAccess 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

ArrayList (java.util.ArrayList)2 FieldAccess (meghanada.analyze.FieldAccess)2 Range (meghanada.analyze.Range)2 MethodCall (meghanada.analyze.MethodCall)1