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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations