Class BaseVisitor

All Implemented Interfaces:
GroovyClassVisitor, GroovyCodeVisitor, ErrorCollecting
Direct Known Subclasses:
AnnotationClosureVisitor, AnnotationContractParameterVisitor, AnnotationProcessorVisitor, ContractElementVisitor, DomainModelInjectionVisitor, DynamicSetterInjectionVisitor, LifecycleAfterTransformationVisitor, LifecycleBeforeTransformationVisitor

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:
  • Field Details

    • GCONTRACTS_ENABLED_VAR

      public static final String GCONTRACTS_ENABLED_VAR
      Local variable name used by generated code to guard contract execution.
      See Also:
    • sourceUnit

      protected final SourceUnit sourceUnit
      Source unit currently being visited.
  • Constructor Details

    • BaseVisitor

      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 Details

    • getSourceUnit

      protected SourceUnit getSourceUnit()
      Returns the source unit associated with this visitor.
      Specified by:
      getSourceUnit in class ClassCodeVisitorSupport
      Returns:
      the current source unit
    • asConditionExecution

      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
    • getOriginalCondition

      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
    • getReplacedCondition

      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
    • replaceCondition

      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