use of org.jboss.windup.decompiler.util.Filter 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 org.jboss.windup.decompiler.util.Filter in project meghanada-server by mopemope.
the class LocationSearcher method getMethodLocationFromProject.
private Optional<Location> getMethodLocationFromProject(final String methodName, final List<String> arguments, final File file) {
try {
final Source declaringClassSrc = getSource(project, file);
final String path = declaringClassSrc.getFile().getPath();
return declaringClassSrc.getClassScopes().stream().flatMap(ts -> ts.getScopes().stream()).filter(bs -> {
if (!methodName.equals(bs.getName())) {
return false;
}
if (!(bs instanceof MethodScope)) {
return false;
}
final MethodScope methodScope = (MethodScope) bs;
final List<String> parameters = methodScope.getParameters();
return ClassNameUtils.compareArgumentType(arguments, parameters);
}).map(MethodScope.class::cast).map(ms -> new Location(path, ms.getBeginLine(), ms.getNameRange().begin.column)).findFirst();
} catch (ExecutionException e) {
throw new UncheckedExecutionException(e);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of org.jboss.windup.decompiler.util.Filter in project meghanada-server by mopemope.
the class LocationSearcher method searchDeclarationLocation.
public Optional<Location> searchDeclarationLocation(final File file, final int line, final int column, final String symbol) throws ExecutionException, IOException {
final Source source = getSource(project, file);
log.trace("search symbol {}", symbol);
return this.functions.stream().map(f -> f.apply(source, line, column, symbol)).filter(Optional::isPresent).findFirst().orElse(Optional.empty());
}
use of org.jboss.windup.decompiler.util.Filter in project meghanada-server by mopemope.
the class LocationSearcher method getFieldLocationFromProject.
private Optional<Location> getFieldLocationFromProject(final String fqcn, final String fieldName, final File file) {
try {
final Source declaringClassSrc = getSource(project, file);
final String path = declaringClassSrc.getFile().getPath();
return declaringClassSrc.getClassScopes().stream().map(cs -> getMatchField(cs, fqcn, fieldName)).filter(Optional::isPresent).map(optional -> {
final Variable variable = optional.get();
return new Location(path, variable.range.begin.line, variable.range.begin.column);
}).findFirst();
} catch (Exception e) {
throw new UncheckedExecutionException(e);
}
}
use of org.jboss.windup.decompiler.util.Filter in project meghanada-server by mopemope.
the class LocationSearcher method copyFromSrcZip.
private File copyFromSrcZip(final String searchFQCN, final File srcZip) throws IOException {
if (this.copiedSrcFile.containsKey(searchFQCN)) {
final File file = this.copiedSrcFile.get(searchFQCN);
if (file.exists()) {
return file;
}
// deleted
this.copiedSrcFile.remove(searchFQCN);
}
try (final ZipFile srcZipFile = new ZipFile(srcZip)) {
final String s = ClassNameUtils.replace(searchFQCN, ".", "/") + FileUtils.JAVA_EXT;
ZipEntry entry = srcZipFile.getEntry(s);
if (entry == null) {
Optional<? extends ZipEntry> zipEntry = srcZipFile.stream().filter(e -> {
Path p = Paths.get(e.getName());
if (p.getNameCount() < 2) {
return false;
}
Path subpath = p.subpath(1, p.getNameCount());
return subpath.toString().equals(s);
}).findFirst();
if (!zipEntry.isPresent()) {
return null;
}
entry = zipEntry.get();
}
String tmpdir = System.getProperty("java.io.tmpdir");
File tmpParent = new File(tmpdir);
if (!tmpParent.exists() && !tmpParent.mkdirs()) {
log.warn("fail create tmpdir");
}
// copy from src.zip
final File temp = File.createTempFile(TEMP_FILE_PREFIX, FileUtils.JAVA_EXT);
temp.deleteOnExit();
try (final InputStream inputStream = srcZipFile.getInputStream(entry);
final OutputStream outputStream = new FileOutputStream(temp)) {
final byte[] buf = new byte[1024];
int ret;
while ((ret = inputStream.read(buf)) != -1) {
outputStream.write(buf, 0, ret);
}
}
// reuse
this.copiedSrcFile.put(searchFQCN, temp);
return temp;
}
}
Aggregations