Search in sources :

Example 16 with EntryMessage

use of org.apache.logging.log4j.message.EntryMessage 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;
}
Also used : CachedASMReflector(meghanada.reflect.asm.CachedASMReflector) MemberDescriptor(meghanada.reflect.MemberDescriptor) EntryMessage(org.apache.logging.log4j.message.EntryMessage) MethodCall(meghanada.analyze.MethodCall)

Example 17 with EntryMessage

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

the class LocationSearcher method searchClassOrInterface.

private Optional<Location> searchClassOrInterface(final Source source, final int line, final int col, String symbol) {
    final EntryMessage entryMessage = log.traceEntry("line={} col={} symbol={}", line, col, symbol);
    if (symbol.startsWith("@")) {
        symbol = symbol.substring(1);
    }
    final List<String> searchTargets = new ArrayList<>(4);
    String fqcn = source.getImportedClassFQCN(symbol, null);
    if (fqcn == null) {
        final CachedASMReflector reflector = CachedASMReflector.getInstance();
        final Map<String, String> standardClasses = reflector.getStandardClasses();
        fqcn = standardClasses.get(symbol);
        if (fqcn == null) {
            if (!source.getPackageName().isEmpty()) {
                fqcn = source.getPackageName() + '.' + symbol;
            } else {
                fqcn = symbol;
            }
            searchTargets.add(fqcn);
            // Add inner class
            final String finalSym = symbol;
            source.getTypeScope(line).ifPresent(typeScope -> {
                final String firstFQCN = typeScope.getFQCN();
                searchTargets.add(firstFQCN + ClassNameUtils.INNER_MARK + finalSym);
            });
        }
    } else {
        searchTargets.add(fqcn);
    }
    final Optional<Location> location = searchTargets.stream().map(this::getFQCNLocation).filter(Objects::nonNull).findFirst();
    log.traceExit(entryMessage);
    return location;
}
Also used : CachedASMReflector(meghanada.reflect.asm.CachedASMReflector) ArrayList(java.util.ArrayList) EntryMessage(org.apache.logging.log4j.message.EntryMessage)

Example 18 with EntryMessage

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

the class LocationSearcher method searchMethodCall.

private Optional<Location> searchMethodCall(final Source source, final int line, final int 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<Location> result = methodCall.flatMap(mc -> {
        final String methodName = mc.name;
        final List<String> arguments = mc.getArguments();
        final String declaringClass = mc.declaringClass;
        if (declaringClass == null) {
            return Optional.empty();
        }
        final List<String> searchTargets = new ArrayList<>(2);
        searchTargets.add(declaringClass);
        final CachedASMReflector reflector = CachedASMReflector.getInstance();
        searchTargets.addAll(reflector.getSuperClass(declaringClass));
        return searchTargets.stream().map(targetFqcn -> existsFQCN(project.getAllSourcesWithDependencies(), targetFqcn).flatMap(file -> getMethodLocationFromProject(methodName, arguments, file)).orElseGet(wrapIO(() -> {
            final SearchContext context = new SearchContext(targetFqcn, SearchKind.METHOD);
            context.name = methodName;
            context.arguments = arguments;
            return Optional.ofNullable(searchFromSrcZip(context)).orElseGet(wrapIO(() -> searchFromDependency(context)));
        }))).filter(Objects::nonNull).findFirst();
    });
    log.traceExit(entryMessage);
    return result;
}
Also used : CachedASMReflector(meghanada.reflect.asm.CachedASMReflector) ArrayList(java.util.ArrayList) EntryMessage(org.apache.logging.log4j.message.EntryMessage) MethodCall(meghanada.analyze.MethodCall)

Example 19 with EntryMessage

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

the class LocationSearcher method searchLocalVariable.

