Package: org.codehaus.groovy.transform.stc

## [Java] Class AbstractTypeCheckingExtension

- org.codehaus.groovy.transform.stc.AbstractTypeCheckingExtension

-     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
    Modifiers | Name | Description
    --- | --- | ---
    `static class` | `AbstractTypeCheckingExtension.TypeCheckingScope` | Map-backed scope used to share data across extension callbacks.

  - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `protected TypeCheckingContext` | `context` | Shared type-checking context exposed to extension helpers.
    `protected boolean` | `debug` | See Also: log(String)
    `protected boolean` | `handled` | See Also: setHandled(boolean)

  - Inherited fields
    Fields inherited from class | Fields
    --- | ---
    `class TypeCheckingExtension` | `typeCheckingVisitor`

  - ### Constructor Summary

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

  - ### Methods Summary

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

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class 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`

- - ### Field Detail

    - #### protected final TypeCheckingContext context

      Shared type-checking context exposed to extension helpers.

    - #### protected boolean debug

      See Also:
        log(String)

    - #### protected boolean handled

      See Also:
        setHandled(boolean)

  - ### Constructor Detail

    - #### public AbstractTypeCheckingExtension(StaticTypeCheckingVisitor typeCheckingVisitor)

      Creates an extension helper bound to the supplied visitor.

  - ### Method Detail

    - #### public boolean argTypeMatches(ClassNode[] argTypes, int index, Class clazz)

      Checks whether the argument at the supplied index matches the given class.

    - #### public boolean argTypeMatches(MethodCall call, int index, Class clazz)

      Checks whether a method call argument at the supplied index matches the given class.

    - #### public boolean argTypesMatches(ClassNode[] argTypes, Class classes)

      Checks whether the supplied argument types exactly match the given classes.

    - #### public boolean argTypesMatches(MethodCall call, Class classes)

      Checks whether a method call argument list exactly matches the given classes.

    - #### public void delegatesTo(ClassNode type)

      Sets closure delegation metadata with Closure.OWNER_FIRST.

    - #### public void delegatesTo(ClassNode type, int strategy)

      Sets closure delegation metadata for the supplied type and strategy.

    - #### public void delegatesTo(ClassNode type, int strategy, DelegationMetadata parent)

      Sets closure delegation metadata for the supplied type, strategy, and parent metadata.

    - #### public boolean firstArgTypesMatches(ClassNode[] argTypes, Class classes)

      Checks whether the leading argument types match the given classes.

    - #### public boolean firstArgTypesMatches(MethodCall call, Class classes)

      Checks whether a method call starts with arguments matching the given classes.

    - #### public ArgumentListExpression getArguments(MethodCall call)

      Returns the normalized argument list for the supplied method call.

    - #### public AbstractTypeCheckingExtension.TypeCheckingScope getCurrentScope()

      Returns the current scope, or `null` if none is active.

    - #### public BinaryExpression getEnclosingBinaryExpression()

      Returns the current enclosing binary expression.

    - #### public List<BinaryExpression> getEnclosingBinaryExpressionStack()

      Returns the enclosing binary-expression stack.

    - #### public ClassNode getEnclosingClassNode()

      Returns the current enclosing class node.

    - #### public List<ClassNode> getEnclosingClassNodes()

      Returns the enclosing class stack.

    - #### public EnclosingClosure getEnclosingClosure()

      Returns the current enclosing closure metadata.

    - #### public List<TypeCheckingContext.EnclosingClosure> getEnclosingClosureStack()

      Returns the enclosing closure stack.

    - #### public MethodNode getEnclosingMethod()

      Returns the current enclosing method.

    - #### public Expression getEnclosingMethodCall()

      Returns the current enclosing method call.

    - #### public List<Expression> getEnclosingMethodCalls()

      Returns the enclosing method-call stack.

    - #### public List<MethodNode> getEnclosingMethods()

      Returns the enclosing method stack.

    - #### public Set<MethodNode> getGeneratedMethods()

      Returns the generated methods created by this extension.

    - #### public boolean isAnnotatedBy(ASTNode node, Class annotation)

      Checks whether the node is annotated with the supplied annotation type.

    - #### public boolean isAnnotatedBy(ASTNode node, ClassNode annotation)

      Checks whether the node is annotated with the supplied annotation node.

    - #### public boolean isDynamic(VariableExpression var)

      Indicates whether the variable resolves dynamically.

    - #### public boolean isExtensionMethod(MethodNode node)

      Indicates whether the supplied method node models an extension method.

    - #### public boolean isGenerated(MethodNode node)

      Indicates whether the supplied method node was created by this extension.

    - #### public boolean isMethodCall(Object o)

      Indicates whether the supplied object is a method call expression.

    - #### public void log(String message)

      Logs a type-checking extension message.

    - #### 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

    - #### 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

    - #### 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

    - #### 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

    - #### 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

    - #### 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

    - #### public MethodNode newMethod(String name, Class returnType)

      Creates a synthetic public method with the supplied return type.

    - #### public MethodNode newMethod(String name, ClassNode returnType)

      Creates a synthetic public method with the supplied return type.

    - #### public MethodNode newMethod(String name, Callable<ClassNode> returnType)

      Creates a synthetic public method whose return type is resolved lazily.

    - #### public AbstractTypeCheckingExtension.TypeCheckingScope newScope()

      Pushes a new extension scope onto the scope stack.

    - #### public AbstractTypeCheckingExtension.TypeCheckingScope newScope(Closure code)

      Pushes a new scope and executes the supplied callback against it.

    - #### public BinaryExpression popEnclosingBinaryExpression()

      Pops the current enclosing binary expression.

    - #### public ClassNode popEnclosingClassNode()

      Pops the current enclosing class node.

    - #### public EnclosingClosure popEnclosingClosure()

      Pops the current enclosing closure metadata.

    - #### public MethodNode popEnclosingMethod()

      Pops the current enclosing method.

    - #### public Expression popEnclosingMethodCall()

      Pops the current enclosing method call.

    - #### public void popTemporaryTypeInfo()

      Pops the temporary type-information stack.

    - #### public void pushEnclosingBinaryExpression(BinaryExpression binaryExpression)

      Pushes an enclosing binary expression onto the context stack.

    - #### public void pushEnclosingClassNode(ClassNode classNode)

      Pushes an enclosing class node onto the context stack.

    - #### public void pushEnclosingClosureExpression(ClosureExpression closureExpression)

      Pushes an enclosing closure expression onto the context stack.

    - #### public void pushEnclosingMethod(MethodNode methodNode)

      Pushes an enclosing method onto the context stack.

    - #### public void pushEnclosingMethodCall(Expression call)

      Pushes an enclosing method call onto the context stack.

    - #### public 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.

    - #### public AbstractTypeCheckingExtension.TypeCheckingScope scopeExit()

      Pops and returns the current scope.

    - #### public AbstractTypeCheckingExtension.TypeCheckingScope scopeExit(Closure code)

      Executes the supplied callback against the current scope and then pops it.

    - #### public void setHandled(boolean handled)

      Marks whether the current event was handled by the extension.

    - #### public List<MethodNode> unique(MethodNode node)

      Wraps the supplied method node in a singleton list.

    - #### <R> public R withTypeChecker(@DelegatesTo(value = StaticTypeCheckingVisitor.class, strategy = Closure.DELEGATE_FIRST)
      @ClosureParams(value = SimpleType.class, options = "org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor")
      Closure<R> code)

      Executes the supplied closure with the type checker as delegate.