public class TypeCheckingExtension extends Object
Modifier and Type | Field and Description |
---|---|
protected StaticTypeCheckingVisitor |
typeCheckingVisitor |
Constructor and Description |
---|
TypeCheckingExtension(StaticTypeCheckingVisitor typeCheckingVisitor) |
Modifier and Type | Method and Description |
---|---|
void |
addStaticTypeError(String msg,
ASTNode expr)
Adds a type checking error, which will be displayed to the user during compilation.
|
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.
|
ClassNode |
classNodeFor(Class type) |
ClassNode |
classNodeFor(String type) |
boolean |
existsProperty(PropertyExpression pexp,
boolean checkForReadOnly) |
boolean |
existsProperty(PropertyExpression pexp,
boolean checkForReadOnly,
ClassCodeVisitorSupport visitor) |
void |
finish()
Subclasses should implement this method if they need to perform additional
checks after the type checker has finished its work.
|
ClassNode[] |
getArgumentTypes(ArgumentListExpression args) |
MethodNode |
getTargetMethod(Expression expression) |
ClassNode |
getType(ASTNode exp)
Returns the inferred type of an expression.
|
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.
|
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.
|
ClassNode |
lookupClassNodeFor(String type)
Lookup a ClassNode by its name from the source unit
|
void |
onMethodSelection(Expression expression,
MethodNode target)
Allows the extension to listen to method selection events.
|
ClassNode |
parameterizedType(ClassNode baseType,
ClassNode... genericsTypeArguments) |
void |
setup()
Subclasses should implement this method whenever they need to perform
special checks before the type checker starts working.
|
void |
storeType(Expression exp,
ClassNode cn)
Stores an inferred type for an expression.
|
protected final StaticTypeCheckingVisitor typeCheckingVisitor
public TypeCheckingExtension(StaticTypeCheckingVisitor typeCheckingVisitor)
public void setup()
public void finish()
public boolean handleUnresolvedVariableExpression(VariableExpression vexp)
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)
pexp
- the unresolved propertyboolean
false if this extension doesn't resolve the property, true
if it resolves the property.public boolean handleUnresolvedAttribute(AttributeExpression aexp)
aexp
- the unresolved attributeboolean
false if this extension doesn't resolve the attribute, true
if it resolves the attribute.public List<MethodNode> handleMissingMethod(ClassNode receiver, String name, ArgumentListExpression argumentList, ClassNode[] argumentTypes, MethodCall call)
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 handleIncompatibleAssignment(ClassNode lhsType, ClassNode rhsType, Expression assignmentExpression)
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 boolean beforeVisitMethod(MethodNode node)
TypeCheckingMode.SKIP
.node
- a method nodepublic void afterVisitMethod(MethodNode node)
TypeCheckingMode.SKIP
.node
- a method nodepublic boolean beforeVisitClass(ClassNode node)
TypeCheckingMode.SKIP
.node
- a class nodepublic void afterVisitClass(ClassNode node)
TypeCheckingMode.SKIP
.node
- a class nodepublic boolean beforeMethodCall(MethodCall call)
TypeCheckingMode.SKIP
.call
- a method call, either a MethodCallExpression
or a StaticMethodCallExpression
public void afterMethodCall(MethodCall call)
TypeCheckingMode.SKIP
.call
- a method call, either a MethodCallExpression
or a StaticMethodCallExpression
public void onMethodSelection(Expression expression, MethodNode target)
expression
- the expression for which a corresponding method has been foundtarget
- the method which has been chosen by the type checkerpublic ClassNode getType(ASTNode exp)
exp
- the expression for which we want to find the inferred typepublic void addStaticTypeError(String msg, ASTNode expr)
msg
- the message for the errorexpr
- the expression which is the root cause of the errorpublic void storeType(Expression exp, ClassNode cn)
exp
- the expression for which we want to store an inferred typecn
- the type of the expressionpublic boolean existsProperty(PropertyExpression pexp, boolean checkForReadOnly)
public boolean existsProperty(PropertyExpression pexp, boolean checkForReadOnly, ClassCodeVisitorSupport visitor)
public ClassNode[] getArgumentTypes(ArgumentListExpression args)
public MethodNode getTargetMethod(Expression expression)
public ClassNode lookupClassNodeFor(String type)
type
- the name of the class whose ClassNode we want to lookup