private Optional<Location> searchLocalVariable(final Source source, final int line, final int col, final String symbol) {
    final EntryMessage entryMessage = log.traceEntry("line={} col={} symbol={}", line, col, symbol);
    final Map<String, Variable> variableMap = source.getVariableMap(line);
    log.trace("variables={}", variableMap);
    final Optional<Variable> variable = Optional.ofNullable(variableMap.get(symbol));
    final Optional<Location> location = variable.map(var -> {
        if (var.isDecl()) {
            final Location loc = new Location(source.getFile().getPath(), var.range.begin.line, var.range.begin.column);
            return Optional.of(loc);
        } else {
            final String fqcn = var.fqcn;
            final Location loc = getFQCNLocation(fqcn);
            return Optional.ofNullable(loc);
        }
    }).orElseGet(() -> {
        // isField
        final Optional<TypeScope> ts = source.getTypeScope(line);
        if (!ts.isPresent()) {
            return Optional.empty();
        }
        return ts.get().getField(symbol).map(fieldSymbol -> new Location(source.getFile().getPath(), fieldSymbol.range.begin.line, fieldSymbol.range.begin.column));
    });
    log.traceExit(entryMessage);
    return location;
}
Also used : DecompilationListener(org.jboss.windup.decompiler.api.DecompilationListener) FunctionUtils.wrapIOConsumer(meghanada.utils.FunctionUtils.wrapIOConsumer) ConstructorDeclaration(com.github.javaparser.ast.body.ConstructorDeclaration) Map(java.util.Map) ZipFile(java.util.zip.ZipFile) MethodCall(meghanada.analyze.MethodCall) CompilationUnit(com.github.javaparser.ast.CompilationUnit) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) FunctionUtils.wrapIO(meghanada.utils.FunctionUtils.wrapIO) GlobalCache(meghanada.cache.GlobalCache) SimpleName(com.github.javaparser.ast.expr.SimpleName) TypeDeclaration(com.github.javaparser.ast.body.TypeDeclaration) StandardOpenOption(java.nio.file.StandardOpenOption) StandardCharsets(java.nio.charset.StandardCharsets) UncheckedIOException(java.io.UncheckedIOException) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) MethodScope(meghanada.analyze.MethodScope) ClassNameUtils(meghanada.utils.ClassNameUtils) Optional(java.util.Optional) Project(meghanada.project.Project) Pattern(java.util.regex.Pattern) ProjectDependency(meghanada.project.ProjectDependency) Config(meghanada.config.Config) Parameter(com.github.javaparser.ast.body.Parameter) Position(com.github.javaparser.Position) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator) Variable(meghanada.analyze.Variable) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ClassScope(meghanada.analyze.ClassScope) OutputStream(java.io.OutputStream) Filter(org.jboss.windup.decompiler.util.Filter) DecompilationResult(org.jboss.windup.decompiler.api.DecompilationResult) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) BodyDeclaration(com.github.javaparser.ast.body.BodyDeclaration) FileOutputStream(java.io.FileOutputStream) FileUtils.existsFQCN(meghanada.utils.FileUtils.existsFQCN) IOException(java.io.IOException) CachedASMReflector(meghanada.reflect.asm.CachedASMReflector) FileUtils(meghanada.utils.FileUtils) EntryMessage(org.apache.logging.log4j.message.EntryMessage) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) FieldDeclaration(com.github.javaparser.ast.body.FieldDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) Paths(java.nio.file.Paths) Source(meghanada.analyze.Source) FernflowerDecompiler(org.jboss.windup.decompiler.fernflower.FernflowerDecompiler) TypeScope(meghanada.analyze.TypeScope) LogManager(org.apache.logging.log4j.LogManager) JavaParser(com.github.javaparser.JavaParser) InputStream(java.io.InputStream) Variable(meghanada.analyze.Variable) TypeScope(meghanada.analyze.TypeScope) EntryMessage(org.apache.logging.log4j.message.EntryMessage)

Example 20 with EntryMessage

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

the class ExpressionScope method dumpFieldAccess.

@Override
public void dumpFieldAccess() {
    EntryMessage em = log.traceEntry("**** {} {}", this.getClassName(), this.range);
    super.dumpFieldAccess(log);
    log.traceExit(em);
}
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