Search in sources :

Example 1 with CachedASMReflector

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");
}
Also used : SessionEventBus(meghanada.session.SessionEventBus) Stopwatch(com.google.common.base.Stopwatch) Collection(java.util.Collection) CompileResult(meghanada.analyze.CompileResult) Config.timeItF(meghanada.config.Config.timeItF) ProjectDatabaseHelper(meghanada.store.ProjectDatabaseHelper) CachedASMReflector(meghanada.reflect.asm.CachedASMReflector) File(java.io.File) Session(meghanada.session.Session) Logger(org.apache.logging.log4j.Logger) Project(meghanada.project.Project) Subscribe(com.google.common.eventbus.Subscribe) ProjectDependency(meghanada.project.ProjectDependency) Config(meghanada.config.Config) LogManager(org.apache.logging.log4j.LogManager) Project(meghanada.project.Project) CachedASMReflector(meghanada.reflect.asm.CachedASMReflector) Stopwatch(com.google.common.base.Stopwatch) CompileResult(meghanada.analyze.CompileResult) File(java.io.File) Session(meghanada.session.Session)

Example 2 with CachedASMReflector

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;
}
Also used : CachedASMReflector(meghanada.reflect.asm.CachedASMReflector)

Example 3 with CachedASMReflector

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;
}
Also used : CachedASMReflector(meghanada.reflect.asm.CachedASMReflector) MemberDescriptor(meghanada.reflect.MemberDescriptor) ArrayList(java.util.ArrayList) CandidateUnit(meghanada.reflect.CandidateUnit)

Example 4 with CachedASMReflector

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());
}
Also used : CachedASMReflector(meghanada.reflect.asm.CachedASMReflector) Stopwatch(com.google.common.base.Stopwatch)

Example 5 with CachedASMReflector

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));
}
Also used : CachedASMReflector(meghanada.reflect.asm.CachedASMReflector)

Aggregations

CachedASMReflector (meghanada.reflect.asm.CachedASMReflector)29 ArrayList (java.util.ArrayList)11 ClassIndex (meghanada.reflect.ClassIndex)9 EntryMessage (org.apache.logging.log4j.message.EntryMessage)9 File (java.io.File)8 HashSet (java.util.HashSet)8 CandidateUnit (meghanada.reflect.CandidateUnit)7 List (java.util.List)6 Map (java.util.Map)6 Optional (java.util.Optional)6 IOException (java.io.IOException)5 ClassScope (meghanada.analyze.ClassScope)5 Config (meghanada.config.Config)5 MemberDescriptor (meghanada.reflect.MemberDescriptor)5 LogManager (org.apache.logging.log4j.LogManager)5 Logger (org.apache.logging.log4j.Logger)5 Stopwatch (com.google.common.base.Stopwatch)4 UncheckedIOException (java.io.UncheckedIOException)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4