Search in sources :

Example 1 with AstVisitor

use of lombok.ast.AstVisitor in project kotlin by JetBrains.

the class JavaVisitor method visitFile.

void visitFile(@NonNull JavaContext context) {
    Node compilationUnit = null;
    try {
        compilationUnit = mParser.parseJava(context);
        if (compilationUnit == null) {
            // with details, location, etc.
            return;
        }
        context.setCompilationUnit(compilationUnit);
        for (VisitingDetector v : mAllDetectors) {
            v.setContext(context);
            v.getDetector().beforeCheckFile(context);
        }
        if (!mSuperClassDetectors.isEmpty()) {
            SuperclassVisitor visitor = new SuperclassVisitor(context);
            compilationUnit.accept(visitor);
        }
        for (VisitingDetector v : mFullTreeDetectors) {
            AstVisitor visitor = v.getVisitor();
            compilationUnit.accept(visitor);
        }
        if (!mMethodDetectors.isEmpty() || !mResourceFieldDetectors.isEmpty() || !mConstructorDetectors.isEmpty()) {
            AstVisitor visitor = new DelegatingJavaVisitor(context);
            compilationUnit.accept(visitor);
        } else if (!mNodeTypeDetectors.isEmpty()) {
            AstVisitor visitor = new DispatchVisitor();
            compilationUnit.accept(visitor);
        }
        for (VisitingDetector v : mAllDetectors) {
            v.getDetector().afterCheckFile(context);
        }
    } catch (RuntimeException e) {
        if (sExceptionCount++ > MAX_REPORTED_CRASHES) {
            // are tripping up ECJ, they get the picture.
            return;
        }
        if (e.getClass().getSimpleName().equals("IndexNotReadyException")) {
            // See http://b.android.com/176644 for an example.
            return;
        } else if (e.getClass().getSimpleName().equals("ProcessCanceledException")) {
            // Cancelling inspections in the IDE
            context.getDriver().cancel();
            return;
        }
        // Work around ECJ bugs; see https://code.google.com/p/android/issues/detail?id=172268
        // Don't allow lint bugs to take down the whole build. TRY to log this as a
        // lint error instead!
        StringBuilder sb = new StringBuilder(100);
        sb.append("Unexpected failure during lint analysis of ");
        sb.append(context.file.getName());
        sb.append(" (this is a bug in lint or one of the libraries it depends on)\n");
        sb.append(e.getClass().getSimpleName());
        sb.append(':');
        StackTraceElement[] stackTrace = e.getStackTrace();
        int count = 0;
        for (StackTraceElement frame : stackTrace) {
            if (count > 0) {
                sb.append("<-");
            }
            String className = frame.getClassName();
            sb.append(className.substring(className.lastIndexOf('.') + 1));
            sb.append('.').append(frame.getMethodName());
            sb.append('(');
            sb.append(frame.getFileName()).append(':').append(frame.getLineNumber());
            sb.append(')');
            count++;
            // Only print the top 3-4 frames such that we can identify the bug
            if (count == 4) {
                break;
            }
        }
        // NOT e: this makes for very noisy logs
        Throwable throwable = null;
        //noinspection ConstantConditions
        context.log(throwable, sb.toString());
    } finally {
        if (compilationUnit != null) {
            mParser.dispose(context, compilationUnit);
        }
    }
}
Also used : Node(lombok.ast.Node) ResolvedNode(com.android.tools.klint.client.api.JavaParser.ResolvedNode) AstVisitor(lombok.ast.AstVisitor) ForwardingAstVisitor(lombok.ast.ForwardingAstVisitor)

Aggregations

ResolvedNode (com.android.tools.klint.client.api.JavaParser.ResolvedNode)1 AstVisitor (lombok.ast.AstVisitor)1 ForwardingAstVisitor (lombok.ast.ForwardingAstVisitor)1 Node (lombok.ast.Node)1