Class AnnotationClosureVisitor

All Implemented Interfaces:
ASTNodeMetaData, GroovyClassVisitor, GroovyCodeVisitor, ErrorCollecting

public class AnnotationClosureVisitor extends BaseVisitor implements ASTNodeMetaData
Visits interfaces & classes and looks for @Requires or @Ensures and creates Closure classes for the annotation closures.

The annotation closure classes are used later on to check interface contract pre- and post-conditions in implementation classes.

See Also:
  • Field Details

    • META_DATA_USE_EXECUTION_TRACKER

      public static final String META_DATA_USE_EXECUTION_TRACKER
      Metadata flag indicating that the rewritten closure performs method calls and therefore needs execution tracking instead of inline expansion.
      See Also:
    • META_DATA_ORIGINAL_TRY_CATCH_BLOCK

      public static final String META_DATA_ORIGINAL_TRY_CATCH_BLOCK
      Metadata key used to stash the original try/catch wrapped assertion block for later phases.
      See Also:
    • OLD_REFERENCES_KEY

      public static final String OLD_REFERENCES_KEY
      Node metadata key for the set of field names referenced via old.xxx in postconditions.
      See Also:
  • Constructor Details

    • AnnotationClosureVisitor

      public AnnotationClosureVisitor(SourceUnit sourceUnit, ReaderSource source)
      Creates a visitor that rewrites contract annotation closures into generated closure classes.
      Parameters:
      sourceUnit - the source unit currently being transformed
      source - the reader source backing the source unit
  • Method Details

    • visitClass

      public void visitClass(ClassNode classNode)
      Rewrites class-level contract closures and then recurses into inherited types that may also contribute contract annotations.
      Specified by:
      visitClass in interface GroovyClassVisitor
      Overrides:
      visitClass in class ClassCodeVisitorSupport
      Parameters:
      classNode - the class currently being visited
    • visitConstructorOrMethod

      public void visitConstructorOrMethod(MethodNode methodNode, boolean isConstructor)
      Rewrites method- and constructor-level contract closures into generated closure classes and records auxiliary metadata needed by later transformation phases.
      Overrides:
      visitConstructorOrMethod in class ClassCodeVisitorSupport
      Parameters:
      methodNode - the method or constructor being visited
      isConstructor - whether the visited executable is a constructor