GroovyTypeCheckingExtensionSupport (Groovy 5.0.6)
Description: declaration: package: org.codehaus.groovy.transform.stc, class: GroovyTypeCheckingExtensionSupport

Package org.codehaus.groovy.transform.stc

# Class GroovyTypeCheckingExtensionSupport

java.lang.Object
org.codehaus.groovy.transform.stc.TypeCheckingExtension
org.codehaus.groovy.transform.stc.AbstractTypeCheckingExtension
org.codehaus.groovy.transform.stc.GroovyTypeCheckingExtensionSupport

public class GroovyTypeCheckingExtensionSupport extends AbstractTypeCheckingExtension
Base class for type checking extensions written in Groovy. Compared to its superclass, `TypeCheckingExtension`, this class adds a number of utility methods aimed at leveraging the syntax of the Groovy language to improve expressiveness and conciseness.

Since:
  2.1.0

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `GroovyTypeCheckingExtensionSupport.TypeCheckingDSL`
  Event handler registration: setup Registers closure that runs after the type checker finishes initialization finish Registers closure that runs after the type checker completes type checking beforeVisitClass Registers closure that runs before type checking a class afterVisitClass Registers closure that runs after having finished the visit of a type checked class beforeVisitMethod Registers closure that runs before type checking a method body afterVisitMethod Registers closure that runs after type checking a method body beforeMethodCall Registers closure that runs before the type checker starts type checking a method call afterMethodCall Registers closure that runs once the type checker has finished type checking a method call methodNotFound Registers closure that runs when it fails to find an appropriate method for a method call ambiguousMethods Registers closure that runs when the type checker cannot choose between several candidate methods onMethodSelection Registers closure that runs when it finds a method appropriate for a method call unresolvedVariable Registers closure that runs when the type checker finds an unresolved variable unresolvedProperty Registers closure that runs when the type checker cannot find a property on the receiver unresolvedAttribute Registers closure that runs when the type checker cannot find an attribute on the receiver incompatibleAssignment Registers closure that runs when the type checker thinks that the right-hand side of an assignment is incompatible with the left-hand side incompatibleReturnType Registers closure that runs when the type checker thinks that a return value is incompatibe with the return type Expression categorization: isAnnotationConstantExpression Determines if argument is an `AnnotationConstantExpression` isArgumentListExpression Determines if argument is an `ArgumentListExpression` isArrayExpression Determines if argument is an `ArrayExpression` isAttributeExpression Determines if argument is an `AttributeExpression` isBinaryExpression Determines if argument is a `BinaryExpression` isBitwiseNegationExpression Determines if argument is a `BitwiseNegationExpression` isBooleanExpression Determines if argument is a `BooleanExpression` isCastExpression Determines if argument is a `CastExpression` isClassExpression Determines if argument is a `ClassExpression` isClosureExpression Determines if argument is a `ClosureExpression` isConstantExpression Determines if argument is a `ConstantExpression` isConstructorCallExpression Determines if argument is a `ConstructorCallExpression` isDeclarationExpression Determines if argument is a `DeclarationExpression` isElvisOperatorExpression Determines if argument is an `ElvisOperatorExpression` isEmptyExpression Determines if argument is an `EmptyExpression` isFieldExpression Determines if argument is a `FieldExpression` isGStringExpression Determines if argument is a `GStringExpression` isLambdaExpression Determines if argument is a `LambdaExpression` isListExpression Determines if argument is a `ListExpression` isMapExpression Determines if argument is a `MapExpression` isMapEntryExpression Determines if argument is a `MapEntryExpression` isMethodCallExpression Determines if argument is a `MethodCallExpression` isMethodPointerExpression Determines if argument is a `MethodPointerExpression` isMethodReferenceExpression Determines if argument is a `MethodReferenceExpression` isNamedArgumentListExpression Determines if argument is a `NamedArgumentListExpression` isNotExpression Determines if argument is a `NotExpression` isPostfixExpression Determines if argument is a `PostfixExpression` isPrefixExpression Determines if argument is a `PrefixExpression` isPropertyExpression Determines if argument is a `PropertyExpression` isRangeExpression Determines if argument is a `RangeExpression` isSpreadExpression Determines if argument is a `SpreadExpression` isSpreadMapExpression Determines if argument is a `SpreadMapExpression` isStaticMethodCallExpression Determines if argument is a `StaticMethodCallExpression` isTernaryExpression Determines if argument is a `TernaryExpression` isTupleExpression Determines if argument is a `TupleExpression` isUnaryMinusExpression Determines if argument is a `UnaryMinusExpression` isUnaryPlusExpression Determines if argument is a `UnaryPlusExpression` isVariableExpression Determines if argument is a `VariableExpression` General utility: Delegates to `AbstractTypeCheckingExtension` Imports static members of `ClassHelper` Imports static members of `StaticTypeCheckingSupport`

  ## Nested classes/interfaces inherited from class org.codehaus.groovy.transform.stc.AbstractTypeCheckingExtension

  `AbstractTypeCheckingExtension.TypeCheckingScope`

