Package: java.org.codenarc.rule

## [Java] Class AbstractAstVisitor

- java.org.codenarc.rule.AbstractAstVisitor

- All Implemented Interfaces and Traits:
    AstVisitor

      public class AbstractAstVisitor
      extends org.codehaus.groovy.ast.ClassCodeVisitorSupport

  Abstract superclass for Groovy AST Visitors used with Rules

  Authors:
    Chris Mair
    Hamlet D'Arcy

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `protected void` | `addViolation(org.codehaus.groovy.ast.ASTNode node)` Add a new Violation to the list of violations found by this visitor.
    `` | `protected void` | `addViolation(org.codehaus.groovy.ast.ASTNode node, String message)` Add a new Violation to the list of violations found by this visitor.
    `` | `protected void` | `addViolation(Violation violation)` Add a new Violation to the list of violations found by this visitor.
    `` | `protected String` | `getCurrentClassName()`
    `` | `protected org.codehaus.groovy.ast.ClassNode` | `getCurrentClassNode()`
    `` | `Rule` | `getRule()`
    `` | `SourceCode` | `getSourceCode()`
    `` | `protected org.codehaus.groovy.control.SourceUnit` | `getSourceUnit()`
    `` | `List<Violation>` | `getViolations()`
    `` | `Set<Object>` | `getVisited()`
    `` | `protected boolean` | `isFirstVisit(Object expression)` Return true if the AST expression has not already been visited.
    `` | `protected String` | `lastSourceLine(org.codehaus.groovy.ast.ASTNode node)` Return the last raw source line corresponding to the specified AST node
    `` | `protected String` | `lastSourceLineTrimmed(org.codehaus.groovy.ast.ASTNode node)` Return the trimmed last source line corresponding to the specified AST node
    `` | `void` | `setRule(Rule rule)`
    `` | `void` | `setSourceCode(SourceCode sourceCode)`
    `` | `void` | `setVisited(Set<Object> visited)`
    `` | `protected boolean` | `shouldVisitMethod(org.codehaus.groovy.ast.MethodNode node)`
    `` | `protected String` | `sourceLine(org.codehaus.groovy.ast.ASTNode node)` Return the raw source line corresponding to the specified AST node
    `` | `protected String` | `sourceLineTrimmed(org.codehaus.groovy.ast.ASTNode node)` Return the trimmed source line corresponding to the specified AST node
    `` | `void` | `visitClass(org.codehaus.groovy.ast.ClassNode node)`
    `` | `protected void` | `visitClassComplete(org.codehaus.groovy.ast.ClassNode node)`
    `` | `protected void` | `visitClassEx(org.codehaus.groovy.ast.ClassNode node)`
    `` | `void` | `visitMethod(org.codehaus.groovy.ast.MethodNode node)`
    `` | `protected void` | `visitMethodComplete(org.codehaus.groovy.ast.MethodNode node)`
    `` | `protected void` | `visitMethodEx(org.codehaus.groovy.ast.MethodNode node)`

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---

    `class org.codehaus.groovy.ast.ClassCodeVisitorSupport`

    `org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitField(org.codehaus.groovy.ast.FieldNode), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitMethod(org.codehaus.groovy.ast.MethodNode), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitReturnStatement(org.codehaus.groovy.ast.stmt.ReturnStatement), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitProperty(org.codehaus.groovy.ast.PropertyNode), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitConstructor(org.codehaus.groovy.ast.ConstructorNode), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitClass(org.codehaus.groovy.ast.ClassNode), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitBlockStatement(org.codehaus.groovy.ast.stmt.BlockStatement), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitForLoop(org.codehaus.groovy.ast.stmt.ForStatement), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitWhileLoop(org.codehaus.groovy.ast.stmt.WhileStatement), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitDoWhileLoop(org.codehaus.groovy.ast.stmt.DoWhileStatement), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitIfElse(org.codehaus.groovy.ast.stmt.IfStatement), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitExpressionStatement(org.codehaus.groovy.ast.stmt.ExpressionStatement), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitAssertStatement(org.codehaus.groovy.ast.stmt.AssertStatement), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitTryCatchFinally(org.codehaus.groovy.ast.stmt.TryCatchStatement), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitSwitch(org.codehaus.groovy.ast.stmt.SwitchStatement), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitCaseStatement(org.codehaus.groovy.ast.stmt.CaseStatement), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitBreakStatement(org.codehaus.groovy.ast.stmt.BreakStatement), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitContinueStatement(org.codehaus.groovy.ast.stmt.ContinueStatement), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitThrowStatement(org.codehaus.groovy.ast.stmt.ThrowStatement), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitSynchronizedStatement(org.codehaus.groovy.ast.stmt.SynchronizedStatement), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitCatchStatement(org.codehaus.groovy.ast.stmt.CatchStatement), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitDeclarationExpression(org.codehaus.groovy.ast.expr.DeclarationExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitAnnotations(org.codehaus.groovy.ast.AnnotatedNode), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitPackage(org.codehaus.groovy.ast.PackageNode), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitImports(org.codehaus.groovy.ast.ModuleNode), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitClassExpression(org.codehaus.groovy.ast.expr.ClassExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitPropertyExpression(org.codehaus.groovy.ast.expr.PropertyExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitListExpression(org.codehaus.groovy.ast.expr.ListExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitMethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitConstructorCallExpression(org.codehaus.groovy.ast.expr.ConstructorCallExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitTernaryExpression(org.codehaus.groovy.ast.expr.TernaryExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitShortTernaryExpression(org.codehaus.groovy.ast.expr.ElvisOperatorExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitBinaryExpression(org.codehaus.groovy.ast.expr.BinaryExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitPrefixExpression(org.codehaus.groovy.ast.expr.PrefixExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitPostfixExpression(org.codehaus.groovy.ast.expr.PostfixExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitBooleanExpression(org.codehaus.groovy.ast.expr.BooleanExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitClosureExpression(org.codehaus.groovy.ast.expr.ClosureExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitTupleExpression(org.codehaus.groovy.ast.expr.TupleExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitMapExpression(org.codehaus.groovy.ast.expr.MapExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitMapEntryExpression(org.codehaus.groovy.ast.expr.MapEntryExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitRangeExpression(org.codehaus.groovy.ast.expr.RangeExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitAttributeExpression(org.codehaus.groovy.ast.expr.AttributeExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitFieldExpression(org.codehaus.groovy.ast.expr.FieldExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitMethodPointerExpression(org.codehaus.groovy.ast.expr.MethodPointerExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitVariableExpression(org.codehaus.groovy.ast.expr.VariableExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitGStringExpression(org.codehaus.groovy.ast.expr.GStringExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitArrayExpression(org.codehaus.groovy.ast.expr.ArrayExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitSpreadExpression(org.codehaus.groovy.ast.expr.SpreadExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitSpreadMapExpression(org.codehaus.groovy.ast.expr.SpreadMapExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitNotExpression(org.codehaus.groovy.ast.expr.NotExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitUnaryMinusExpression(org.codehaus.groovy.ast.expr.UnaryMinusExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitUnaryPlusExpression(org.codehaus.groovy.ast.expr.UnaryPlusExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitBitwiseNegationExpression(org.codehaus.groovy.ast.expr.BitwiseNegationExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitCastExpression(org.codehaus.groovy.ast.expr.CastExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitArgumentlistExpression(org.codehaus.groovy.ast.expr.ArgumentListExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitClosureListExpression(org.codehaus.groovy.ast.expr.ClosureListExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitBytecodeExpression(org.codehaus.groovy.classgen.BytecodeExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#visitStaticMethodCallExpression(org.codehaus.groovy.ast.expr.StaticMethodCallExpression), org.codehaus.groovy.ast.ClassCodeVisitorSupport#equals(java.lang.Object), org.codehaus.groovy.ast.ClassCodeVisitorSupport#toString(), org.codehaus.groovy.ast.ClassCodeVisitorSupport#hashCode(), org.codehaus.groovy.ast.ClassCodeVisitorSupport#getClass(), org.codehaus.groovy.ast.ClassCodeVisitorSupport#notify(), org.codehaus.groovy.ast.ClassCodeVisitorSupport#notifyAll(), org.codehaus.groovy.ast.ClassCodeVisitorSupport#wait(long), org.codehaus.groovy.ast.ClassCodeVisitorSupport#wait(long, int), org.codehaus.groovy.ast.ClassCodeVisitorSupport#wait()`

    `class org.codehaus.groovy.ast.CodeVisitorSupport`

    `org.codehaus.groovy.ast.CodeVisitorSupport#visitConstantExpression(org.codehaus.groovy.ast.expr.ConstantExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitClassExpression(org.codehaus.groovy.ast.expr.ClassExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitPropertyExpression(org.codehaus.groovy.ast.expr.PropertyExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitReturnStatement(org.codehaus.groovy.ast.stmt.ReturnStatement), org.codehaus.groovy.ast.CodeVisitorSupport#visitListExpression(org.codehaus.groovy.ast.expr.ListExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitBlockStatement(org.codehaus.groovy.ast.stmt.BlockStatement), org.codehaus.groovy.ast.CodeVisitorSupport#visitForLoop(org.codehaus.groovy.ast.stmt.ForStatement), org.codehaus.groovy.ast.CodeVisitorSupport#visitWhileLoop(org.codehaus.groovy.ast.stmt.WhileStatement), org.codehaus.groovy.ast.CodeVisitorSupport#visitDoWhileLoop(org.codehaus.groovy.ast.stmt.DoWhileStatement), org.codehaus.groovy.ast.CodeVisitorSupport#visitIfElse(org.codehaus.groovy.ast.stmt.IfStatement), org.codehaus.groovy.ast.CodeVisitorSupport#visitExpressionStatement(org.codehaus.groovy.ast.stmt.ExpressionStatement), org.codehaus.groovy.ast.CodeVisitorSupport#visitAssertStatement(org.codehaus.groovy.ast.stmt.AssertStatement), org.codehaus.groovy.ast.CodeVisitorSupport#visitTryCatchFinally(org.codehaus.groovy.ast.stmt.TryCatchStatement), org.codehaus.groovy.ast.CodeVisitorSupport#visitSwitch(org.codehaus.groovy.ast.stmt.SwitchStatement), org.codehaus.groovy.ast.CodeVisitorSupport#visitCaseStatement(org.codehaus.groovy.ast.stmt.CaseStatement), org.codehaus.groovy.ast.CodeVisitorSupport#visitBreakStatement(org.codehaus.groovy.ast.stmt.BreakStatement), org.codehaus.groovy.ast.CodeVisitorSupport#visitContinueStatement(org.codehaus.groovy.ast.stmt.ContinueStatement), org.codehaus.groovy.ast.CodeVisitorSupport#visitThrowStatement(org.codehaus.groovy.ast.stmt.ThrowStatement), org.codehaus.groovy.ast.CodeVisitorSupport#visitSynchronizedStatement(org.codehaus.groovy.ast.stmt.SynchronizedStatement), org.codehaus.groovy.ast.CodeVisitorSupport#visitCatchStatement(org.codehaus.groovy.ast.stmt.CatchStatement), org.codehaus.groovy.ast.CodeVisitorSupport#visitMethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitConstructorCallExpression(org.codehaus.groovy.ast.expr.ConstructorCallExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitTernaryExpression(org.codehaus.groovy.ast.expr.TernaryExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitShortTernaryExpression(org.codehaus.groovy.ast.expr.ElvisOperatorExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitBinaryExpression(org.codehaus.groovy.ast.expr.BinaryExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitPrefixExpression(org.codehaus.groovy.ast.expr.PrefixExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitPostfixExpression(org.codehaus.groovy.ast.expr.PostfixExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitBooleanExpression(org.codehaus.groovy.ast.expr.BooleanExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitClosureExpression(org.codehaus.groovy.ast.expr.ClosureExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitTupleExpression(org.codehaus.groovy.ast.expr.TupleExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitMapExpression(org.codehaus.groovy.ast.expr.MapExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitMapEntryExpression(org.codehaus.groovy.ast.expr.MapEntryExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitRangeExpression(org.codehaus.groovy.ast.expr.RangeExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitAttributeExpression(org.codehaus.groovy.ast.expr.AttributeExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitFieldExpression(org.codehaus.groovy.ast.expr.FieldExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitMethodPointerExpression(org.codehaus.groovy.ast.expr.MethodPointerExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitVariableExpression(org.codehaus.groovy.ast.expr.VariableExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitDeclarationExpression(org.codehaus.groovy.ast.expr.DeclarationExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitGStringExpression(org.codehaus.groovy.ast.expr.GStringExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitArrayExpression(org.codehaus.groovy.ast.expr.ArrayExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitSpreadExpression(org.codehaus.groovy.ast.expr.SpreadExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitSpreadMapExpression(org.codehaus.groovy.ast.expr.SpreadMapExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitNotExpression(org.codehaus.groovy.ast.expr.NotExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitUnaryMinusExpression(org.codehaus.groovy.ast.expr.UnaryMinusExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitUnaryPlusExpression(org.codehaus.groovy.ast.expr.UnaryPlusExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitBitwiseNegationExpression(org.codehaus.groovy.ast.expr.BitwiseNegationExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitCastExpression(org.codehaus.groovy.ast.expr.CastExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitArgumentlistExpression(org.codehaus.groovy.ast.expr.ArgumentListExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitClosureListExpression(org.codehaus.groovy.ast.expr.ClosureListExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitBytecodeExpression(org.codehaus.groovy.classgen.BytecodeExpression), org.codehaus.groovy.ast.CodeVisitorSupport#visitStaticMethodCallExpression(org.codehaus.groovy.ast.expr.StaticMethodCallExpression), org.codehaus.groovy.ast.CodeVisitorSupport#equals(java.lang.Object), org.codehaus.groovy.ast.CodeVisitorSupport#toString(), org.codehaus.groovy.ast.CodeVisitorSupport#hashCode(), org.codehaus.groovy.ast.CodeVisitorSupport#getClass(), org.codehaus.groovy.ast.CodeVisitorSupport#notify(), org.codehaus.groovy.ast.CodeVisitorSupport#notifyAll(), org.codehaus.groovy.ast.CodeVisitorSupport#wait(long), org.codehaus.groovy.ast.CodeVisitorSupport#wait(long, int), org.codehaus.groovy.ast.CodeVisitorSupport#wait()`

