Class ErrorProneScanner

java.lang.Object
com.sun.source.util.TreeScanner<Void,VisitorState>
com.sun.source.util.TreePathScanner<Void,VisitorState>
com.google.errorprone.scanner.Scanner
com.google.errorprone.scanner.ErrorProneScanner
All Implemented Interfaces:
com.sun.source.tree.TreeVisitor<Void,VisitorState>

public class ErrorProneScanner extends Scanner
Scans the parsed AST, looking for violations of any of the enabled checks.
Author:
Alex Eagle (alexeagle@google.com)
  • Constructor Details

    • ErrorProneScanner

      public ErrorProneScanner(BugChecker... checkers)
      Create an error-prone scanner for the given checkers.
      Parameters:
      checkers - The checkers that this scanner should use.
    • ErrorProneScanner

      public ErrorProneScanner(Iterable<BugChecker> checkers)
      Create an error-prone scanner for a non-hardcoded set of checkers.
      Parameters:
      checkers - The checkers that this scanner should use.
    • ErrorProneScanner

      public ErrorProneScanner(Iterable<BugChecker> checkers, Map<String,BugPattern.SeverityLevel> severities)
      Create an error-prone scanner for a non-hardcoded set of checkers.
      Parameters:
      checkers - The checkers that this scanner should use.
      severities - The default check severities.
  • Method Details

    • getCustomSuppressionAnnotations

      protected Set<? extends com.sun.tools.javac.util.Name> getCustomSuppressionAnnotations(VisitorState state)
      Description copied from class: Scanner
      Returns a set of all the custom suppression annotation types used by the BugCheckers in thisScanner.
      Overrides:
      getCustomSuppressionAnnotations in class Scanner
    • visitAnnotation

      public Void visitAnnotation(com.sun.source.tree.AnnotationTree tree, VisitorState visitorState)
      Specified by:
      visitAnnotation in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitAnnotation in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitAnnotatedType

      public Void visitAnnotatedType(com.sun.source.tree.AnnotatedTypeTree tree, VisitorState visitorState)
      Specified by:
      visitAnnotatedType in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitAnnotatedType in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitArrayAccess

      public Void visitArrayAccess(com.sun.source.tree.ArrayAccessTree tree, VisitorState visitorState)
      Specified by:
      visitArrayAccess in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitArrayAccess in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitArrayType

      public Void visitArrayType(com.sun.source.tree.ArrayTypeTree tree, VisitorState visitorState)
      Specified by:
      visitArrayType in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitArrayType in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitAssert

      public Void visitAssert(com.sun.source.tree.AssertTree tree, VisitorState visitorState)
      Specified by:
      visitAssert in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitAssert in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitAssignment

      public Void visitAssignment(com.sun.source.tree.AssignmentTree tree, VisitorState visitorState)
      Specified by:
      visitAssignment in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitAssignment in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitBinary

      public Void visitBinary(com.sun.source.tree.BinaryTree tree, VisitorState visitorState)
      Specified by:
      visitBinary in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitBinary in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitBlock

      public Void visitBlock(com.sun.source.tree.BlockTree tree, VisitorState visitorState)
      Specified by:
      visitBlock in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitBlock in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitBreak

      public Void visitBreak(com.sun.source.tree.BreakTree tree, VisitorState visitorState)
      Specified by:
      visitBreak in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitBreak in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitCase

      public Void visitCase(com.sun.source.tree.CaseTree tree, VisitorState visitorState)
      Specified by:
      visitCase in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitCase in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitCatch

      public Void visitCatch(com.sun.source.tree.CatchTree tree, VisitorState visitorState)
      Specified by:
      visitCatch in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitCatch in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitClass

      public Void visitClass(com.sun.source.tree.ClassTree tree, VisitorState visitorState)
      Specified by:
      visitClass in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitClass in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitCompilationUnit

      public Void visitCompilationUnit(com.sun.source.tree.CompilationUnitTree tree, VisitorState visitorState)
      Specified by:
      visitCompilationUnit in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitCompilationUnit in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitCompoundAssignment

      public Void visitCompoundAssignment(com.sun.source.tree.CompoundAssignmentTree tree, VisitorState visitorState)
      Specified by:
      visitCompoundAssignment in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitCompoundAssignment in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitConditionalExpression

      public Void visitConditionalExpression(com.sun.source.tree.ConditionalExpressionTree tree, VisitorState visitorState)
      Specified by:
      visitConditionalExpression in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitConditionalExpression in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitContinue

      public Void visitContinue(com.sun.source.tree.ContinueTree tree, VisitorState visitorState)
      Specified by:
      visitContinue in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitContinue in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitDoWhileLoop

      public Void visitDoWhileLoop(com.sun.source.tree.DoWhileLoopTree tree, VisitorState visitorState)
      Specified by:
      visitDoWhileLoop in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitDoWhileLoop in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitEmptyStatement

      public Void visitEmptyStatement(com.sun.source.tree.EmptyStatementTree tree, VisitorState visitorState)
      Specified by:
      visitEmptyStatement in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitEmptyStatement in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitEnhancedForLoop

      public Void visitEnhancedForLoop(com.sun.source.tree.EnhancedForLoopTree tree, VisitorState visitorState)
      Specified by:
      visitEnhancedForLoop in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitEnhancedForLoop in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitExpressionStatement

      public Void visitExpressionStatement(com.sun.source.tree.ExpressionStatementTree tree, VisitorState visitorState)
      Specified by:
      visitExpressionStatement in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitExpressionStatement in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitForLoop

      public Void visitForLoop(com.sun.source.tree.ForLoopTree tree, VisitorState visitorState)
      Specified by:
      visitForLoop in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitForLoop in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitIdentifier

      public Void visitIdentifier(com.sun.source.tree.IdentifierTree tree, VisitorState visitorState)
      Specified by:
      visitIdentifier in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitIdentifier in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitIf

      public Void visitIf(com.sun.source.tree.IfTree tree, VisitorState visitorState)
      Specified by:
      visitIf in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitIf in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitImport

      public Void visitImport(com.sun.source.tree.ImportTree tree, VisitorState visitorState)
      Specified by:
      visitImport in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitImport in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitInstanceOf

      public Void visitInstanceOf(com.sun.source.tree.InstanceOfTree tree, VisitorState visitorState)
      Specified by:
      visitInstanceOf in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitInstanceOf in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitIntersectionType

      public Void visitIntersectionType(com.sun.source.tree.IntersectionTypeTree tree, VisitorState visitorState)
      Specified by:
      visitIntersectionType in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitIntersectionType in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitLabeledStatement

      public Void visitLabeledStatement(com.sun.source.tree.LabeledStatementTree tree, VisitorState visitorState)
      Specified by:
      visitLabeledStatement in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitLabeledStatement in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitLambdaExpression

      public Void visitLambdaExpression(com.sun.source.tree.LambdaExpressionTree tree, VisitorState visitorState)
      Specified by:
      visitLambdaExpression in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitLambdaExpression in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitLiteral

      public Void visitLiteral(com.sun.source.tree.LiteralTree tree, VisitorState visitorState)
      Specified by:
      visitLiteral in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitLiteral in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitMemberReference

      public Void visitMemberReference(com.sun.source.tree.MemberReferenceTree tree, VisitorState visitorState)
      Specified by:
      visitMemberReference in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitMemberReference in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitMemberSelect

      public Void visitMemberSelect(com.sun.source.tree.MemberSelectTree tree, VisitorState visitorState)
      Specified by:
      visitMemberSelect in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitMemberSelect in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitMethod

      public Void visitMethod(com.sun.source.tree.MethodTree tree, VisitorState visitorState)
      Specified by:
      visitMethod in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitMethod in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitMethodInvocation

      public Void visitMethodInvocation(com.sun.source.tree.MethodInvocationTree tree, VisitorState visitorState)
      Specified by:
      visitMethodInvocation in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitMethodInvocation in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitModifiers

      public Void visitModifiers(com.sun.source.tree.ModifiersTree tree, VisitorState visitorState)
      Specified by:
      visitModifiers in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitModifiers in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitNewArray

      public Void visitNewArray(com.sun.source.tree.NewArrayTree tree, VisitorState visitorState)
      Specified by:
      visitNewArray in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitNewArray in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitNewClass

      public Void visitNewClass(com.sun.source.tree.NewClassTree tree, VisitorState visitorState)
      Specified by:
      visitNewClass in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitNewClass in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitParameterizedType

      public Void visitParameterizedType(com.sun.source.tree.ParameterizedTypeTree tree, VisitorState visitorState)
      Specified by:
      visitParameterizedType in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitParameterizedType in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitParenthesized

      public Void visitParenthesized(com.sun.source.tree.ParenthesizedTree tree, VisitorState visitorState)
      Specified by:
      visitParenthesized in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitParenthesized in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitPrimitiveType

      public Void visitPrimitiveType(com.sun.source.tree.PrimitiveTypeTree tree, VisitorState visitorState)
      Specified by:
      visitPrimitiveType in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitPrimitiveType in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitReturn

      public Void visitReturn(com.sun.source.tree.ReturnTree tree, VisitorState visitorState)
      Specified by:
      visitReturn in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitReturn in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitSwitch

      public Void visitSwitch(com.sun.source.tree.SwitchTree tree, VisitorState visitorState)
      Specified by:
      visitSwitch in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitSwitch in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitSynchronized

      public Void visitSynchronized(com.sun.source.tree.SynchronizedTree tree, VisitorState visitorState)
      Specified by:
      visitSynchronized in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitSynchronized in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitThrow

      public Void visitThrow(com.sun.source.tree.ThrowTree tree, VisitorState visitorState)
      Specified by:
      visitThrow in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitThrow in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitTry

      public Void visitTry(com.sun.source.tree.TryTree tree, VisitorState visitorState)
      Specified by:
      visitTry in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitTry in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitTypeCast

      public Void visitTypeCast(com.sun.source.tree.TypeCastTree tree, VisitorState visitorState)
      Specified by:
      visitTypeCast in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitTypeCast in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitTypeParameter

      public Void visitTypeParameter(com.sun.source.tree.TypeParameterTree tree, VisitorState visitorState)
      Specified by:
      visitTypeParameter in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitTypeParameter in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitUnary

      public Void visitUnary(com.sun.source.tree.UnaryTree tree, VisitorState visitorState)
      Specified by:
      visitUnary in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitUnary in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitUnionType

      public Void visitUnionType(com.sun.source.tree.UnionTypeTree tree, VisitorState visitorState)
      Specified by:
      visitUnionType in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitUnionType in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitVariable

      public Void visitVariable(com.sun.source.tree.VariableTree tree, VisitorState visitorState)
      Specified by:
      visitVariable in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitVariable in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitWhileLoop

      public Void visitWhileLoop(com.sun.source.tree.WhileLoopTree tree, VisitorState visitorState)
      Specified by:
      visitWhileLoop in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitWhileLoop in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • visitWildcard

      public Void visitWildcard(com.sun.source.tree.WildcardTree tree, VisitorState visitorState)
      Specified by:
      visitWildcard in interface com.sun.source.tree.TreeVisitor<Void,VisitorState>
      Overrides:
      visitWildcard in class com.sun.source.util.TreeScanner<Void,VisitorState>
    • handleError

      protected void handleError(Suppressible s, Throwable t)
      Handles an exception thrown by an individual BugPattern. By default, wraps the exception in an ErrorProneError and rethrows. May be overridden by subclasses, for example to log the error and continue.
      Overrides:
      handleError in class Scanner
    • severityMap

      public Map<String,BugPattern.SeverityLevel> severityMap()
      Description copied from class: Scanner
      Returns a mapping between the canonical names of checks and their BugPattern.SeverityLevel.
      Overrides:
      severityMap in class Scanner
    • getBugCheckers

      public com.google.common.collect.ImmutableSet<BugChecker> getBugCheckers()