use of meghanada.reflect.asm.CachedASMReflector in project meghanada-server by mopemope.
the class DeclarationSearcher method searchClassOrInterface.
private static Optional<Declaration> searchClassOrInterface(final Source source, final Integer line, final Integer col, final String symbol) {
// TODO need tune
final EntryMessage entryMessage = log.traceEntry("line={} col={} symbol={}", line, col, symbol);
final CachedASMReflector reflector = CachedASMReflector.getInstance();
Optional<Declaration> result;
String fqcn = source.getImportedClassFQCN(symbol, null);
if (fqcn == null) {
if (!source.getPackageName().isEmpty()) {
fqcn = source.getPackageName() + '.' + symbol;
result = reflector.containsClassIndex(fqcn).map(classIndex -> {
final Declaration declaration = new Declaration(symbol, classIndex.getReturnType(), Declaration.Type.CLASS, 0);
return Optional.of(declaration);
}).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 ci : reflector.searchInnerClasses(parents)) {
final String returnType = ci.getReturnType();
if (returnType.endsWith(symbol)) {
final Declaration d = new Declaration(symbol, returnType, Declaration.Type.CLASS, 0);
return Optional.of(d);
}
}
return Optional.empty();
});
} else {
result = Optional.empty();
}
} else {
final Declaration declaration = new Declaration(symbol, fqcn, Declaration.Type.CLASS, 0);
result = Optional.of(declaration);
}
log.traceExit(entryMessage);
return result;
}
use of meghanada.reflect.asm.CachedASMReflector in project meghanada-server by mopemope.
the class LocationSearcher method searchFieldAccess.
private Optional<Location> searchFieldAccess(final Source src, final int line, final int col, final String symbol) {
final EntryMessage entryMessage = log.traceEntry("line={} col={} symbol={}", line, col, symbol);
final Optional<Location> result = src.searchFieldAccess(line, col, symbol).flatMap(fa -> {
final String fieldName = fa.name;
final String declaringClass = fa.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(fqcn -> existsFQCN(project.getAllSourcesWithDependencies(), fqcn).flatMap(file -> getFieldLocationFromProject(fqcn, fieldName, file)).orElseGet(wrapIO(() -> {
final SearchContext context = new SearchContext(fqcn, SearchKind.FIELD);
context.name = fieldName;
return Optional.ofNullable(searchFromSrcZip(context)).orElseGet(wrapIO(() -> searchFromDependency(context)));
}))).filter(Objects::nonNull).findFirst();
});
log.traceExit(entryMessage);
return result;
}
use of meghanada.reflect.asm.CachedASMReflector 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;
}
use of meghanada.reflect.asm.CachedASMReflector in project meghanada-server by mopemope.
the class MemberCacheLoader method storeMembers.
private void storeMembers(final String fqcn, final List<MemberDescriptor> list) {
final CachedASMReflector reflector = CachedASMReflector.getInstance();
reflector.containsClassIndex(fqcn).map(wrapIO(index -> ProjectDatabaseHelper.saveMemberDescriptors(index.getRawDeclaration(), list))).orElseGet(() -> {
final String innerFQCN = ClassNameUtils.replaceInnerMark(fqcn);
reflector.containsClassIndex(innerFQCN).ifPresent(wrapIOConsumer(index -> ProjectDatabaseHelper.saveMemberDescriptors(index.getRawDeclaration(), list)));
return true;
});
}
Aggregations