use of meghanada.reflect.asm.CachedASMReflector in project meghanada-server by mopemope.
the class ProjectDependency method getDependencyFilePath.
public String getDependencyFilePath() {
try {
if (type.equals(Type.PROJECT)) {
if (nonNull(this.dependencyFilePath)) {
return this.dependencyFilePath;
}
// get gradle's project archive
final File projectArchive = new File(file, "build" + File.separator + "libs" + File.separator + this.id + ".jar");
if (projectArchive.exists()) {
// add index
final List<File> temp = new ArrayList<>(1);
temp.add(projectArchive);
final CachedASMReflector reflector = CachedASMReflector.getInstance();
reflector.createClassIndexes(temp);
this.dependencyFilePath = projectArchive.getCanonicalPath();
} else {
if (nonNull(this.dependencyFilePath)) {
return this.dependencyFilePath;
}
String root = Config.getProjectRoot();
try {
final File output = getProjectOutput();
this.dependencyFilePath = output.getCanonicalPath();
} finally {
Config.setProjectRoot(root);
}
}
return this.dependencyFilePath;
} else {
return file.getCanonicalPath();
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of meghanada.reflect.asm.CachedASMReflector 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 meghanada.reflect.asm.CachedASMReflector in project meghanada-server by mopemope.
the class TestRunner method getTestClass.
private List<Class<?>> getTestClass(String testName) throws ClassNotFoundException {
List<Class<?>> classes = new ArrayList<>();
CachedASMReflector cachedASMReflector = CachedASMReflector.getInstance();
for (ClassIndex classIndex : cachedASMReflector.getGlobalClassIndex().values()) {
String fqcn = classIndex.getReturnType();
String className = classIndex.getName();
if (fqcn.equals(testName) || className.equals(testName) || fqcn.matches(testName)) {
classes.add(Class.forName(fqcn));
}
}
return classes;
}
use of meghanada.reflect.asm.CachedASMReflector in project meghanada-server by mopemope.
the class LocationSearcher method searchFromDependency.
private Location searchFromDependency(final SearchContext context) throws IOException {
final String searchFQCN = context.searchFQCN;
final CachedASMReflector reflector = CachedASMReflector.getInstance();
final File classFile = reflector.getClassFile(searchFQCN);
final String tempDir = System.getProperty("java.io.tmpdir");
if (classFile != null && classFile.exists() && classFile.getName().endsWith(FileUtils.JAR_EXT)) {
final String androidHome = System.getenv("ANDROID_HOME");
if (androidHome != null) {
final Optional<ProjectDependency> dependencyOptional = this.project.getDependencies().stream().filter(dependency -> dependency.getFile().equals(classFile)).findFirst();
if (dependencyOptional.isPresent()) {
final ProjectDependency dependency = dependencyOptional.get();
final String sourceJar = ClassNameUtils.getSimpleName(dependency.getId()) + '-' + dependency.getVersion() + "-sources.jar";
final File root = new File(androidHome, "extras");
if (root.exists()) {
return getLocationFromSrcOrDecompile(context, classFile, root, sourceJar);
}
}
}
final File depParent = classFile.getParentFile();
final File dependencyDir = depParent.getParentFile();
final String srcJarName = ClassNameUtils.replace(classFile.getName(), FileUtils.JAR_EXT, "-sources.jar");
final String disable = System.getProperty("disable-source-jar");
if (disable != null && disable.equals("true")) {
return searchLocationFromDecompileFile(context, searchFQCN, classFile, tempDir);
}
return getLocationFromSrcOrDecompile(context, classFile, dependencyDir, srcJarName);
}
return null;
}
use of meghanada.reflect.asm.CachedASMReflector 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;
}
Aggregations