Package org.codehaus.groovy.transform.stc

# Class AbstractTypeCheckingExtension

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

Direct Known Subclasses:
  `GroovyTypeCheckingExtensionSupport`, `TraitTypeCheckingExtension`

public class AbstractTypeCheckingExtension extends TypeCheckingExtension

Custom type checking extensions may extend this method in order to benefit from a lot of support methods.

The methods found in this class are made directly available in type checking scripts through the `GroovyTypeCheckingExtensionSupport` class.

Since:
  2.3.0

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `AbstractTypeCheckingExtension.TypeCheckingScope`
  Map-backed scope used to share data across extension callbacks.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final TypeCheckingContext`
  `context`
  Shared type-checking context exposed to extension helpers.
  `protected boolean`
  `debug`
  `protected boolean`
  `handled`

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

  `typeCheckingVisitor`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AbstractTypeCheckingExtension(StaticTypeCheckingVisitor typeCheckingVisitor)`
  Creates an extension helper bound to the supplied visitor.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `argTypeMatches(ClassNode[] argTypes, int index, Class clazz)`
  Checks whether the argument at the supplied index matches the given class.
  `boolean`
  `argTypeMatches(MethodCall call, int index, Class clazz)`
  Checks whether a method call argument at the supplied index matches the given class.
  `boolean`
  `argTypesMatches(ClassNode[] argTypes, Class... classes)`
  Checks whether the supplied argument types exactly match the given classes.
  `boolean`
  `argTypesMatches(MethodCall call, Class... classes)`
  Checks whether a method call argument list exactly matches the given classes.
  `void`
  `delegatesTo(ClassNode type)`
  Sets closure delegation metadata with `Closure.OWNER_FIRST`.
  `void`
  `delegatesTo(ClassNode type, int strategy)`
  Sets closure delegation metadata for the supplied type and strategy.
  `void`
  `delegatesTo(ClassNode type, int strategy, org.codehaus.groovy.transform.stc.DelegationMetadata parent)`
  Sets closure delegation metadata for the supplied type, strategy, and parent metadata.
  `boolean`
  `firstArgTypesMatches(ClassNode[] argTypes, Class... classes)`
  Checks whether the leading argument types match the given classes.
  `boolean`
  `firstArgTypesMatches(MethodCall call, Class... classes)`
  Checks whether a method call starts with arguments matching the given classes.
  `ArgumentListExpression`
  `getArguments(MethodCall call)`
  Returns the normalized argument list for the supplied method call.
  `AbstractTypeCheckingExtension.TypeCheckingScope`
  `getCurrentScope()`
  Returns the current scope, or `null` if none is active.
  `BinaryExpression`
  `getEnclosingBinaryExpression()`
  Returns the current enclosing binary expression.
  `List<BinaryExpression>`
  `getEnclosingBinaryExpressionStack()`
  Returns the enclosing binary-expression stack.
  `ClassNode`
  `getEnclosingClassNode()`
  Returns the current enclosing class node.
  `List<ClassNode>`
  `getEnclosingClassNodes()`
  Returns the enclosing class stack.
  `TypeCheckingContext.EnclosingClosure`
  `getEnclosingClosure()`
  Returns the current enclosing closure metadata.
  `List<TypeCheckingContext.EnclosingClosure>`
  `getEnclosingClosureStack()`
  Returns the enclosing closure stack.
  `MethodNode`
  `getEnclosingMethod()`
  Returns the current enclosing method.
  `Expression`
  `getEnclosingMethodCall()`
  Returns the current enclosing method call.
  `List<Expression>`
  `getEnclosingMethodCalls()`
  Returns the enclosing method-call stack.
  `List<MethodNode>`
  `getEnclosingMethods()`
  Returns the enclosing method stack.
  `Set<MethodNode>`
  `getGeneratedMethods()`
  Returns the generated methods created by this extension.
  `boolean`
  `isAnnotatedBy(ASTNode node, Class annotation)`
  Checks whether the node is annotated with the supplied annotation type.
  `boolean`
  `isAnnotatedBy(ASTNode node, ClassNode annotation)`
  Checks whether the node is annotated with the supplied annotation node.
  `boolean`
  `isDynamic(VariableExpression var)`
  Indicates whether the variable resolves dynamically.
  `boolean`
  `isExtensionMethod(MethodNode node)`
  Indicates whether the supplied method node models an extension method.
  `boolean`
  `isGenerated(MethodNode node)`
  Indicates whether the supplied method node was created by this extension.
  `boolean`
  `isMethodCall(Object o)`
  Indicates whether the supplied object is a method call expression.
  `void`
  `log(String message)`
  Logs a type-checking extension message.
  `MethodNode`
  `makeDynamic(MethodCall call)`
  Used to instruct the type checker that the call is a dynamic method call.
  `MethodNode`
  `makeDynamic(MethodCall call, ClassNode returnType)`
  Used to instruct the type checker that the call is a dynamic method call.
  `void`
  `makeDynamic(PropertyExpression pexp)`
  Instructs the type checker that a property access is dynamic, returning an instance of an Object.
  `void`
  `makeDynamic(PropertyExpression pexp, ClassNode returnType)`
  Instructs the type checker that a property access is dynamic.
  `void`
  `makeDynamic(VariableExpression vexp)`
  Instructs the type checker that an unresolved variable is a dynamic variable of type Object.
  `void`
  `makeDynamic(VariableExpression vexp, ClassNode returnType)`
  Instructs the type checker that an unresolved variable is a dynamic variable.
  `MethodNode`
  `newMethod(String name, Class returnType)`
  Creates a synthetic public method with the supplied return type.
  `MethodNode`
  `newMethod(String name, Callable<ClassNode> returnType)`
  Creates a synthetic public method whose return type is resolved lazily.
  `MethodNode`
  `newMethod(String name, ClassNode returnType)`
  Creates a synthetic public method with the supplied return type.
  `AbstractTypeCheckingExtension.TypeCheckingScope`
  `newScope()`
  Pushes a new extension scope onto the scope stack.
  `AbstractTypeCheckingExtension.TypeCheckingScope`
  `newScope(Closure code)`
  Pushes a new scope and executes the supplied callback against it.
  `BinaryExpression`
  `popEnclosingBinaryExpression()`
  Pops the current enclosing binary expression.
  `ClassNode`
  `popEnclosingClassNode()`
  Pops the current enclosing class node.
  `TypeCheckingContext.EnclosingClosure`
  `popEnclosingClosure()`
  Pops the current enclosing closure metadata.
  `MethodNode`
  `popEnclosingMethod()`
  Pops the current enclosing method.
  `Expression`
  `popEnclosingMethodCall()`
  Pops the current enclosing method call.
  `void`
  `popTemporaryTypeInfo()`
  Pops the temporary type-information stack.
  `void`
  `pushEnclosingBinaryExpression(BinaryExpression binaryExpression)`
  Pushes an enclosing binary expression onto the context stack.
  `void`
  `pushEnclosingClassNode(ClassNode classNode)`
  Pushes an enclosing class node onto the context stack.
  `void`
  `pushEnclosingClosureExpression(ClosureExpression closureExpression)`
  Pushes an enclosing closure expression onto the context stack.
  `void`
  `pushEnclosingMethod(MethodNode methodNode)`
  Pushes an enclosing method onto the context stack.
  `void`
  `pushEnclosingMethodCall(Expression call)`
  Pushes an enclosing method call onto the context stack.
  `void`
  `pushTemporaryTypeInfo()`
  Pushes a new temporary type-information frame.
  `protected Object`
  `safeCall(Closure closure, Object... args)`
  Invokes the supplied closure and reports any failure to the source unit.
  `AbstractTypeCheckingExtension.TypeCheckingScope`
  `scopeExit()`
  Pops and returns the current scope.
  `AbstractTypeCheckingExtension.TypeCheckingScope`
  `scopeExit(Closure code)`
  Executes the supplied callback against the current scope and then pops it.
  `void`
  `setHandled(boolean handled)`
  Marks whether the current event was handled by the extension.
  `List<MethodNode>`
  `unique(MethodNode node)`
  Wraps the supplied method node in a singleton list.
  `<R> R`
  `withTypeChecker(Closure<R> code)`
  Executes the supplied closure with the type checker as delegate.

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

  `addStaticTypeError, afterMethodCall, afterVisitClass, afterVisitMethod, beforeMethodCall, beforeVisitClass, beforeVisitMethod, buildListType, buildMapType, classNodeFor, classNodeFor, existsProperty, existsProperty, extractStaticReceiver, finish, getArgumentTypes, getOptions, getTargetMethod, getType, handleAmbiguousMethods, handleIncompatibleAssignment, handleIncompatibleReturnType, handleMissingMethod, handleUnresolvedAttribute, handleUnresolvedProperty, handleUnresolvedVariableExpression, isStaticMethodCallOnClass, lookupClassNodeFor, onMethodSelection, parameterizedType, setOptions, setup, storeType`

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

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

