Package: org.apache.groovy.contracts.ast.visitor

## [Java] Class BaseVisitor

- org.apache.groovy.contracts.ast.visitor.BaseVisitor

-     public abstract class BaseVisitor
      extends ClassCodeVisitorSupport

  Base class for ClassCodeVisitorSupport descendants. This class is used in groovy-contracts as root class for all code visitors directly used by global AST transformations.

  See Also:
    ClassCodeVisitorSupport

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static String` | `GCONTRACTS_ENABLED_VAR` | Local variable name used by generated code to guard contract execution.
    `protected SourceUnit` | `sourceUnit` | Source unit currently being visited.

  - ### Constructor Summary

    Constructors
    Constructor and description
    `BaseVisitor(SourceUnit sourceUnit, ReaderSource source)` Creates a visitor bound to the supplied source unit.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public static BooleanExpression` | `asConditionExecution(AnnotationNode annotation)` Creates a boolean expression that invokes the generated closure backing the supplied annotation.
    `` | `protected static ClosureExpression` | `getOriginalCondition(AnnotationNode annotation)` Returns the original closure expression stored on the annotation, if it has not yet been replaced.
    `` | `protected static Expression` | `getReplacedCondition(AnnotationNode annotation)` Returns the rewritten annotation value once the original closure has been replaced.
    `` | `protected SourceUnit` | `getSourceUnit()` Returns the source unit associated with this visitor.
    `` | `protected static void` | `replaceCondition(AnnotationNode node, Expression expr)` Replaces the annotation value with the generated expression used by later transformation phases.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class ClassCodeVisitorSupport` | `addError, getSourceUnit, visitAnnotation, visitAnnotations, visitAnnotations, visitAssertStatement, visitBlockStatement, visitBreakStatement, visitCaseStatement, visitCatchStatement, visitClass, visitClassCodeContainer, visitClosureExpression, visitConstructor, visitConstructorOrMethod, visitContinueStatement, visitDeclarationExpression, visitDoWhileLoop, visitExpressionStatement, visitField, visitForLoop, visitIfElse, visitImports, visitMethod, visitObjectInitializerStatements, visitPackage, visitProperty, visitReturnStatement, visitStatement, visitStatementAnnotations, visitSwitch, visitSynchronizedStatement, visitThrowStatement, visitTryCatchFinally, visitWhileLoop`
    `class CodeVisitorSupport` | `afterSwitchCaseStatementsVisited, afterSwitchConditionExpressionVisited, visitArgumentlistExpression, visitArrayExpression, visitAssertStatement, visitAttributeExpression, visitBinaryExpression, visitBitwiseNegationExpression, visitBlockStatement, visitBooleanExpression, visitBreakStatement, visitBytecodeExpression, visitCaseStatement, visitCastExpression, visitCatchStatement, visitClassExpression, visitClosureExpression, visitClosureListExpression, visitConstantExpression, visitConstructorCallExpression, visitContinueStatement, visitDeclarationExpression, visitDoWhileLoop, visitEmptyStatement, visitExpressionStatement, visitFieldExpression, visitForLoop, visitGStringExpression, visitIfElse, visitLambdaExpression, visitListExpression, visitMapEntryExpression, visitMapExpression, visitMethodCallExpression, visitMethodPointerExpression, visitMethodReferenceExpression, visitNotExpression, visitPostfixExpression, visitPrefixExpression, visitPropertyExpression, visitRangeExpression, visitReturnStatement, visitShortTernaryExpression, visitSpreadExpression, visitSpreadMapExpression, visitStaticMethodCallExpression, visitSwitch, visitSynchronizedStatement, visitTernaryExpression, visitThrowStatement, visitTryCatchFinally, visitTupleExpression, visitUnaryMinusExpression, visitUnaryPlusExpression, visitVariableExpression, visitWhileLoop`

- - ### Field Detail

    - #### public static final String GCONTRACTS_ENABLED_VAR

      Local variable name used by generated code to guard contract execution.

    - #### protected final SourceUnit sourceUnit

      Source unit currently being visited.

  - ### Constructor Detail

    - #### public BaseVisitor(SourceUnit sourceUnit, ReaderSource source)

      Creates a visitor bound to the supplied source unit.

      Parameters:
        `sourceUnit` - the source unit currently being transformed
        `source` - the reader source backing the source unit

  - ### Method Detail

    - #### public static BooleanExpression asConditionExecution(AnnotationNode annotation)

      Creates a boolean expression that invokes the generated closure backing the supplied annotation.

      Parameters:
        `annotation` - the contract annotation whose closure should be executed
      Returns:
        a boolean expression that evaluates the generated closure

    - #### protected static ClosureExpression getOriginalCondition(AnnotationNode annotation)

      Returns the original closure expression stored on the annotation, if it has not yet been replaced.

      Parameters:
        `annotation` - the annotation to inspect
      Returns:
        the original closure expression, or `null` if it has already been rewritten

    - #### protected static Expression getReplacedCondition(AnnotationNode annotation)

      Returns the rewritten annotation value once the original closure has been replaced.

      Parameters:
        `annotation` - the annotation to inspect
      Returns:
        the replacement expression, or `null` while the original closure is still present

    - #### protected SourceUnit getSourceUnit()

      Returns the source unit associated with this visitor.

      Returns:
        the current source unit

    - #### protected static void replaceCondition(AnnotationNode node, Expression expr)

      Replaces the annotation value with the generated expression used by later transformation phases.

      Parameters:
        `node` - the annotation to update
        `expr` - the replacement expression