The main class code visitor responsible for static type checking. It will perform various inspections like checking assignment types, type inference, ... Eventually, class nodes may be annotated with inferred type information.
| Modifiers | Name | Description |
|---|---|---|
static class |
StaticTypeCheckingVisitor.SignatureCodecFactory |
|
protected class |
StaticTypeCheckingVisitor.VariableExpressionTypeMemoizer |
| Constructor and description |
|---|
StaticTypeCheckingVisitor
(SourceUnit source, ClassNode cn) |
| Type | Name and description |
|---|---|
protected void |
addAmbiguousErrorMessage(List foundMethods, String name, ClassNode[] args, Expression expr) |
protected void |
addAssignmentError(ClassNode leftType, ClassNode rightType, Expression assignmentExpression) |
protected void |
addCategoryMethodCallError(Expression call) |
protected void |
addClosureReturnType(ClassNode returnType) |
protected void |
addError(String msg, ASTNode expr) |
protected void |
addNoMatchingMethodError(ClassNode receiver, String name, ClassNode[] args, Expression call) |
protected void |
addReceivers(List receivers, Collection owners, boolean implicitThis) |
protected void |
addStaticTypeError(String msg, ASTNode expr) |
void |
addTypeCheckingExtension(TypeCheckingExtension extension) |
protected void |
addTypeCheckingInfoAnnotation(MethodNode node) |
protected void |
addUnsupportedPreOrPostfixExpressionError(Expression expression) |
protected boolean |
areCategoryMethodCalls(List foundMethods, String name, ClassNode[] args) |
protected boolean |
checkCast(ClassNode targetType, Expression source) |
protected void |
checkClosureParameters(Expression callArguments, ClassNode receiver)visit a method call target, to infer the type. |
protected void |
checkForbiddenSpreadArgument(ArgumentListExpression argumentList) |
protected void |
checkGroovyConstructorMap(Expression receiver, ClassNode receiverType, MapExpression mapExpression)Checks that a constructor style expression is valid regarding the number of arguments and the argument types. |
protected void |
checkGroovyStyleConstructor(ClassNode node, ClassNode[] arguments)A helper method which determines which receiver class should be used in error messages when a field or attribute is not found. |
protected MethodNode |
checkGroovyStyleConstructor(ClassNode node, ClassNode[] arguments, ASTNode source) |
protected ClassNode |
checkReturnType(ReturnStatement statement) |
protected void |
collectAllInterfaceMethodsByName(ClassNode receiver, String name, List methods) |
protected boolean |
existsProperty(PropertyExpression pexp, boolean checkForReadOnly) |
protected boolean |
existsProperty(PropertyExpression pexp, boolean readMode, ClassCodeVisitorSupport visitor) |
static String |
extractPropertyNameFromMethodName(String prefix, String methodName)Stores the inferred return type of a closure or a method. |
protected Object |
extractTemporaryTypeInfoKey(Expression expression) |
protected static ClassNode[] |
extractTypesFromParameters(Parameter[] parameters) |
protected ClassNode |
findCurrentInstanceOfClass(Expression expr, ClassNode type) |
protected List |
findMethod(ClassNode receiver, String name, ClassNode... args) |
protected MethodNode |
findMethodOrFail(Expression expr, ClassNode receiver, String name, ClassNode... args) |
protected List |
findMethodsWithGenerated(ClassNode receiver, String name)Given a method name and a prefix, returns the name of the property that should be looked up, following the java beans rules. |
protected static String |
formatArgumentList(ClassNode[] nodes) |
protected ClassNode[] |
getArgumentTypes(ArgumentListExpression args) |
protected DelegationMetadata |
getDelegationMetadata(ClosureExpression expression) |
protected static ClassNode |
getGroupOperationResultType(ClassNode a, ClassNode b)This method returns the list of methods named against the supplied parameter that are defined on the specified receiver, but it will also add "non existing" methods that will be generated afterwards by the compiler, for example if a method is using default values and that the specified class node isn't compiled yet. |
protected ClassNode |
getInferredReturnType(ASTNode exp) |
protected ClassNode |
getInferredReturnTypeFromWithClosureArgument(Expression callArguments) |
protected ClassNode |
getOriginalDeclarationType(Expression lhs) |
protected ClassNode |
getResultType(ClassNode left, int op, ClassNode right, BinaryExpression expr) |
protected SourceUnit |
getSourceUnit() |
protected List |
getTemporaryTypesForExpression(Expression objectExpression) |
protected ClassNode |
getType(ASTNode exp) |
protected ClassNode[] |
getTypeCheckingAnnotations() |
TypeCheckingContext |
getTypeCheckingContext()Returns the current type checking context. |
protected static boolean |
hasRHSIncompleteGenericTypeInfo(ClassNode inferredRightExpressionType) |
protected StaticTypeCheckingVisitor.SetterInfo |
hasSetter(PropertyExpression pexp) |
protected void |
inferClosureParameterTypes(ClassNode receiver, Expression arguments, ClosureExpression expression, Parameter param, MethodNode selectedMethod) |
protected ClassNode |
inferComponentType(ClassNode containerType, ClassNode indexType) |
protected void |
inferDiamondType(ConstructorCallExpression cce, ClassNode lType) |
protected ClassNode |
inferListExpressionType(ListExpression list) |
static ClassNode |
inferLoopElementType(ClassNode collectionType) |
protected ClassNode |
inferMapExpressionType(MapExpression map) |
protected ClassNode |
inferReturnTypeGenerics(ClassNode receiver, MethodNode method, Expression arguments) |
void |
initialize() |
protected static boolean |
isClassInnerClassOrEqualTo(ClassNode toBeChecked, ClassNode start) |
protected boolean |
isClosureCall(String name, Expression objectExpression, Expression arguments) |
protected static boolean |
isNullConstant(Expression expression) |
protected boolean |
isSecondPassNeededForControlStructure(Map varOrigType, Map oldTracker) |
boolean |
isSkipMode(AnnotatedNode node) |
protected boolean |
isSkippedInnerClass(AnnotatedNode node)Test if a node is an inner class node, and if it is, then checks if the enclosing method is skipped. |
protected List |
makeOwnerList(Expression objectExpression) |
void |
performSecondPass() |
protected Map |
popAssignmentTracking(Map oldTracker) |
protected static String |
prettyPrintMethodList(List nodes) |
protected Map |
pushAssignmentTracking() |
protected void |
pushInstanceOfTypeInfo(Expression objectOfInstanceOf, Expression typeExpression)Stores information about types when [objectOfInstanceof instanceof typeExpression] is visited |
protected void |
restoreVariableExpressionMetadata(Map typesBeforeVisit) |
protected void |
saveVariableExpressionMetadata(Set closureSharedExpressions, Map typesBeforeVisit) |
void |
setCompilationUnit(CompilationUnit cu) |
void |
setMethodsToBeVisited(Set methodsToBeVisited) |
protected boolean |
shouldSkipClassNode(ClassNode node) |
protected boolean |
shouldSkipMethodNode(MethodNode node) |
protected void |
silentlyVisitMethodNode(MethodNode directMethodCallCandidate) |
protected void |
startMethodInference(MethodNode node, ErrorCollector collector) |
protected ClassNode |
storeInferredReturnType(ASTNode node, ClassNode type)This method will convert a closure type to the appropriate SAM type, which will be used to infer return type generics. |
protected void |
storeInferredTypeForPropertyExpression(PropertyExpression pexp, ClassNode flatInferredType) |
protected void |
storeTargetMethod(Expression call, MethodNode directMethodCallCandidate) |
protected void |
storeType(Expression exp, ClassNode cn) |
protected void |
typeCheckAssignment(BinaryExpression assignmentExpression, Expression leftExpression, ClassNode leftExpressionType, Expression rightExpression, ClassNode inferredRightExpressionType) |
protected void |
typeCheckClosureCall(Expression callArguments, ClassNode[] args, Parameter[] parameters) |
protected MethodNode |
typeCheckMapConstructor(ConstructorCallExpression call, ClassNode receiver, Expression arguments) |
protected boolean |
typeCheckMethodsWithGenericsOrFail(ClassNode receiver, ClassNode[] arguments, MethodNode candidateMethod, Expression location)Returns a wrapped type if, and only if, the provided class node is a primitive type. |
void |
visitAttributeExpression(AttributeExpression expression) |
void |
visitBinaryExpression(BinaryExpression expression) |
void |
visitBitwiseNegationExpression(BitwiseNegationExpression expression) |
void |
visitCaseStatement(CaseStatement statement) |
void |
visitCastExpression(CastExpression expression) |
void |
visitClass(ClassNode node) |
void |
visitClassExpression(ClassExpression expression) |
void |
visitClosureExpression(ClosureExpression expression) |
void |
visitConstructorCallExpression(ConstructorCallExpression call) |
protected void |
visitConstructorOrMethod(MethodNode node, boolean isConstructor) |
void |
visitField(FieldNode node)Given a loop collection type, returns the inferred type of the loop element. |
void |
visitForLoop(ForStatement forLoop) |
void |
visitIfElse(IfStatement ifElse) |
void |
visitMethod(MethodNode node) |
protected void |
visitMethodCallArguments(ClassNode receiver, ArgumentListExpression arguments, boolean visitClosures, MethodNode selectedMethod) |
void |
visitMethodCallExpression(MethodCallExpression call) |
void |
visitPostfixExpression(PostfixExpression expression) |
void |
visitPrefixExpression(PrefixExpression expression) |
void |
visitPropertyExpression(PropertyExpression pexp) |
void |
visitRangeExpression(RangeExpression expression) |
void |
visitReturnStatement(ReturnStatement statement) |
void |
visitStaticMethodCallExpression(StaticMethodCallExpression call) |
void |
visitSwitch(SwitchStatement statement) |
void |
visitTernaryExpression(TernaryExpression expression) |
void |
visitTryCatchFinally(TryCatchStatement statement) |
void |
visitUnaryMinusExpression(UnaryMinusExpression expression) |
void |
visitUnaryPlusExpression(UnaryPlusExpression expression) |
void |
visitVariableExpression(VariableExpression vexp) |
void |
visitWhileLoop(WhileStatement loop) |
protected static ClassNode |
wrapTypeIfNecessary(ClassNode type) |
visit a method call target, to infer the type. Don't report errors right away, that will be done by a later visitMethod call
Checks that a constructor style expression is valid regarding the number of arguments and the argument types.
node - the class node for which we will try to find a matching constructorarguments - the constructor argumentsA helper method which determines which receiver class should be used in error messages when a field or attribute is not found. The returned type class depends on whether we have temporary type information availble (due to instanceof checks) and whether there is a single candidate in that case.
expr - the expression for which an unknown field has been foundtype - the type of the expression (used as fallback type)Stores the inferred return type of a closure or a method. We are using a separate key to store inferred return type because the inferred type of a closure is Closure, which is different from the inferred type of the code of the closure.
node - a ClosureExpression or a MethodNodetype - the inferred return type of the codeGiven a method name and a prefix, returns the name of the property that should be looked up, following the java beans rules. For example, "getName" would return "name", while "getFullName" would return "fullName". If the prefix is not found, returns null.
prefix - the method name prefix ("get", "is", "set", ...)methodName - the method nameThis method returns the list of methods named against the supplied parameter that are defined on the specified receiver, but it will also add "non existing" methods that will be generated afterwards by the compiler, for example if a method is using default values and that the specified class node isn't compiled yet.
receiver - the receiver where to find methodsname - the name of the methods to returnReturns the current type checking context. The context is used internally by the type checker during type checking to store various state data.
Test if a node is an inner class node, and if it is, then checks if the enclosing method is skipped.
Stores information about types when [objectOfInstanceof instanceof typeExpression] is visited
objectOfInstanceOf - the expression which must be checked against instanceoftypeExpression - the expression which represents the target typeThis method will convert a closure type to the appropriate SAM type, which will be used to infer return type generics.
closureType - the inferred type of a closure (Closure<ClosureReturnType>)samType - the type into which the closure is coerced intoReturns a wrapped type if, and only if, the provided class node is a primitive type. This method differs from ClassHelper#getWrapper(org.codehaus.groovy.ast.ClassNode) as it will return the same instance if the provided type is not a generic type.
Given a loop collection type, returns the inferred type of the loop element. Used, for example, to infer the element type of a (for e in list) loop.
collectionType - the type of the collectionCopyright © 2003-2014 The Codehaus. All rights reserved.