use of meghanada.reflect.asm.CachedASMReflector in project meghanada-server by mopemope.
the class CacheEventSubscriber method analyze.
private void analyze() {
final Stopwatch stopwatch = Stopwatch.createStarted();
final Session session = super.sessionEventBus.getSession();
final Project project = session.getCurrentProject();
final CachedASMReflector reflector = CachedASMReflector.getInstance();
reflector.addClasspath(project.getOutput());
reflector.addClasspath(project.getTestOutput());
project.getDependencies().stream().filter(pd -> pd.getType().equals(ProjectDependency.Type.PROJECT)).forEach(pd -> {
final File df = new File(pd.getDependencyFilePath());
if (df.exists() && df.isDirectory()) {
reflector.addClasspath(df);
}
});
final Collection<File> dependentJars = session.getDependentJars();
final int size = dependentJars.size();
timeItF("create class index ... read " + size + " jars. elapsed:{}", () -> {
reflector.addClasspath(dependentJars);
reflector.createClassIndexes();
});
if (cleanUnusedSource(project)) {
project.resetCallerMap();
}
log.info("start analyze sources ...");
timeItF("analyzed and compiled. elapsed:{}", () -> {
try {
final CompileResult compileResult = project.compileJava();
if (compileResult.isSuccess()) {
if (compileResult.hasDiagnostics()) {
log.warn("compile message: {}", compileResult.getDiagnosticsSummary());
}
final CompileResult testCompileResult = project.compileTestJava();
if (testCompileResult.isSuccess()) {
if (testCompileResult.hasDiagnostics()) {
log.warn("compile(test) message: {}", testCompileResult.getDiagnosticsSummary());
}
} else {
log.warn("compile(test) error: {}", testCompileResult.getDiagnosticsSummary());
}
} else {
log.warn("compile message {}", compileResult.getDiagnosticsSummary());
}
} catch (Exception e) {
log.catching(e);
}
});
final Runtime runtime = Runtime.getRuntime();
final float maxMemory = runtime.maxMemory() / 1024 / 1024;
final float totalMemory = runtime.totalMemory() / 1024 / 1024;
final float usedMemory = (runtime.totalMemory() - runtime.freeMemory()) / 1024 / 1024;
log.info("class index size:{} total elapsed:{}", reflector.getGlobalClassIndex().size(), stopwatch.stop());
Config.showMemory();
log.info("Ready");
}
use of meghanada.reflect.asm.CachedASMReflector in project meghanada-server by mopemope.
the class ClassNameUtils method compareVarArgumentType.
private static boolean compareVarArgumentType(List<String> arguments, List<String> parameters) {
final Iterator<String> iteratorA = arguments.iterator();
final CachedASMReflector reflector = CachedASMReflector.getInstance();
final int last = parameters.size() - 1;
int index = 0;
for (final String paramStr : parameters) {
if (index == last) {
return checkVarargs(iteratorA, paramStr);
} else {
final String realArgStr = iteratorA.next();
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());
index++;
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 TypeInfoSearcher method getMembers.
private static List<MemberDescriptor> getMembers(String fqcn, String clsName) {
List<MemberDescriptor> results = new ArrayList<>();
CachedASMReflector reflector = CachedASMReflector.getInstance();
for (MemberDescriptor md : reflector.reflect(fqcn)) {
CandidateUnit.MemberType type = md.getMemberType();
String nm = ClassNameUtils.getSimpleName(md.getDeclaringClass());
boolean own = clsName.equals(nm);
if (type == CandidateUnit.MemberType.CONSTRUCTOR) {
if (own) {
results.add(md);
}
} else {
if (md.isPrivate()) {
if (own) {
results.add(md);
}
} else {
results.add(md);
}
}
}
return results;
}
use of meghanada.reflect.asm.CachedASMReflector in project meghanada-server by mopemope.
the class GradleTestBase method setupReflector.
public static void setupReflector(boolean useCache) throws Exception {
setupProject(useCache);
CachedASMReflector cachedASMReflector = CachedASMReflector.getInstance();
cachedASMReflector.getGlobalClassIndex().clear();
addClasspath(cachedASMReflector);
final Stopwatch stopwatch = Stopwatch.createStarted();
cachedASMReflector.createClassIndexes();
log.info("createClassIndexes elapsed: {}", stopwatch.stop());
}
use of meghanada.reflect.asm.CachedASMReflector in project meghanada-server by mopemope.
the class TypeInfoSearcher method createTypeInfo.
private static TypeInfo createTypeInfo(String fqcn) {
CachedASMReflector reflector = CachedASMReflector.getInstance();
final String clsName = ClassNameUtils.getSimpleName(fqcn);
Optional<TypeInfo> typeInfo = reflector.containsClassIndex(fqcn).map(index -> createTypeInfo(fqcn, clsName));
return typeInfo.orElse(new TypeInfo(fqcn));
}
Aggregations