Search in sources :

Example 1 with Position

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

the class ReferenceSearcher method searchMemberCondition.

private static Optional<SearchCondition> searchMemberCondition(Source source, int line, int col, String symbol) {
    EntryMessage msg = log.traceEntry("line={} col={} symbol={}", line, col, symbol);
    for (ClassScope classScope : source.getClassScopes()) {
        for (Variable variable : classScope.getVariables()) {
            if (variable.isField) {
                Position pos = variable.range.begin;
                String name = variable.name;
                if (pos.line == line && name.equals(symbol)) {
                    String clazz = classScope.getFQCN();
                    SearchCondition condition = new SearchCondition(clazz, name, SearchCondition.Type.FIELD);
                    return Optional.of(condition);
                }
            }
        }
        for (BlockScope blockScope : classScope.getScopes()) {
            if (blockScope instanceof MethodScope) {
                MethodScope methodScope = ((MethodScope) blockScope);
                Position pos = methodScope.getNameRange().begin;
                String name = methodScope.getName();
                if (pos.line == line && name.equals(symbol)) {
                    String clazz = classScope.getFQCN();
                    SearchCondition condition = new SearchCondition(clazz, name, SearchCondition.Type.METHOD, methodScope.getParameters());
                    return Optional.of(condition);
                }
            }
        }
    }
    log.traceExit(msg);
    return Optional.empty();
}
Also used : Variable(meghanada.analyze.Variable) Position(meghanada.analyze.Position) BlockScope(meghanada.analyze.BlockScope) MethodScope(meghanada.analyze.MethodScope) EntryMessage(org.apache.logging.log4j.message.EntryMessage) ClassScope(meghanada.analyze.ClassScope)

Aggregations

BlockScope (meghanada.analyze.BlockScope)1 ClassScope (meghanada.analyze.ClassScope)1 MethodScope (meghanada.analyze.MethodScope)1 Position (meghanada.analyze.Position)1 Variable (meghanada.analyze.Variable)1 EntryMessage (org.apache.logging.log4j.message.EntryMessage)1