Search in sources :

Example 56 with EntryMessage

use of org.apache.logging.log4j.message.EntryMessage in project meghanada-server by mopemope.

the class Source method getMethodCall.

public Optional<MethodCall> getMethodCall(final int line, final int column, final boolean onlyName) {
    final EntryMessage entryMessage = log.traceEntry("line={} column={}", line, column);
    int col = column;
    final Scope scope = Scope.getInnerScope(line, this.classScopes);
    if (nonNull(scope)) {
        final Collection<MethodCall> symbols = scope.getMethodCall(line);
        final int size = symbols.size();
        log.trace("variables:{}", symbols);
        if (onlyName) {
            for (final MethodCall methodCall : symbols) {
                if (methodCall.nameContains(col)) {
                    final Optional<MethodCall> result = Optional.of(methodCall);
                    return log.traceExit(entryMessage, result);
                }
            }
        } else {
            while (size > 0 && col-- > 0) {
                for (final MethodCall methodCallSymbol : symbols) {
                    if (methodCallSymbol.containsColumn(col)) {
                        final Optional<MethodCall> result = Optional.of(methodCallSymbol);
                        return log.traceExit(entryMessage, result);
                    }
                }
            }
        }
    }
    final Optional<MethodCall> empty = Optional.empty();
    return log.traceExit(entryMessage, empty);
}
Also used : EntryMessage(org.apache.logging.log4j.message.EntryMessage)

Example 57 with EntryMessage

use of org.apache.logging.log4j.message.EntryMessage in project meghanada-server by mopemope.

the class ReferenceSearcher method searchMethodCallCondition.

private static Optional<SearchCondition> searchMethodCallCondition(Source source, int line, int col, String symbol) {
    EntryMessage msg = log.traceEntry("line={} col={} symbol={}", line, col, symbol);
    Optional<MethodCall> mcResult = source.getMethodCall(line, col, true);
    Optional<SearchCondition> result = mcResult.map(mc -> {
        String methodName = mc.name;
        List<String> arguments = mc.getArguments();
        String declaringClass = mc.declaringClass;
        if (isNull(declaringClass)) {
            return null;
        }
        MemberDescriptor method = searchMatchMethod(declaringClass, methodName, arguments).orElseGet(() -> searchMatchConstructor(declaringClass, arguments).orElse(null));
        if (isNull(method)) {
            // not match
            return null;
        }
        MethodDescriptor md = (MethodDescriptor) method;
        if (md.getMemberType().equals(CandidateUnit.MemberType.CONSTRUCTOR)) {
            return new SearchCondition(mc.declaringClass, mc.name, SearchCondition.Type.CONSTRUCTOR, mc.getArguments());
        }
        return new SearchCondition(mc.declaringClass, mc.name, SearchCondition.Type.METHOD, mc.getArguments());
    });
    log.traceExit(msg);
    return result;
}
Also used : MemberDescriptor(meghanada.reflect.MemberDescriptor) EntryMessage(org.apache.logging.log4j.message.EntryMessage) MethodCall(meghanada.analyze.MethodCall) MethodDescriptor(meghanada.reflect.MethodDescriptor)

Example 58 with EntryMessage

use of org.apache.logging.log4j.message.EntryMessage in project meghanada-server by mopemope.

the class ReferenceSearcher method searchClassCondition.

private static Optional<SearchCondition> searchClassCondition(Source source, int line, int col, String symbol) {
    final CachedASMReflector reflector = CachedASMReflector.getInstance();
    final EntryMessage entryMessage = log.traceEntry("line={} col={} symbol={}", line, col, symbol);
    Optional<SearchCondition> result;
    String fqcn = source.getImportedClassFQCN(symbol, null);
    if (isNull(fqcn)) {
        if (!source.getPackageName().isEmpty()) {
            fqcn = source.getPackageName() + '.' + symbol;
            result = reflector.containsClassIndex(fqcn).map(index -> {
                SearchCondition sc = new SearchCondition(index.getRawDeclaration(), index.getName(), SearchCondition.Type.CLASS);
                return Optional.of(sc);
            }).orElseGet(() -> {
                final Set<String> parents = new HashSet<>(8);
                for (final ClassScope classScope : source.getClassScopes()) {
                    final String className = classScope.getFQCN();
                    parents.add(className);
                }
                parents.addAll(source.importClasses);
                for (final ClassIndex index : reflector.searchInnerClasses(parents)) {
                    final String returnType = index.getReturnType();
                    if (returnType.endsWith(symbol)) {
                        SearchCondition sc = new SearchCondition(index.getRawDeclaration(), index.getName(), SearchCondition.Type.CLASS);
                        return Optional.of(sc);
                    }
                }
                return Optional.empty();
            });
        } else {
            result = Optional.empty();
        }
    } else {
        SearchCondition sc = new SearchCondition(fqcn, ClassNameUtils.getSimpleName(fqcn), SearchCondition.Type.CLASS);
        result = Optional.of(sc);
    }
    log.traceExit(entryMessage);
    return result;
}
Also used : ClassIndex(meghanada.reflect.ClassIndex) CachedASMReflector(meghanada.reflect.asm.CachedASMReflector) HashSet(java.util.HashSet) Set(java.util.Set) EntryMessage(org.apache.logging.log4j.message.EntryMessage) ClassScope(meghanada.analyze.ClassScope)

Example 59 with EntryMessage

use of org.apache.logging.log4j.message.EntryMessage in project meghanada-server by mopemope.

the class MethodScope method dumpVariable.

@Override
public void dumpVariable() {
    final EntryMessage entryMessage = log.traceEntry("**** {} {} return {}", this.getScopeType(), this.name, this.returnType);
    super.dumpVariable(log);
    for (final ExpressionScope expressionScope : this.expressions) {
        expressionScope.dumpVariable();
    }
    for (final BlockScope blockScope : this.scopes) {
        blockScope.dumpVariable();
    }
    log.traceExit(entryMessage);
}
Also used : EntryMessage(org.apache.logging.log4j.message.EntryMessage)

Example 60 with EntryMessage

use of org.apache.logging.log4j.message.EntryMessage in project meghanada-server by mopemope.

the class ClassScope method dumpFieldAccess.

@Override
public void dumpFieldAccess() {
    final EntryMessage entryMessage = log.traceEntry("**** {} {} methods:{}", this.getScopeType(), this.name, this.scopes.size());
    super.dumpFieldAccess(log);
    for (final ExpressionScope expressionScope : this.expressions) {
        expressionScope.dumpFieldAccess();
    }
    for (final BlockScope blockScope : this.scopes) {
        blockScope.dumpFieldAccess();
    }
    for (final ClassScope cs : this.classScopes) {
        cs.dumpFieldAccess();
    }
    log.traceExit(entryMessage);
}
Also used : EntryMessage(org.apache.logging.log4j.message.EntryMessage)

Aggregations

EntryMessage (org.apache.logging.log4j.message.EntryMessage)64 ArrayList (java.util.ArrayList)9 CachedASMReflector (meghanada.reflect.asm.CachedASMReflector)8 Test (org.junit.jupiter.api.Test)8 ClassScope (meghanada.analyze.ClassScope)5 MethodCall (meghanada.analyze.MethodCall)5 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 ExecutionException (java.util.concurrent.ExecutionException)3 Variable (meghanada.analyze.Variable)3 Project (meghanada.project.Project)3 ClassIndex (meghanada.reflect.ClassIndex)3 ClassNameUtils (meghanada.utils.ClassNameUtils)3 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 SignatureReader (org.objectweb.asm.signature.SignatureReader)3