- ## Field Summary

  ### Fields inherited from class org.codehaus.groovy.transform.stc.AbstractTypeCheckingExtension

  `context, debug, handled`

  ### Fields inherited from class org.codehaus.groovy.transform.stc.TypeCheckingExtension

  `typeCheckingVisitor`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `GroovyTypeCheckingExtensionSupport(StaticTypeCheckingVisitor typeCheckingVisitor, String scriptPath, CompilationUnit compilationUnit)`
  Builds a type checking extension relying on a Groovy script (type checking DSL).

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `afterMethodCall(MethodCall call)`
  Allows the extension to perform additional tasks after the type checker actually visits a method call.
  `void`
  `afterVisitClass(ClassNode node)`
  Allows the extension to perform additional tasks after the type checker actually visited a class node.
  `void`
  `afterVisitMethod(MethodNode node)`
  Allows the extension to perform additional tasks after the type checker actually visited a method node.
  `boolean`
  `beforeMethodCall(MethodCall call)`
  Allows the extension to perform additional tasks before the type checker actually visits a method call.
  `boolean`
  `beforeVisitClass(ClassNode node)`
  Allows the extension to perform additional tasks before the type checker actually visits a class node.
  `boolean`
  `beforeVisitMethod(MethodNode node)`
  Allows the extension to perform additional tasks before the type checker actually visits a method node.
  `boolean`
  `equals(Object that)`
  `void`
  `finish()`
  Subclasses should implement this method if they need to perform additional checks after the type checker has finished its work.
  `List<MethodNode>`
  `handleAmbiguousMethods(List<MethodNode> nodes, Expression origin)`
  This method is called by the type checker before throwing an "ambiguous method" error, giving the chance to the extension to select the method properly.
  `boolean`
  `handleIncompatibleAssignment(ClassNode lhsType, ClassNode rhsType, Expression assignmentExpression)`
  This method is called by the type checker when an assignment is not allowed by the type checker.
  `boolean`
  `handleIncompatibleReturnType(ReturnStatement returnStatement, ClassNode inferredReturnType)`
  Allows the extension to catch incompatible return types.
  `List<MethodNode>`
  `handleMissingMethod(ClassNode receiver, String name, ArgumentListExpression argumentList, ClassNode[] argumentTypes, MethodCall call)`
  This method is called by the type checker when a method call cannot be resolved.
  `boolean`
  `handleUnresolvedAttribute(AttributeExpression aexp)`
  This method is called by the type checker when an attribute expression cannot be resolved (for example, when an attribute doesn't exist).
  `boolean`
  `handleUnresolvedProperty(PropertyExpression pexp)`
  This method is called by the type checker when a property expression cannot be resolved (for example, when a property doesn't exist).
  `boolean`
  `handleUnresolvedVariableExpression(VariableExpression vexp)`
  This method is called by the type checker when a variable expression cannot be resolved.
  `int`
  `hashCode()`
  `void`
  `onMethodSelection(Expression expression, MethodNode target)`
  Allows the extension to listen to method selection events.
  `void`
  `setDebug(boolean debug)`
  `void`
  `setup()`
  Subclasses should implement this method whenever they need to perform special checks before the type checker starts working.

  ### Methods inherited from class org.codehaus.groovy.transform.stc.AbstractTypeCheckingExtension

  `argTypeMatches, argTypeMatches, argTypesMatches, argTypesMatches, delegatesTo, delegatesTo, delegatesTo, firstArgTypesMatches, firstArgTypesMatches, getArguments, getCurrentScope, getEnclosingBinaryExpression, getEnclosingBinaryExpressionStack, getEnclosingClassNode, getEnclosingClassNodes, getEnclosingClosure, getEnclosingClosureStack, getEnclosingMethod, getEnclosingMethodCall, getEnclosingMethodCalls, getEnclosingMethods, getGeneratedMethods, isAnnotatedBy, isAnnotatedBy, isDynamic, isExtensionMethod, isGenerated, isMethodCall, log, makeDynamic, makeDynamic, makeDynamic, makeDynamic, makeDynamic, makeDynamic, newMethod, newMethod, newMethod, newScope, newScope, popEnclosingBinaryExpression, popEnclosingClassNode, popEnclosingClosure, popEnclosingMethod, popEnclosingMethodCall, popTemporaryTypeInfo, pushEnclosingBinaryExpression, pushEnclosingClassNode, pushEnclosingClosureExpression, pushEnclosingMethod, pushEnclosingMethodCall, pushTemporaryTypeInfo, safeCall, scopeExit, scopeExit, setHandled, unique, withTypeChecker`

  ### Methods inherited from class org.codehaus.groovy.transform.stc.TypeCheckingExtension

  `addStaticTypeError, buildListType, buildMapType, classNodeFor, classNodeFor, existsProperty, existsProperty, extractStaticReceiver, getArgumentTypes, getTargetMethod, getType, isStaticMethodCallOnClass, lookupClassNodeFor, parameterizedType, storeType`

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

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

- ## Constructor Details

  - ### GroovyTypeCheckingExtensionSupport

    public GroovyTypeCheckingExtensionSupport(StaticTypeCheckingVisitor typeCheckingVisitor, String scriptPath, CompilationUnit compilationUnit)
    Builds a type checking extension relying on a Groovy script (type checking DSL).
    Parameters:
      `typeCheckingVisitor` - the type checking visitor
      `scriptPath` - the path to the type checking script (in classpath)
      `compilationUnit` -

- ## Method Details

  - ### equals

    public boolean equals(Object that)
    Overrides:
      `equals` in class `Object`

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`

  - ### setDebug

    public void setDebug(boolean debug)

  - ### setup

    public void setup()
    Description copied from class: `TypeCheckingExtension`
    Subclasses should implement this method whenever they need to perform special checks before the type checker starts working.
    Overrides:
      `setup` in class `TypeCheckingExtension`

  - ### finish

    public void finish()
    Description copied from class: `TypeCheckingExtension`
    Subclasses should implement this method if they need to perform additional checks after the type checker has finished its work. This is particularly useful for situations where you need multiple passes. Some checks in that case may be deferred to the end, using this method.
    Overrides:
      `finish` in class `TypeCheckingExtension`

  - ### onMethodSelection

    public void onMethodSelection(Expression expression, MethodNode target)
    Description copied from class: `TypeCheckingExtension`
    Allows the extension to listen to method selection events. Given an expression, which may be a method call expression, a static method call expression, a pre/postfix expression, ..., if a corresponding method is found, this method is called.
    Overrides:
      `onMethodSelection` in class `TypeCheckingExtension`
    Parameters:
      `expression` - the expression for which a corresponding method has been found
      `target` - the method which has been chosen by the type checker

  - ### afterMethodCall

    public void afterMethodCall(MethodCall call)
    Description copied from class: `TypeCheckingExtension`
    Allows the extension to perform additional tasks after the type checker actually visits a method call. Compared to a custom visitor, this method ensures that the node being visited is a node which would have been visited by the type checker. This is in particular important for nodes which are marked with `TypeCheckingMode.SKIP`.
    Overrides:
      `afterMethodCall` in class `TypeCheckingExtension`
    Parameters:
      `call` - a method call, either a `MethodCallExpression`, `StaticMethodCallExpression`, or `ConstructorCallExpression`

  - ### beforeMethodCall

    public boolean beforeMethodCall(MethodCall call)
    Description copied from class: `TypeCheckingExtension`
    Allows the extension to perform additional tasks before the type checker actually visits a method call. Compared to a custom visitor, this method ensures that the node being visited is a node which would have been visited by the type checker. This is in particular important for nodes which are marked with `TypeCheckingMode.SKIP`.
    Overrides:
      `beforeMethodCall` in class `TypeCheckingExtension`
    Parameters:
      `call` - a method call, either a `MethodCallExpression`, `StaticMethodCallExpression`, or `ConstructorCallExpression`
    Returns:
      false if the type checker should visit the node, or true if this extension replaces what the type checker would do with the method call.

  - ### handleUnresolvedVariableExpression

    public boolean handleUnresolvedVariableExpression(VariableExpression vexp)
    Description copied from class: `TypeCheckingExtension`
    This method is called by the type checker when a variable expression cannot be resolved. It gives the extension a chance to resolve it for the type checker.
    Overrides:
      `handleUnresolvedVariableExpression` in class `TypeCheckingExtension`
    Parameters:
      `vexp` - the unresolved variable extension
    Returns:
      `boolean` false if the extension doesn't handle it, true if the extension handles this variable.

  - ### handleUnresolvedProperty

    public boolean handleUnresolvedProperty(PropertyExpression pexp)
    Description copied from class: `TypeCheckingExtension`
    This method is called by the type checker when a property expression cannot be resolved (for example, when a property doesn't exist). It gives the extension a chance to resolve it.
    Overrides:
      `handleUnresolvedProperty` in class `TypeCheckingExtension`
    Parameters:
      `pexp` - the unresolved property
    Returns:
      `boolean` false if this extension doesn't resolve the property, true if it resolves the property.

  - ### handleUnresolvedAttribute

    public boolean handleUnresolvedAttribute(AttributeExpression aexp)
    Description copied from class: `TypeCheckingExtension`
    This method is called by the type checker when an attribute expression cannot be resolved (for example, when an attribute doesn't exist). It gives the extension a chance to resolve it.
    Overrides:
      `handleUnresolvedAttribute` in class `TypeCheckingExtension`
    Parameters:
      `aexp` - the unresolved attribute
    Returns:
      `boolean` false if this extension doesn't resolve the attribute, true if it resolves the attribute.

  - ### afterVisitMethod

    public void afterVisitMethod(MethodNode node)
    Description copied from class: `TypeCheckingExtension`
    Allows the extension to perform additional tasks after the type checker actually visited a method node. Compared to a custom visitor, this method ensures that the node being visited is a node which would have been visited by the type checker. This is in particular important for nodes which are marked with `TypeCheckingMode.SKIP`.
    Overrides:
      `afterVisitMethod` in class `TypeCheckingExtension`
    Parameters:
      `node` - a method node

  - ### beforeVisitClass

    public boolean beforeVisitClass(ClassNode node)
    Description copied from class: `TypeCheckingExtension`
    Allows the extension to perform additional tasks before the type checker actually visits a class node. Compared to a custom visitor, this method ensures that the node being visited is a node which would have been visited by the type checker. This is in particular important for nodes which are marked with `TypeCheckingMode.SKIP`.
    Overrides:
      `beforeVisitClass` in class `TypeCheckingExtension`
    Parameters:
      `node` - a class node
    Returns:
      false if the type checker should visit the node, or true if this extension replaces what the type checker would do with the class.

  - ### afterVisitClass

    public void afterVisitClass(ClassNode node)
    Description copied from class: `TypeCheckingExtension`
    Allows the extension to perform additional tasks after the type checker actually visited a class node. Compared to a custom visitor, this method ensures that the node being visited is a node which would have been visited by the type checker. This is in particular important for nodes which are marked with `TypeCheckingMode.SKIP`.
    Overrides:
      `afterVisitClass` in class `TypeCheckingExtension`
    Parameters:
      `node` - a class node

  - ### beforeVisitMethod

    public boolean beforeVisitMethod(MethodNode node)
    Description copied from class: `TypeCheckingExtension`
    Allows the extension to perform additional tasks before the type checker actually visits a method node. Compared to a custom visitor, this method ensures that the node being visited is a node which would have been visited by the type checker. This is in particular important for nodes which are marked with `TypeCheckingMode.SKIP`.
    Overrides:
      `beforeVisitMethod` in class `TypeCheckingExtension`
    Parameters:
      `node` - a method node
    Returns:
      false if the type checker should visit the node, or true if this extension replaces what the type checker would do with the method.

  - ### handleIncompatibleAssignment

    public boolean handleIncompatibleAssignment(ClassNode lhsType, ClassNode rhsType, Expression assignmentExpression)
    Description copied from class: `TypeCheckingExtension`
    This method is called by the type checker when an assignment is not allowed by the type checker. Extensions may override this method to allow such assignments where the type checker normally disallows them.
    Overrides:
      `handleIncompatibleAssignment` in class `TypeCheckingExtension`
    Parameters:
      `lhsType` - the type of the left hand side of the assignment, as found by the type checker
      `rhsType` - the type of the right hand side of the assignment, as found by the type checker
      `assignmentExpression` - the assignment expression which triggered this call
    Returns:
      `boolean` false if the extension does not handle this assignment, true otherwise

  - ### handleIncompatibleReturnType

    public boolean handleIncompatibleReturnType(ReturnStatement returnStatement, ClassNode inferredReturnType)
    Description copied from class: `TypeCheckingExtension`
    Allows the extension to catch incompatible return types. This event is called whenever the type checker finds that an inferred return type is incompatible with the declared return type of a method.
    Overrides:
      `handleIncompatibleReturnType` in class `TypeCheckingExtension`
    Parameters:
      `returnStatement` - the statement that triggered the error
      `inferredReturnType` - the inferred return type for this statement
    Returns:
      false if the extension doesn't handle the error, true otherwise

  - ### handleMissingMethod

    public List<MethodNode> handleMissingMethod(ClassNode receiver, String name, ArgumentListExpression argumentList, ClassNode[] argumentTypes, MethodCall call)
    Description copied from class: `TypeCheckingExtension`
    This method is called by the type checker when a method call cannot be resolved. Extensions may override this method to handle missing methods and prevent the type checker from throwing an error.
    Overrides:
      `handleMissingMethod` in class `TypeCheckingExtension`
    Parameters:
      `receiver` - the type of the receiver
      `name` - the name of the called method
      `argumentList` - the list of arguments of the call
      `argumentTypes` - the types of the arguments of the call
      `call` - the method call itself, if needed
    Returns:
      an empty list if the extension cannot resolve the method, or a list of potential methods if the extension finds candidates. This method must not return null.

  - ### handleAmbiguousMethods

    public List<MethodNode> handleAmbiguousMethods(List<MethodNode> nodes, Expression origin)
    Description copied from class: `TypeCheckingExtension`
    This method is called by the type checker before throwing an "ambiguous method" error, giving the chance to the extension to select the method properly. This means that when this method is called, the "nodes" parameter contains at least two methods. If the returned list still contains at least two methods, then the type checker will throw an ambiguous method call error. If the returned method contains 1 element, then the type checker will not throw any error. It is invalid to return an empty list.
    Overrides:
      `handleAmbiguousMethods` in class `TypeCheckingExtension`
    Parameters:
      `nodes` - the list of ambiguous methods
      `origin` - the expression which originated the method selection process
    Returns:
      a single element list of disambiguated selection, or more elements if still ambiguous. It is not allowed to return an empty list.