use of meghanada.reflect.asm.CachedASMReflector in project meghanada-server by mopemope.
the class Session method reloadProject.
public void reloadProject() throws IOException {
final Project currentProject = this.currentProject;
final File projectRoot = currentProject.getProjectRoot();
this.projects.clear();
if (currentProject instanceof GradleProject) {
loadProject(projectRoot, Project.GRADLE_PROJECT_FILE).ifPresent(project -> {
boolean ret = setProject(projectRoot, project);
});
} else if (currentProject instanceof MavenProject) {
loadProject(projectRoot, Project.MVN_PROJECT_FILE).ifPresent(project -> {
boolean ret = setProject(projectRoot, project);
});
} else {
loadProject(projectRoot, Config.MEGHANADA_CONF_FILE).ifPresent(project -> {
boolean ret = setProject(projectRoot, project);
});
}
final Set<File> temp = new HashSet<>(this.currentProject.getSources());
temp.addAll(this.currentProject.getTestSources());
this.sessionEventBus.requestWatchFiles(new ArrayList<>(temp));
final CachedASMReflector reflector = CachedASMReflector.getInstance();
reflector.addClasspath(Session.getSystemJars());
this.sessionEventBus.requestCreateCache();
this.projects.values().forEach(project -> this.sessionEventBus.requestWatchFile(project.getProjectRoot()));
}
use of meghanada.reflect.asm.CachedASMReflector 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;
}
use of meghanada.reflect.asm.CachedASMReflector in project meghanada-server by mopemope.
the class ClassNameUtils method compareArgumentType.
public static boolean compareArgumentType(final List<String> arguments, final List<String> parameters) {
if (!parameters.isEmpty() && parameters.size() > 0 && arguments.size() > parameters.size()) {
final String last = parameters.get(parameters.size() - 1);
final boolean isVarargs = last.endsWith(ClassNameUtils.ARRAY);
if (isVarargs) {
return compareVarArgumentType(arguments, parameters);
}
}
if (arguments.size() != parameters.size()) {
return false;
}
final Iterator<String> iteratorA = arguments.iterator();
final CachedASMReflector reflector = CachedASMReflector.getInstance();
for (final String paramStr : parameters) {
final String realArgStr = iteratorA.next();
if (realArgStr == null) {
return false;
}
if (realArgStr.equals("<null>")) {
// match all
continue;
}
if (ClassNameUtils.isArray(paramStr) != ClassNameUtils.isArray(realArgStr)) {
return false;
}
final ClassName paramClass = new ClassName(paramStr);
final ClassName argClass = new ClassName(realArgStr);
final String paramClassName = autoBoxing(paramClass.getName());
final String argClassName = autoBoxing(argClass.getName());
if (paramClassName.equals(argClassName)) {
continue;
}
if (implicitTypeCastMap.containsKey(argClassName)) {
Set<String> types = implicitTypeCastMap.get(argClassName);
if (types.contains(paramClassName)) {
continue;
}
}
final boolean result = reflector.getSuperClassStream(argClassName).anyMatch(s -> {
final String cls = new ClassName(s).getName();
return cls.equals(paramClassName);
});
if (!result) {
return false;
}
}
return true;
}
use of meghanada.reflect.asm.CachedASMReflector in project meghanada-server by mopemope.
the class GradleProjectTest method setupReflector.
private void setupReflector(Project p) {
CachedASMReflector cachedASMReflector = CachedASMReflector.getInstance();
cachedASMReflector.addClasspath(getSystemJars());
cachedASMReflector.addClasspath(getJars(p));
cachedASMReflector.addClasspath(p.getOutput());
cachedASMReflector.addClasspath(p.getTestOutput());
cachedASMReflector.createClassIndexes();
}
use of meghanada.reflect.asm.CachedASMReflector in project meghanada-server by mopemope.
the class TreeAnalyzer method markFQCN.
private static String markFQCN(Source src, String fqcn, boolean markUnUse) {
if (fqcn.equals("void")) {
return fqcn;
}
if (fqcn.startsWith("capture of") || fqcn.equals("any") || fqcn.equals("<any>")) {
// log.warn("unknown type={}", fqcn);
return fqcn;
}
String simpleName = ClassNameUtils.removeTypeAndArray(fqcn);
simpleName = ClassNameUtils.removeWildcard(simpleName);
if (ClassNameUtils.isPrimitive(simpleName)) {
return fqcn;
}
// checkLoadable(src, fqcn, simpleName);
for (String s : ClassNameUtils.parseTypeParameter(fqcn)) {
if (s.startsWith(ClassNameUtils.CAPTURE_OF)) {
String cls = ClassNameUtils.removeCapture(s);
if (cls.equals(ClassNameUtils.CAPTURE_OF)) {
String ignore = markFQCN(src, ClassNameUtils.OBJECT_CLASS);
} else {
String ignore = markFQCN(src, cls);
}
} else {
String ignore = markFQCN(src, s);
}
}
CachedASMReflector cachedASMReflector = CachedASMReflector.getInstance();
Map<String, ClassIndex> classIndex = cachedASMReflector.getGlobalClassIndex();
if (!src.importClasses.contains(simpleName) && !classIndex.containsKey(simpleName)) {
src.addUnknown(simpleName);
} else {
if (markUnUse) {
// contains
String name = ClassNameUtils.replaceInnerMark(simpleName);
if (src.unused.contains(name)) {
src.unused.remove(name);
}
int i = simpleName.indexOf('$');
if (i > 0) {
String parentClass = simpleName.substring(0, i);
if (src.unused.contains(parentClass)) {
src.unused.remove(parentClass);
}
}
}
File classFile = cachedASMReflector.getClassFile(simpleName);
if (isNull(classFile) || !classFile.getName().endsWith(".jar")) {
src.usingClasses.add(simpleName);
}
}
return fqcn;
}
Aggregations