Package org.codehaus.groovy.control

# Class OptimizerVisitor

java.lang.Object
org.codehaus.groovy.ast.CodeVisitorSupport
org.codehaus.groovy.ast.ClassCodeVisitorSupport
org.codehaus.groovy.ast.ClassCodeExpressionTransformer
org.codehaus.groovy.control.OptimizerVisitor

All Implemented Interfaces:
  `ExpressionTransformer`, `GroovyClassVisitor`, `GroovyCodeVisitor`, `ErrorCollecting`

public class OptimizerVisitor extends ClassCodeExpressionTransformer
Visitor to produce several optimizations:

- to replace numbered constants with references to static fields
- remove superfluous references to GroovyObject interface

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `OptimizerVisitor(CompilationUnit cu)`
  Creates an optimizer visitor.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected SourceUnit`
  `getSourceUnit()`
  Returns the source unit currently being optimized.
  `Expression`
  `transform(Expression exp)`
  Rewrites constant expressions that can be cached in synthetic fields.
  `void`
  `visitClass(ClassNode node, SourceUnit source)`
  Applies optimizer rewrites to the supplied class.
  `void`
  `visitClosureExpression(ClosureExpression expression)`
  Leaves closure bodies untouched so constant caching does not leak into closure classes.

  ### Methods inherited from class org.codehaus.groovy.ast.ClassCodeExpressionTransformer

  `setSourcePosition, visitAnnotation, visitAssertStatement, visitCaseStatement, visitConstructorOrMethod, visitDoWhileLoop, visitExpressionStatement, visitField, visitForLoop, visitIfElse, visitProperty, visitReturnStatement, visitSwitch, visitSynchronizedStatement, visitThrowStatement, visitWhileLoop`

  ### Methods inherited from class org.codehaus.groovy.ast.ClassCodeVisitorSupport

  `addError, visitAnnotations, visitAnnotations, visitBlockStatement, visitBreakStatement, visitCatchStatement, visitClass, visitClassCodeContainer, visitConstructor, visitContinueStatement, visitDeclarationExpression, visitImports, visitMethod, visitObjectInitializerStatements, visitPackage, visitStatement, visitStatementAnnotations, visitTryCatchFinally`

  ### Methods inherited from class org.codehaus.groovy.ast.CodeVisitorSupport

  `afterSwitchCaseStatementsVisited, afterSwitchConditionExpressionVisited, visitArgumentlistExpression, visitArrayExpression, visitAttributeExpression, visitBinaryExpression, visitBitwiseNegationExpression, visitBooleanExpression, visitBytecodeExpression, visitCastExpression, visitClassExpression, visitClosureListExpression, visitConstantExpression, visitConstructorCallExpression, visitEmptyStatement, visitFieldExpression, visitGStringExpression, visitLambdaExpression, visitListExpression, visitMapEntryExpression, visitMapExpression, visitMethodCallExpression, visitMethodPointerExpression, visitMethodReferenceExpression, visitNotExpression, visitPostfixExpression, visitPrefixExpression, visitPropertyExpression, visitRangeExpression, visitShortTernaryExpression, visitSpreadExpression, visitSpreadMapExpression, visitStaticMethodCallExpression, visitTernaryExpression, visitTupleExpression, visitUnaryMinusExpression, visitUnaryPlusExpression, visitVariableExpression`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface org.codehaus.groovy.ast.GroovyCodeVisitor

  `visit, visit, visitEmptyExpression, visitListOfExpressions`

- ## Constructor Details

  - ### OptimizerVisitor

    public OptimizerVisitor(CompilationUnit cu)
    Creates an optimizer visitor.
    Parameters:
      `cu` - the owning compilation unit

- ## Method Details

  - ### visitClass

    public void visitClass(ClassNode node, SourceUnit source)
    Applies optimizer rewrites to the supplied class.
    Parameters:
      `node` - the class to optimize
      `source` - the source unit containing the class

  - ### transform

    public Expression transform(Expression exp)
    Rewrites constant expressions that can be cached in synthetic fields.
    Specified by:
      `transform` in interface `ExpressionTransformer`
    Overrides:
      `transform` in class `ClassCodeExpressionTransformer`
    Parameters:
      `exp` - the expression to transform
    Returns:
      the transformed expression

  - ### getSourceUnit

    protected SourceUnit getSourceUnit()
    Returns the source unit currently being optimized.
    Specified by:
      `getSourceUnit` in class `ClassCodeVisitorSupport`
    Returns:
      the active source unit

  - ### visitClosureExpression

    public void visitClosureExpression(ClosureExpression expression)
    Leaves closure bodies untouched so constant caching does not leak into closure classes.
    Specified by:
      `visitClosureExpression` in interface `GroovyCodeVisitor`
    Overrides:
      `visitClosureExpression` in class `ClassCodeExpressionTransformer`
    Parameters:
      `expression` - the closure expression being skipped