- ## Field Details

  - ### context

    protected final TypeCheckingContext context
    Shared type-checking context exposed to extension helpers.

  - ### debug

    protected boolean debug

  - ### handled

    protected boolean handled

- ## Constructor Details

  - ### AbstractTypeCheckingExtension

    public AbstractTypeCheckingExtension(StaticTypeCheckingVisitor typeCheckingVisitor)
    Creates an extension helper bound to the supplied visitor.

- ## Method Details

  - ### setHandled

    public void setHandled(boolean handled)
    Marks whether the current event was handled by the extension.

  - ### newScope

    public AbstractTypeCheckingExtension.TypeCheckingScope newScope()
    Pushes a new extension scope onto the scope stack.

  - ### newScope

    public AbstractTypeCheckingExtension.TypeCheckingScope newScope(Closure code)
    Pushes a new scope and executes the supplied callback against it.

  - ### scopeExit

    public AbstractTypeCheckingExtension.TypeCheckingScope scopeExit()
    Pops and returns the current scope.

  - ### getCurrentScope

    public AbstractTypeCheckingExtension.TypeCheckingScope getCurrentScope()
    Returns the current scope, or `null` if none is active.

  - ### scopeExit

    public AbstractTypeCheckingExtension.TypeCheckingScope scopeExit(Closure code)
    Executes the supplied callback against the current scope and then pops it.

  - ### isGenerated

    public boolean isGenerated(MethodNode node)
    Indicates whether the supplied method node was created by this extension.

  - ### unique

    public List<MethodNode> unique(MethodNode node)
    Wraps the supplied method node in a singleton list.

  - ### newMethod

    public MethodNode newMethod(String name, Class returnType)
    Creates a synthetic public method with the supplied return type.

  - ### newMethod

    public MethodNode newMethod(String name, ClassNode returnType)
    Creates a synthetic public method with the supplied return type.

  - ### newMethod

    public MethodNode newMethod(String name, Callable<ClassNode> returnType)
    Creates a synthetic public method whose return type is resolved lazily.

  - ### delegatesTo

    public void delegatesTo(ClassNode type)
    Sets closure delegation metadata with `Closure.OWNER_FIRST`.

  - ### delegatesTo

    public void delegatesTo(ClassNode type, int strategy)
    Sets closure delegation metadata for the supplied type and strategy.

  - ### delegatesTo

    public void delegatesTo(ClassNode type, int strategy, org.codehaus.groovy.transform.stc.DelegationMetadata parent)
    Sets closure delegation metadata for the supplied type, strategy, and parent metadata.

  - ### isAnnotatedBy

    public boolean isAnnotatedBy(ASTNode node, Class annotation)
    Checks whether the node is annotated with the supplied annotation type.

  - ### isAnnotatedBy

    public boolean isAnnotatedBy(ASTNode node, ClassNode annotation)
    Checks whether the node is annotated with the supplied annotation node.

  - ### isDynamic

    public boolean isDynamic(VariableExpression var)
    Indicates whether the variable resolves dynamically.

  - ### isExtensionMethod

    public boolean isExtensionMethod(MethodNode node)
    Indicates whether the supplied method node models an extension method.

  - ### getArguments

    public ArgumentListExpression getArguments(MethodCall call)
    Returns the normalized argument list for the supplied method call.

  - ### safeCall

    protected Object safeCall(Closure closure, Object... args)
    Invokes the supplied closure and reports any failure to the source unit.

  - ### isMethodCall

    public boolean isMethodCall(Object o)
    Indicates whether the supplied object is a method call expression.

  - ### argTypesMatches

    public boolean argTypesMatches(ClassNode[] argTypes, Class... classes)
    Checks whether the supplied argument types exactly match the given classes.

  - ### argTypesMatches

    public boolean argTypesMatches(MethodCall call, Class... classes)
    Checks whether a method call argument list exactly matches the given classes.

  - ### firstArgTypesMatches

    public boolean firstArgTypesMatches(ClassNode[] argTypes, Class... classes)
    Checks whether the leading argument types match the given classes.

  - ### firstArgTypesMatches

    public boolean firstArgTypesMatches(MethodCall call, Class... classes)
    Checks whether a method call starts with arguments matching the given classes.

  - ### argTypeMatches

    public boolean argTypeMatches(ClassNode[] argTypes, int index, Class clazz)
    Checks whether the argument at the supplied index matches the given class.

  - ### argTypeMatches

    public boolean argTypeMatches(MethodCall call, int index, Class clazz)
    Checks whether a method call argument at the supplied index matches the given class.

  - ### withTypeChecker

    public <R> R withTypeChecker(@DelegatesTo(value=StaticTypeCheckingVisitor.class,strategy=1) @ClosureParams(value=SimpleType.class,options="org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor") Closure<R> code)
    Executes the supplied closure with the type checker as delegate.

  - ### makeDynamic

    public MethodNode makeDynamic(MethodCall call)
    Used to instruct the type checker that the call is a dynamic method call. Calling this method automatically sets the handled flag to true. The expected return type of the dynamic method call is Object.
    Parameters:
      `call` - the method call which is a dynamic method call
    Returns:
      a virtual method node with the same name as the expected call

  - ### makeDynamic

    public MethodNode makeDynamic(MethodCall call, ClassNode returnType)
    Used to instruct the type checker that the call is a dynamic method call. Calling this method automatically sets the handled flag to true.
    Parameters:
      `call` - the method call which is a dynamic method call
      `returnType` - the expected return type of the dynamic call
    Returns:
      a virtual method node with the same name as the expected call

  - ### makeDynamic

    public void makeDynamic(PropertyExpression pexp)
    Instructs the type checker that a property access is dynamic, returning an instance of an Object. Calling this method automatically sets the handled flag to true.
    Parameters:
      `pexp` - the property or attribute expression

  - ### makeDynamic

    public void makeDynamic(PropertyExpression pexp, ClassNode returnType)
    Instructs the type checker that a property access is dynamic. Calling this method automatically sets the handled flag to true.
    Parameters:
      `pexp` - the property or attribute expression
      `returnType` - the type of the property

  - ### makeDynamic

    public void makeDynamic(VariableExpression vexp)
    Instructs the type checker that an unresolved variable is a dynamic variable of type Object. Calling this method automatically sets the handled flag to true.
    Parameters:
      `vexp` - the dynamic variable

  - ### makeDynamic

    public void makeDynamic(VariableExpression vexp, ClassNode returnType)
    Instructs the type checker that an unresolved variable is a dynamic variable.
    Parameters:
      `returnType` - the type of the dynamic variable Calling this method automatically sets the handled flag to true.
      `vexp` - the dynamic variable

  - ### log

    public void log(String message)
    Logs a type-checking extension message.

  - ### getEnclosingBinaryExpression

    public BinaryExpression getEnclosingBinaryExpression()
    Returns the current enclosing binary expression.

  - ### pushEnclosingBinaryExpression

    public void pushEnclosingBinaryExpression(BinaryExpression binaryExpression)
    Pushes an enclosing binary expression onto the context stack.

  - ### pushEnclosingClosureExpression

    public void pushEnclosingClosureExpression(ClosureExpression closureExpression)
    Pushes an enclosing closure expression onto the context stack.

  - ### getEnclosingMethodCall

    public Expression getEnclosingMethodCall()
    Returns the current enclosing method call.

  - ### popEnclosingMethodCall

    public Expression popEnclosingMethodCall()
    Pops the current enclosing method call.

  - ### popEnclosingMethod

    public MethodNode popEnclosingMethod()
    Pops the current enclosing method.

  - ### getEnclosingClassNode

    public ClassNode getEnclosingClassNode()
    Returns the current enclosing class node.

  - ### getEnclosingMethods

    public List<MethodNode> getEnclosingMethods()
    Returns the enclosing method stack.

  - ### getEnclosingMethod

    public MethodNode getEnclosingMethod()
    Returns the current enclosing method.

  - ### popTemporaryTypeInfo

    public void popTemporaryTypeInfo()
    Pops the temporary type-information stack.

  - ### pushEnclosingClassNode

    public void pushEnclosingClassNode(ClassNode classNode)
    Pushes an enclosing class node onto the context stack.

  - ### popEnclosingBinaryExpression

    public BinaryExpression popEnclosingBinaryExpression()
    Pops the current enclosing binary expression.

  - ### getEnclosingClassNodes

    public List<ClassNode> getEnclosingClassNodes()
    Returns the enclosing class stack.

  - ### getEnclosingClosureStack

    public List<TypeCheckingContext.EnclosingClosure> getEnclosingClosureStack()
    Returns the enclosing closure stack.

  - ### popEnclosingClassNode

    public ClassNode popEnclosingClassNode()
    Pops the current enclosing class node.

  - ### pushEnclosingMethod

    public void pushEnclosingMethod(MethodNode methodNode)
    Pushes an enclosing method onto the context stack.

  - ### getGeneratedMethods

    public Set<MethodNode> getGeneratedMethods()
    Returns the generated methods created by this extension.

  - ### getEnclosingBinaryExpressionStack

    public List<BinaryExpression> getEnclosingBinaryExpressionStack()
    Returns the enclosing binary-expression stack.

  - ### getEnclosingClosure

    public TypeCheckingContext.EnclosingClosure getEnclosingClosure()
    Returns the current enclosing closure metadata.

  - ### getEnclosingMethodCalls

    public List<Expression> getEnclosingMethodCalls()
    Returns the enclosing method-call stack.

  - ### pushEnclosingMethodCall

    public void pushEnclosingMethodCall(Expression call)
    Pushes an enclosing method call onto the context stack.

  - ### popEnclosingClosure

    public TypeCheckingContext.EnclosingClosure popEnclosingClosure()
    Pops the current enclosing closure metadata.

  - ### pushTemporaryTypeInfo

    public void pushTemporaryTypeInfo()
    Pushes a new temporary type-information frame.