Search in sources :

Example 1 with EntryMessage

use of org.apache.logging.log4j.message.EntryMessage in project meghanada-server by mopemope.

the class Session method loadProject.

private static Optional<Project> loadProject(final File projectRoot, final String targetFile) throws IOException {
    final EntryMessage entryMessage = log.traceEntry("projectRoot={} targetFile={}", projectRoot, targetFile);
    final String projectRootPath = projectRoot.getCanonicalPath();
    Config.setProjectRoot(projectRootPath);
    try {
        final Config config = Config.load();
        final String id = FileUtils.findProjectID(projectRoot, targetFile);
        if (Project.loadedProject.containsKey(id)) {
            // loaded skip
            final Project project = Project.loadedProject.get(id);
            log.traceExit(entryMessage);
            Config.setProjectRoot(projectRootPath);
            return Optional.of(project);
        }
        log.trace("project projectID={} projectRoot={}", id, projectRoot);
        if (config.useFastBoot()) {
            try {
                final Project tempProject = Project.loadProject(projectRootPath);
                if (nonNull(tempProject) && tempProject.getId().equals(id)) {
                    tempProject.setId(id);
                    log.debug("load from cache project={}", tempProject);
                    log.info("load project from cache. projectRoot:{}", tempProject.getProjectRoot());
                    log.traceExit(entryMessage);
                    return Optional.of(tempProject.mergeFromProjectConfig());
                }
            } catch (Exception ex) {
                log.catching(ex);
            }
        }
        Project project;
        switch(targetFile) {
            case Project.GRADLE_PROJECT_FILE:
                project = new GradleProject(projectRoot);
                break;
            case Project.MVN_PROJECT_FILE:
                project = new MavenProject(projectRoot);
                break;
            default:
                project = new MeghanadaProject(projectRoot);
                break;
        }
        project.setId(id);
        final Stopwatch stopwatch = Stopwatch.createStarted();
        final Project parsed = project.parseProject();
        if (config.useFastBoot()) {
            parsed.saveProject();
        }
        log.info("loaded project:{} elapsed:{}", project.getProjectRoot(), stopwatch.stop());
        log.traceExit(entryMessage);
        return Optional.of(parsed.mergeFromProjectConfig());
    } finally {
        Config.setProjectRoot(projectRootPath);
    }
}
Also used : MavenProject(meghanada.project.maven.MavenProject) GradleProject(meghanada.project.gradle.GradleProject) Project(meghanada.project.Project) MeghanadaProject(meghanada.project.meghanada.MeghanadaProject) MavenProject(meghanada.project.maven.MavenProject) MeghanadaProject(meghanada.project.meghanada.MeghanadaProject) Config(meghanada.config.Config) Stopwatch(com.google.common.base.Stopwatch) GradleProject(meghanada.project.gradle.GradleProject) EntryMessage(org.apache.logging.log4j.message.EntryMessage) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with EntryMessage

use of org.apache.logging.log4j.message.EntryMessage in project meghanada-server by mopemope.

the class FieldAnalyzeVisitor method parseSignature.

FieldAnalyzeVisitor parseSignature() {
    final EntryMessage m = log.traceEntry("fieldSignature={}", fieldSignature);
    boolean isStatic = (Opcodes.ACC_STATIC & this.access) > 0;
    SignatureReader signatureReader = new SignatureReader(this.fieldSignature);
    FieldSignatureVisitor visitor;
    if (isStatic) {
        visitor = new FieldSignatureVisitor(this.name, new ArrayList<>(4));
    } else {
        visitor = new FieldSignatureVisitor(this.name, this.classAnalyzeVisitor.classTypeParameters);
    }
    if (this.typeMap != null) {
        visitor.setTypeMap(this.typeMap);
    }
    this.fieldSignatureVisitor = visitor;
    signatureReader.acceptType(fieldSignatureVisitor);
    return log.traceExit(m, this);
}
Also used : SignatureReader(org.objectweb.asm.signature.SignatureReader) ArrayList(java.util.ArrayList) EntryMessage(org.apache.logging.log4j.message.EntryMessage)

