use of meghanada.reflect.ClassIndex in project meghanada-server by mopemope.
the class ASMReflector method getClasses.
Map<ClassIndex, File> getClasses(final File file) throws IOException {
final Map<ClassIndex, File> indexes = new ConcurrentHashMap<>(32);
if (ModuleHelper.isJrtFsFile(file)) {
ModuleHelper.walkModule(path -> ModuleHelper.pathToClassData(path).ifPresent(cd -> {
String className = cd.getClassName();
String moduleName = cd.getModuleName();
if (this.ignorePackage(className)) {
return;
}
try (final InputStream in = cd.getInputStream()) {
ASMReflector.readClassIndex(indexes, in, file, false);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}));
} else if (file.isFile() && file.getName().endsWith("jar")) {
try (final JarFile jarFile = new JarFile(file);
final Stream<JarEntry> jarStream = jarFile.stream().parallel();
final Stream<JarEntry> stream = jarStream.filter(jarEntry -> jarEntry.getName().endsWith(".class")).collect(Collectors.toList()).parallelStream()) {
stream.forEach(wrapIOConsumer(jarEntry -> {
final String entryName = jarEntry.getName();
if (!entryName.endsWith(".class")) {
return;
}
final String className = ClassNameUtils.replaceSlash(entryName.substring(0, entryName.length() - 6));
if (this.ignorePackage(className)) {
return;
}
try (final InputStream in = jarFile.getInputStream(jarEntry)) {
ASMReflector.readClassIndex(indexes, in, file, false);
}
}));
}
} else if (file.isFile() && file.getName().endsWith(".class")) {
final String entryName = file.getName();
if (!entryName.endsWith(".class")) {
return indexes;
}
final String className = ClassNameUtils.replaceSlash(entryName.substring(0, entryName.length() - 6));
if (this.ignorePackage(className)) {
return indexes;
}
try (final InputStream in = new FileInputStream(file)) {
ASMReflector.readClassIndex(indexes, in, file, true);
}
} else if (file.isDirectory()) {
try (final Stream<Path> pathStream = Files.walk(file.toPath());
final Stream<File> stream = pathStream.map(Path::toFile).filter(f -> f.isFile() && f.getName().endsWith(".class")).collect(Collectors.toList()).stream()) {
stream.forEach(wrapIOConsumer(classFile -> {
final String entryName = classFile.getName();
if (!entryName.endsWith(".class")) {
return;
}
final String className = ClassNameUtils.replaceSlash(entryName.substring(0, entryName.length() - 6));
if (this.ignorePackage(className)) {
return;
}
try (final InputStream in = new FileInputStream(classFile)) {
ASMReflector.readClassIndex(indexes, in, file, true);
}
}));
}
}
return indexes;
}
use of meghanada.reflect.ClassIndex in project meghanada-server by mopemope.
the class ASMReflector method readSuperMembers.
private void readSuperMembers(File parent, ClassAnalyzeVisitor cv, List<MemberDescriptor> units) {
final ClassIndex classIndex = cv.getClassIndex();
List<List<MemberDescriptor>> lists = classIndex.getSupers().stream().parallel().map(wrapIO(s -> reflect(parent, s))).collect(Collectors.toList());
lists.forEach(units::addAll);
}
use of meghanada.reflect.ClassIndex in project meghanada-server by mopemope.
the class CachedASMReflector method addClassIndex.
private void addClassIndex(ClassIndex newIndex, File file) {
final String fqcn = newIndex.getRawDeclaration();
ClassIndex old = this.globalClassIndex.get(fqcn);
if (nonNull(old)) {
EntityId entityId = old.getEntityId();
if (nonNull(entityId)) {
// inheriting entityID
newIndex.setEntityID(entityId);
}
}
try {
if (ModuleHelper.isJrtFsFile(file)) {
newIndex.setFilePath(file.getPath());
} else {
newIndex.setFilePath(file.getCanonicalPath());
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
this.globalClassIndex.put(fqcn, newIndex);
}
use of meghanada.reflect.ClassIndex in project meghanada-server by mopemope.
the class ProjectDatabaseHelper method getClassIndexLinks.
public static void getClassIndexLinks(String fqcn, String linkName, Consumer<EntityIterable> fn) throws Exception {
Map<String, ClassIndex> globalClassIndex = CachedASMReflector.getInstance().getGlobalClassIndex();
if (!globalClassIndex.containsKey(fqcn)) {
return;
}
ClassIndex index = globalClassIndex.get(fqcn);
EntityId entityId = index.getEntityId();
ProjectDatabase database = ProjectDatabase.getInstance();
boolean result = database.execute(txn -> {
Entity classEntity = txn.getEntity(entityId);
EntityIterable iterable = classEntity.getLinks(linkName);
fn.accept(iterable);
return true;
});
}
use of meghanada.reflect.ClassIndex in project meghanada-server by mopemope.
the class TypeInfoSearcher method searchClassCondition.
private static Optional<String> searchClassCondition(Source source, int line, int col, String symbol) {
final CachedASMReflector reflector = CachedASMReflector.getInstance();
Optional<String> result;
String fqcn = source.getImportedClassFQCN(symbol, null);
if (isNull(fqcn)) {
if (!source.getPackageName().isEmpty() && !symbol.isEmpty()) {
fqcn = source.getPackageName() + '.' + symbol;
result = reflector.containsClassIndex(fqcn).map(index -> {
return Optional.of(index.getDeclaration());
}).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)) {
return Optional.of(returnType);
}
}
return Optional.empty();
});
} else {
result = Optional.empty();
}
} else {
result = Optional.of(fqcn);
}
return result;
}
Aggregations