- - ### Method Detail

    - #### @Deprecated protected void addViolation(org.codehaus.groovy.ast.ASTNode node)

      Add a new Violation to the list of violations found by this visitor. Only add the violation if the node lineNumber >= 0.

      deprecated:
        Always define a message. Use the other addViolation method instead of this one.
      Parameters:
        `node` - - the Groovy AST Node

    - #### protected void addViolation(org.codehaus.groovy.ast.ASTNode node, String message)

      Add a new Violation to the list of violations found by this visitor. Only add the violation if the node lineNumber >= 0.

      Parameters:
        `node` - - the Groovy AST Node
        `message` - - the message for the violation; defaults to null

    - #### protected void addViolation(Violation violation)

      Add a new Violation to the list of violations found by this visitor.

      Parameters:
        `violation` - - the violation to add

    - #### protected String getCurrentClassName()

    - #### protected org.codehaus.groovy.ast.ClassNode getCurrentClassNode()

    - #### public Rule getRule()

    - #### public SourceCode getSourceCode()

    - #### protected org.codehaus.groovy.control.SourceUnit getSourceUnit()

    - #### public List<Violation> getViolations()

    - #### public Set<Object> getVisited()

    - #### protected boolean isFirstVisit(Object expression)

      Return true if the AST expression has not already been visited. If it is the first visit, register the expression so that the next visit will return false.

      Parameters:
        `expression` - - the AST expression to check
      Returns:
        true if the AST expression has NOT already been visited

    - #### protected String lastSourceLine(org.codehaus.groovy.ast.ASTNode node)

      Return the last raw source line corresponding to the specified AST node

      Parameters:
        `node` - - the Groovy AST node

    - #### protected String lastSourceLineTrimmed(org.codehaus.groovy.ast.ASTNode node)

      Return the trimmed last source line corresponding to the specified AST node

      Parameters:
        `node` - - the Groovy AST node

    - #### public void setRule(Rule rule)

    - #### public void setSourceCode(SourceCode sourceCode)

    - #### public void setVisited(Set<Object> visited)

    - #### protected boolean shouldVisitMethod(org.codehaus.groovy.ast.MethodNode node)

    - #### protected String sourceLine(org.codehaus.groovy.ast.ASTNode node)

      Return the raw source line corresponding to the specified AST node

      Parameters:
        `node` - - the Groovy AST node

    - #### protected String sourceLineTrimmed(org.codehaus.groovy.ast.ASTNode node)

      Return the trimmed source line corresponding to the specified AST node

      Parameters:
        `node` - - the Groovy AST node

    - #### public final void visitClass(org.codehaus.groovy.ast.ClassNode node)

    - #### protected void visitClassComplete(org.codehaus.groovy.ast.ClassNode node)

    - #### protected void visitClassEx(org.codehaus.groovy.ast.ClassNode node)

    - #### public final void visitMethod(org.codehaus.groovy.ast.MethodNode node)

    - #### protected void visitMethodComplete(org.codehaus.groovy.ast.MethodNode node)

    - #### protected void visitMethodEx(org.codehaus.groovy.ast.MethodNode node)