public class GroovyTypeCheckingExtensionSupport extends TypeCheckingExtension
TypeCheckingExtension
,
this class adds a number of utility methods aimed at leveraging the syntax of the Groovy language to improve
expressivity and conciseness.Modifier and Type | Class and Description |
---|---|
static class |
GroovyTypeCheckingExtensionSupport.TypeCheckingDSL |
typeCheckingVisitor
Constructor and Description |
---|
GroovyTypeCheckingExtensionSupport(StaticTypeCheckingVisitor typeCheckingVisitor,
java.lang.String scriptPath,
CompilationUnit compilationUnit)
Builds a type checking extension relying on a Groovy script (type checking DSL).
|
Modifier and Type | Method and 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 |
argTypeMatches(ClassNode[] argTypes,
int index,
java.lang.Class clazz) |
boolean |
argTypeMatches(MethodCall call,
int index,
java.lang.Class clazz) |
boolean |
argTypesMatches(ClassNode[] argTypes,
java.lang.Class... classes) |
boolean |
argTypesMatches(MethodCall call,
java.lang.Class... classes) |
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.
|
void |
delegatesTo(ClassNode type) |
void |
delegatesTo(ClassNode type,
int strategy) |
void |
delegatesTo(ClassNode type,
int strategy,
org.codehaus.groovy.transform.stc.DelegationMetadata parent) |
void |
finish()
Subclasses should implement this method if they need to perform additional
checks after the type checker has finished its work.
|
boolean |
firstArgTypesMatches(ClassNode[] argTypes,
java.lang.Class... classes) |
boolean |
firstArgTypesMatches(MethodCall call,
java.lang.Class... classes) |
ArgumentListExpression |
getArguments(MethodCall call) |
org.codehaus.groovy.transform.stc.GroovyTypeCheckingExtensionSupport.TypeCheckingScope |
getCurrentScope() |
BinaryExpression |
getEnclosingBinaryExpression() |
java.util.List<BinaryExpression> |
getEnclosingBinaryExpressionStack() |
ClassNode |
getEnclosingClassNode() |
java.util.List<ClassNode> |
getEnclosingClassNodes() |
TypeCheckingContext.EnclosingClosure |
getEnclosingClosure() |
java.util.List<TypeCheckingContext.EnclosingClosure> |
getEnclosingClosureStack() |
MethodNode |
getEnclosingMethod() |
Expression |
getEnclosingMethodCall() |
java.util.List<Expression> |
getEnclosingMethodCalls() |
java.util.List<MethodNode> |
getEnclosingMethods() |
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.
|
java.util.List<MethodNode> |
handleMissingMethod(ClassNode receiver,
java.lang.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.
|
boolean |
isAnnotatedBy(ASTNode node,
java.lang.Class annotation) |
boolean |
isAnnotatedBy(ASTNode node,
ClassNode annotation) |
boolean |
isDynamic(VariableExpression var) |
boolean |
isExtensionMethod(MethodNode node) |
boolean |
isGenerated(MethodNode node) |
boolean |
isMethodCall(java.lang.Object o) |
MethodNode |
newMethod(java.lang.String name,
java.util.concurrent.Callable<ClassNode> returnType) |
MethodNode |
newMethod(java.lang.String name,
java.lang.Class returnType) |
MethodNode |
newMethod(java.lang.String name,
ClassNode returnType) |
org.codehaus.groovy.transform.stc.GroovyTypeCheckingExtensionSupport.TypeCheckingScope |
newScope() |
org.codehaus.groovy.transform.stc.GroovyTypeCheckingExtensionSupport.TypeCheckingScope |
newScope(Closure code) |
void |
onMethodSelection(Expression expression,
MethodNode target)
Allows the extension to listen to method selection events.
|
BinaryExpression |
popEnclosingBinaryExpression() |
ClassNode |
popEnclosingClassNode() |
TypeCheckingContext.EnclosingClosure |
popEnclosingClosure() |
MethodNode |
popEnclosingMethod() |
Expression |
popEnclosingMethodCall() |
void |
popTemporaryTypeInfo() |
void |
pushEnclosingBinaryExpression(BinaryExpression binaryExpression) |
void |
pushEnclosingClassNode(ClassNode classNode) |
void |
pushEnclosingClosureExpression(ClosureExpression closureExpression) |
void |
pushEnclosingMethod(MethodNode methodNode) |
void |
pushEnclosingMethodCall(Expression call) |
void |
pushTemporaryTypeInfo() |
org.codehaus.groovy.transform.stc.GroovyTypeCheckingExtensionSupport.TypeCheckingScope |
scopeExit() |
org.codehaus.groovy.transform.stc.GroovyTypeCheckingExtensionSupport.TypeCheckingScope |
scopeExit(Closure code) |
void |
setHandled(boolean handled) |
void |
setup()
Subclasses should implement this method whenever they need to perform
special checks before the type checker starts working.
|
java.util.List<MethodNode> |
unique(MethodNode node) |
<R> R |
withTypeChecker(Closure<R> code) |
addStaticTypeError, classNodeFor, classNodeFor, existsProperty, existsProperty, getArgumentTypes, getTargetMethod, getType, lookupClassNodeFor, parameterizedType, storeType
public GroovyTypeCheckingExtensionSupport(StaticTypeCheckingVisitor typeCheckingVisitor, java.lang.String scriptPath, CompilationUnit compilationUnit)
typeCheckingVisitor
- the type checking visitorscriptPath
- the path to the type checking script (in classpath)compilationUnit
- public void setup()
TypeCheckingExtension
setup
in class TypeCheckingExtension
public void finish()
TypeCheckingExtension
finish
in class TypeCheckingExtension
public void setHandled(boolean handled)
public org.codehaus.groovy.transform.stc.GroovyTypeCheckingExtensionSupport.TypeCheckingScope newScope()
public org.codehaus.groovy.transform.stc.GroovyTypeCheckingExtensionSupport.TypeCheckingScope newScope(Closure code)
public org.codehaus.groovy.transform.stc.GroovyTypeCheckingExtensionSupport.TypeCheckingScope scopeExit()
public org.codehaus.groovy.transform.stc.GroovyTypeCheckingExtensionSupport.TypeCheckingScope getCurrentScope()
public org.codehaus.groovy.transform.stc.GroovyTypeCheckingExtensionSupport.TypeCheckingScope scopeExit(Closure code)
public boolean isGenerated(MethodNode node)
public java.util.List<MethodNode> unique(MethodNode node)
public MethodNode newMethod(java.lang.String name, java.lang.Class returnType)
public MethodNode newMethod(java.lang.String name, ClassNode returnType)
public MethodNode newMethod(java.lang.String name, java.util.concurrent.Callable<ClassNode> returnType)
public void delegatesTo(ClassNode type)
public void delegatesTo(ClassNode type, int strategy)
public void delegatesTo(ClassNode type, int strategy, org.codehaus.groovy.transform.stc.DelegationMetadata parent)
public boolean isAnnotatedBy(ASTNode node, java.lang.Class annotation)
public boolean isDynamic(VariableExpression var)
public boolean isExtensionMethod(MethodNode node)
public ArgumentListExpression getArguments(MethodCall call)
public void onMethodSelection(Expression expression, MethodNode target)
TypeCheckingExtension
onMethodSelection
in class TypeCheckingExtension
expression
- the expression for which a corresponding method has been foundtarget
- the method which has been chosen by the type checkerpublic void afterMethodCall(MethodCall call)
TypeCheckingExtension
TypeCheckingMode.SKIP
.afterMethodCall
in class TypeCheckingExtension
call
- a method call, either a MethodCallExpression
or a StaticMethodCallExpression
public boolean beforeMethodCall(MethodCall call)
TypeCheckingExtension
TypeCheckingMode.SKIP
.beforeMethodCall
in class TypeCheckingExtension
call
- a method call, either a MethodCallExpression
or a StaticMethodCallExpression
public boolean handleUnresolvedVariableExpression(VariableExpression vexp)
TypeCheckingExtension
handleUnresolvedVariableExpression
in class TypeCheckingExtension
vexp
- the unresolved variable extensionboolean
false if the extension doesn't handle it,
true if the extension handles this variable.public boolean handleUnresolvedProperty(PropertyExpression pexp)
TypeCheckingExtension
handleUnresolvedProperty
in class TypeCheckingExtension
pexp
- the unresolved propertyboolean
false if this extension doesn't resolve the property, true
if it resolves the property.public boolean handleUnresolvedAttribute(AttributeExpression aexp)
TypeCheckingExtension
handleUnresolvedAttribute
in class TypeCheckingExtension
aexp
- the unresolved attributeboolean
false if this extension doesn't resolve the attribute, true
if it resolves the attribute.public void afterVisitMethod(MethodNode node)
TypeCheckingExtension
TypeCheckingMode.SKIP
.afterVisitMethod
in class TypeCheckingExtension
node
- a method nodepublic boolean beforeVisitClass(ClassNode node)
TypeCheckingExtension
TypeCheckingMode.SKIP
.beforeVisitClass
in class TypeCheckingExtension
node
- a class nodepublic void afterVisitClass(ClassNode node)
TypeCheckingExtension
TypeCheckingMode.SKIP
.afterVisitClass
in class TypeCheckingExtension
node
- a class nodepublic boolean beforeVisitMethod(MethodNode node)
TypeCheckingExtension
TypeCheckingMode.SKIP
.beforeVisitMethod
in class TypeCheckingExtension
node
- a method nodepublic boolean handleIncompatibleAssignment(ClassNode lhsType, ClassNode rhsType, Expression assignmentExpression)
TypeCheckingExtension
handleIncompatibleAssignment
in class TypeCheckingExtension
lhsType
- the type of the left hand side of the assignment, as found by the type checkerrhsType
- the type of the right hand side of the assignment, as found by the type checkerassignmentExpression
- the assignment expression which triggerred this callboolean
false if the extension does not handle this assignment, true otherwisepublic java.util.List<MethodNode> handleMissingMethod(ClassNode receiver, java.lang.String name, ArgumentListExpression argumentList, ClassNode[] argumentTypes, MethodCall call)
TypeCheckingExtension
handleMissingMethod
in class TypeCheckingExtension
receiver
- the type of the receivername
- the name of the called methodargumentList
- the list of arguments of the callargumentTypes
- the types of the arguments of the callcall
- the method call itself, if neededpublic boolean isMethodCall(java.lang.Object o)
public boolean argTypesMatches(ClassNode[] argTypes, java.lang.Class... classes)
public boolean argTypesMatches(MethodCall call, java.lang.Class... classes)
public boolean firstArgTypesMatches(ClassNode[] argTypes, java.lang.Class... classes)
public boolean firstArgTypesMatches(MethodCall call, java.lang.Class... classes)
public boolean argTypeMatches(ClassNode[] argTypes, int index, java.lang.Class clazz)
public boolean argTypeMatches(MethodCall call, int index, java.lang.Class clazz)
public <R> R withTypeChecker(Closure<R> code)
public BinaryExpression getEnclosingBinaryExpression()
public void pushEnclosingBinaryExpression(BinaryExpression binaryExpression)
public void pushEnclosingClosureExpression(ClosureExpression closureExpression)
public Expression getEnclosingMethodCall()
public Expression popEnclosingMethodCall()
public MethodNode popEnclosingMethod()
public ClassNode getEnclosingClassNode()
public java.util.List<MethodNode> getEnclosingMethods()
public MethodNode getEnclosingMethod()
public void popTemporaryTypeInfo()
public void pushEnclosingClassNode(ClassNode classNode)
public BinaryExpression popEnclosingBinaryExpression()
public java.util.List<ClassNode> getEnclosingClassNodes()
public java.util.List<TypeCheckingContext.EnclosingClosure> getEnclosingClosureStack()
public ClassNode popEnclosingClassNode()
public void pushEnclosingMethod(MethodNode methodNode)
public java.util.List<BinaryExpression> getEnclosingBinaryExpressionStack()
public TypeCheckingContext.EnclosingClosure getEnclosingClosure()
public java.util.List<Expression> getEnclosingMethodCalls()
public void pushEnclosingMethodCall(Expression call)
public TypeCheckingContext.EnclosingClosure popEnclosingClosure()
public void pushTemporaryTypeInfo()