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

      Pushes a new extension scope onto the scope stack.
    • newScope

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

      Pops and returns the current scope.
    • getCurrentScope

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

      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.