Example 3 with EntryMessage

use of org.apache.logging.log4j.message.EntryMessage in project meghanada-server by mopemope.

the class FieldSignatureVisitor method visitTypeArgument.

@Override
public void visitTypeArgument() {
    final EntryMessage m = log.traceEntry("mame={} typeInfo={} currentType={}", this.name, this.typeInfo, this.currentType);
    if (this.currentType.size() == 0) {
        this.visitClassType("?");
        log.traceExit();
        return;
    }
    final TypeInfo typeInfo = new TypeInfo("?", "?");
    final TypeInfo current = this.currentType.peek();
    if (current.typeParameters == null) {
        current.typeParameters = new ArrayList<>(4);
    }
    current.typeParameters.add(typeInfo);
    log.traceExit(m);
}
Also used : EntryMessage(org.apache.logging.log4j.message.EntryMessage)

Example 4 with EntryMessage

use of org.apache.logging.log4j.message.EntryMessage in project meghanada-server by mopemope.

the class FieldSignatureVisitor method visitBaseType.

@Override
public void visitBaseType(final char c) {
    final String primitive = ASMReflector.toPrimitive(c);
    final TypeInfo typeInfo = new TypeInfo(primitive, primitive);
    if (this.typeInfo == null) {
        this.typeInfo = typeInfo;
        if (this.holdArray) {
            this.typeInfo.isArray = true;
            this.holdArray = false;
        }
    }
    if (this.currentType.size() == 0) {
        // set main
        this.currentType.push(typeInfo);
    }
    final EntryMessage em = log.traceEntry("c={} name={} typeInfo={} currentType={}", c, this.name, this.typeInfo, this.currentType);
    log.traceExit(em);
}
Also used : EntryMessage(org.apache.logging.log4j.message.EntryMessage)

Example 5 with EntryMessage

use of org.apache.logging.log4j.message.EntryMessage in project meghanada-server by mopemope.

the class FieldSignatureVisitor method visitClassType.

@Override
public void visitClassType(final String s) {
    final String className = ClassNameUtils.replaceSlash(s);
    final TypeInfo typeInfo = new TypeInfo(className, className);
    if (this.typeInfo == null) {
        this.typeInfo = typeInfo;
        if (this.holdArray) {
            this.typeInfo.isArray = true;
            this.holdArray = false;
        }
    }
    final EntryMessage em = log.traceEntry("s={} name={} typeInfo={} currentType={}", s, this.name, this.typeInfo, this.currentType);
    if (this.currentType.size() == 0) {
        // set main
        this.currentType.push(typeInfo);
    } else {
        final TypeInfo current = this.currentType.peek();
        if (current != null && current.typeParameters != null && isInstance) {
            current.typeParameters.add(typeInfo);
            // swap
            this.currentType.push(typeInfo);
        }
    }
    log.traceExit(em);
}
Also used : EntryMessage(org.apache.logging.log4j.message.EntryMessage)

Aggregations

EntryMessage (org.apache.logging.log4j.message.EntryMessage)64 ArrayList (java.util.ArrayList)9 CachedASMReflector (meghanada.reflect.asm.CachedASMReflector)8 Test (org.junit.jupiter.api.Test)8 ClassScope (meghanada.analyze.ClassScope)5 MethodCall (meghanada.analyze.MethodCall)5 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 HashSet (java.util.HashSet)3 List (java.util.List)3 Map (java.util.Map)3 Set (java.util.Set)3 ExecutionException (java.util.concurrent.ExecutionException)3 Variable (meghanada.analyze.Variable)3 Project (meghanada.project.Project)3 ClassIndex (meghanada.reflect.ClassIndex)3 ClassNameUtils (meghanada.utils.ClassNameUtils)3 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 SignatureReader (org.objectweb.asm.signature.SignatureReader)3