Class StaticTypeCheckingSupport
- java.lang.Object
- 
- org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport
 
- 
 public abstract class StaticTypeCheckingSupport extends java.lang.ObjectSupport methods forStaticTypeCheckingVisitor.
- 
- 
Field SummaryFields Modifier and Type Field Description protected static ClassNodeArrayList_TYPEprotected static ClassNodeCollection_TYPEprotected static ClassNodeDeprecated_TYPEprotected static java.util.Comparator<MethodNode>DGM_METHOD_NODE_COMPARATORThis comparator is used when we return the list of methods from DGM which name correspond to a given name.protected static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.ExtensionMethodCacheEXTENSION_METHOD_CACHEprotected static ClassNodeGSTRING_STRING_CLASSNODEprotected static ClassNodeMatcher_TYPEprotected static java.util.Map<java.lang.String,java.lang.Integer>NUMBER_OPSprotected static java.util.Map<ClassNode,java.lang.Integer>NUMBER_TYPESprotected static ClassNodeUNKNOWN_PARAMETER_TYPEThis is for internal use only.
 - 
Constructor SummaryConstructors Constructor Description StaticTypeCheckingSupport()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static intallParametersAndArgumentsMatch(Parameter[] parameters, ClassNode[] argumentTypes)Checks that arguments and parameter types match.static booleancheckCompatibleAssignmentTypes(ClassNode left, ClassNode right)Returns true or false depending on whether the right classnode can be assigned to the left classnode.static booleancheckCompatibleAssignmentTypes(ClassNode left, ClassNode right, Expression rightExpression)static booleancheckCompatibleAssignmentTypes(ClassNode left, ClassNode right, Expression rightExpression, boolean allowConstructorCoercion)Everything that can be done bycastToTypeshould be allowed for assignment.static java.util.List<MethodNode>chooseBestMethod(ClassNode receiver, java.util.Collection<MethodNode> methods, ClassNode... argumentTypes)Returns the method(s) which best fit the argument types.static voidclearExtensionMethodCache(java.lang.ClassLoader loader)static java.util.Set<ClassNode>collectAllInterfaces(ClassNode node)Collects all interfaces of a class node, including those defined by the super class.static java.lang.ObjectevaluateExpression(Expression expr, CompilerConfiguration config)Evaluates expressions as found in annotation parameters.static java.util.List<MethodNode>findDGMMethodsByNameAndArguments(java.lang.ClassLoader loader, ClassNode receiver, java.lang.String name, ClassNode[] args)static java.util.List<MethodNode>findDGMMethodsByNameAndArguments(java.lang.ClassLoader loader, ClassNode receiver, java.lang.String name, ClassNode[] args, java.util.List<MethodNode> methods)static java.util.List<MethodNode>findDGMMethodsByNameAndArguments(ClassNode receiver, java.lang.String name, ClassNode[] args)static java.util.List<MethodNode>findDGMMethodsByNameAndArguments(ClassNode receiver, java.lang.String name, ClassNode[] args, java.util.List<MethodNode> methods)protected static java.util.Set<MethodNode>findDGMMethodsForClassNode(java.lang.ClassLoader loader, ClassNode clazz, java.lang.String name)protected static voidfindDGMMethodsForClassNode(java.lang.ClassLoader loader, ClassNode clazz, java.lang.String name, java.util.TreeSet<MethodNode> accumulator)protected static java.util.Set<MethodNode>findDGMMethodsForClassNode(ClassNode clazz, java.lang.String name)Deprecated.protected static voidfindDGMMethodsForClassNode(ClassNode clazz, java.lang.String name, java.util.TreeSet<MethodNode> accumulator)Deprecated.static java.util.List<MethodNode>findSetters(ClassNode cn, java.lang.String setterName, boolean voidOnly)protected static VariablefindTargetVariable(VariableExpression ve)Given a variable expression, returns the ultimately accessed variable.protected static GenericsTypefullyResolve(GenericsType gt, java.util.Map<GenericsType.GenericsTypeName,GenericsType> placeholders)Given a generics type representing SomeClass<T,V> and a resolved placeholder map, returns a new generics type for which placeholders are resolved recursively.protected static ClassNodefullyResolveType(ClassNode type, java.util.Map<GenericsType.GenericsTypeName,GenericsType> placeholders)static ClassNodegetCorrectedClassNode(ClassNode type, ClassNode superClass, boolean handlingGenerics)static booleanimplementsInterfaceOrIsSubclassOf(ClassNode type, ClassNode superOrInterface)protected static booleanisArrayAccessExpression(Expression expression)Returns true for expressions of the form x[...]static booleanisAssignment(int op)static booleanisBeingCompiled(ClassNode node)static booleanisClassClassNodeWrappingConcreteType(ClassNode classNode)Returns true if the class node represents a the class node for the Class class and if the parametrized type is a neither a placeholder or a wildcard.static booleanisCompareToBoolean(int op)static booleanisGStringOrGStringStringLUB(ClassNode node)static booleanisParameterizedWithGStringOrGStringString(ClassNode node)static booleanisParameterizedWithString(ClassNode node)static ClassNodeisTraitSelf(VariableExpression vexp)static booleanisUnboundedWildcard(GenericsType gt)static booleanisUsingGenericsOrIsArrayUsingGenerics(ClassNode cn)Returns true if a class node makes use of generic types.static booleanisUsingUncheckedGenerics(ClassNode node)Returns true if the provided class node, when considered as a receiver of a message or as a parameter, is using a placeholder in its generics type.static booleanisWildcardLeftHandSide(ClassNode node)Tells if a class is one of the "accept all" classes as the left hand side of an assignment.static booleanisWithCall(java.lang.String name, Expression arguments)Called on method call checks in order to determine if a method call corresponds to the idiomatic o.with { ...static booleanmissesGenericsTypes(ClassNode cn)Determines if node is a raw type or references any generics placeholders.static Parameter[]parameterizeArguments(ClassNode receiver, MethodNode m)Given a receiver and a method node, parameterize the method arguments using available generic type information.static ClassNoderesolveClassNodeGenerics(java.util.Map<GenericsType.GenericsTypeName,GenericsType> resolvedPlaceholders, java.util.Map<GenericsType.GenericsTypeName,GenericsType> placeholdersFromContext, ClassNode currentType)protected static booleantypeCheckMethodArgumentWithGenerics(ClassNode parameterType, ClassNode argumentType, boolean lastArg)Checks that the parameterized generics of an argument are compatible with the generics of the parameter.protected static booleantypeCheckMethodsWithGenerics(ClassNode receiver, ClassNode[] arguments, MethodNode candidateMethod)
 
- 
- 
- 
Field Detail- 
Matcher_TYPEprotected static final ClassNode Matcher_TYPE 
 - 
ArrayList_TYPEprotected static final ClassNode ArrayList_TYPE 
 - 
Collection_TYPEprotected static final ClassNode Collection_TYPE 
 - 
Deprecated_TYPEprotected static final ClassNode Deprecated_TYPE 
 - 
NUMBER_TYPESprotected static final java.util.Map<ClassNode,java.lang.Integer> NUMBER_TYPES 
 - 
NUMBER_OPSprotected static final java.util.Map<java.lang.String,java.lang.Integer> NUMBER_OPS 
 - 
GSTRING_STRING_CLASSNODEprotected static final ClassNode GSTRING_STRING_CLASSNODE 
 - 
UNKNOWN_PARAMETER_TYPEprotected static final ClassNode UNKNOWN_PARAMETER_TYPE This is for internal use only. When an argument method is null, we cannot determine its type, so we use this one as a wildcard.
 - 
DGM_METHOD_NODE_COMPARATORprotected static final java.util.Comparator<MethodNode> DGM_METHOD_NODE_COMPARATOR This comparator is used when we return the list of methods from DGM which name correspond to a given name. As we also lookup for DGM methods of superclasses or interfaces, it may be possible to find two methods which have the same name and the same arguments. In that case, we should not add the method from superclass or interface otherwise the system won't be able to select the correct method, resulting in an ambiguous method selection for similar methods.
 - 
EXTENSION_METHOD_CACHEprotected static final org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.ExtensionMethodCache EXTENSION_METHOD_CACHE 
 
- 
 - 
Method Detail- 
clearExtensionMethodCachepublic static void clearExtensionMethodCache(java.lang.ClassLoader loader) 
 - 
isArrayAccessExpressionprotected static boolean isArrayAccessExpression(Expression expression) Returns true for expressions of the form x[...]- Parameters:
- expression- an expression
- Returns:
- true for array access expressions
 
 - 
isWithCallpublic static boolean isWithCall(java.lang.String name, Expression arguments)Called on method call checks in order to determine if a method call corresponds to the idiomatic o.with { ... } structure- Parameters:
- name- name of the method called
- arguments- method call arguments
- Returns:
- true if the name is "with" and arguments consist of a single closure
 
 - 
findTargetVariableprotected static Variable findTargetVariable(VariableExpression ve) Given a variable expression, returns the ultimately accessed variable.- Parameters:
- ve- a variable expression
- Returns:
- the target variable
 
 - 
findDGMMethodsForClassNode@Deprecated protected static java.util.Set<MethodNode> findDGMMethodsForClassNode(ClassNode clazz, java.lang.String name) Deprecated.
 - 
findDGMMethodsForClassNodeprotected static java.util.Set<MethodNode> findDGMMethodsForClassNode(java.lang.ClassLoader loader, ClassNode clazz, java.lang.String name) 
 - 
findDGMMethodsForClassNode@Deprecated protected static void findDGMMethodsForClassNode(ClassNode clazz, java.lang.String name, java.util.TreeSet<MethodNode> accumulator) Deprecated.
 - 
findDGMMethodsForClassNodeprotected static void findDGMMethodsForClassNode(java.lang.ClassLoader loader, ClassNode clazz, java.lang.String name, java.util.TreeSet<MethodNode> accumulator)
 - 
allParametersAndArgumentsMatchpublic static int allParametersAndArgumentsMatch(Parameter[] parameters, ClassNode[] argumentTypes) Checks that arguments and parameter types match.- Returns:
- -1 if arguments do not match, 0 if arguments are of the exact type and > 0 when one or more argument is not of the exact type but still match
 
 - 
isCompareToBooleanpublic static boolean isCompareToBoolean(int op) 
 - 
isAssignmentpublic static boolean isAssignment(int op) 
 - 
checkCompatibleAssignmentTypespublic static boolean checkCompatibleAssignmentTypes(ClassNode left, ClassNode right) Returns true or false depending on whether the right classnode can be assigned to the left classnode. This method should not add errors by itself: we let the caller decide what to do if an incompatible assignment is found.- Parameters:
- left- the class to be assigned to
- right- the assignee class
- Returns:
- false if types are incompatible
 
 - 
checkCompatibleAssignmentTypespublic static boolean checkCompatibleAssignmentTypes(ClassNode left, ClassNode right, Expression rightExpression) 
 - 
checkCompatibleAssignmentTypespublic static boolean checkCompatibleAssignmentTypes(ClassNode left, ClassNode right, Expression rightExpression, boolean allowConstructorCoercion) Everything that can be done bycastToTypeshould be allowed for assignment.
 - 
isWildcardLeftHandSidepublic static boolean isWildcardLeftHandSide(ClassNode node) Tells if a class is one of the "accept all" classes as the left hand side of an assignment.- Parameters:
- node- the classnode to test
- Returns:
- true if it's an Object, String, boolean, Boolean or Class.
 
 - 
isBeingCompiledpublic static boolean isBeingCompiled(ClassNode node) 
 - 
implementsInterfaceOrIsSubclassOfpublic static boolean implementsInterfaceOrIsSubclassOf(ClassNode type, ClassNode superOrInterface) 
 - 
findDGMMethodsByNameAndArguments@Deprecated public static java.util.List<MethodNode> findDGMMethodsByNameAndArguments(ClassNode receiver, java.lang.String name, ClassNode[] args) 
 - 
findDGMMethodsByNameAndArgumentspublic static java.util.List<MethodNode> findDGMMethodsByNameAndArguments(java.lang.ClassLoader loader, ClassNode receiver, java.lang.String name, ClassNode[] args) 
 - 
findDGMMethodsByNameAndArguments@Deprecated public static java.util.List<MethodNode> findDGMMethodsByNameAndArguments(ClassNode receiver, java.lang.String name, ClassNode[] args, java.util.List<MethodNode> methods) 
 - 
findDGMMethodsByNameAndArgumentspublic static java.util.List<MethodNode> findDGMMethodsByNameAndArguments(java.lang.ClassLoader loader, ClassNode receiver, java.lang.String name, ClassNode[] args, java.util.List<MethodNode> methods) 
 - 
isUsingUncheckedGenericspublic static boolean isUsingUncheckedGenerics(ClassNode node) Returns true if the provided class node, when considered as a receiver of a message or as a parameter, is using a placeholder in its generics type. In this case, we're facing unchecked generics and type checking is limited (ex: void foo(Set s) { s.keySet() }- Parameters:
- node- the node to test
- Returns:
- true if it is using any placeholder in generics types
 
 - 
chooseBestMethodpublic static java.util.List<MethodNode> chooseBestMethod(ClassNode receiver, java.util.Collection<MethodNode> methods, ClassNode... argumentTypes) Returns the method(s) which best fit the argument types.- Returns:
- zero or more results
 
 - 
parameterizeArgumentspublic static Parameter[] parameterizeArguments(ClassNode receiver, MethodNode m) Given a receiver and a method node, parameterize the method arguments using available generic type information.- Parameters:
- receiver- the class
- m- the method
- Returns:
- the parameterized arguments
 
 - 
isUsingGenericsOrIsArrayUsingGenericspublic static boolean isUsingGenericsOrIsArrayUsingGenerics(ClassNode cn) Returns true if a class node makes use of generic types. If the class node represents an array type, then checks if the component type is using generics.- Parameters:
- cn- a class node for which to check if it is using generics
- Returns:
- true if the type (or component type) is using generics
 
 - 
fullyResolveprotected static GenericsType fullyResolve(GenericsType gt, java.util.Map<GenericsType.GenericsTypeName,GenericsType> placeholders) Given a generics type representing SomeClass<T,V> and a resolved placeholder map, returns a new generics type for which placeholders are resolved recursively.
 - 
fullyResolveTypeprotected static ClassNode fullyResolveType(ClassNode type, java.util.Map<GenericsType.GenericsTypeName,GenericsType> placeholders) 
 - 
typeCheckMethodArgumentWithGenericsprotected static boolean typeCheckMethodArgumentWithGenerics(ClassNode parameterType, ClassNode argumentType, boolean lastArg) Checks that the parameterized generics of an argument are compatible with the generics of the parameter.- Parameters:
- parameterType- the parameter type of a method
- argumentType- the type of the argument passed to the method
 
 - 
typeCheckMethodsWithGenericsprotected static boolean typeCheckMethodsWithGenerics(ClassNode receiver, ClassNode[] arguments, MethodNode candidateMethod) 
 - 
resolveClassNodeGenericspublic static ClassNode resolveClassNodeGenerics(java.util.Map<GenericsType.GenericsTypeName,GenericsType> resolvedPlaceholders, java.util.Map<GenericsType.GenericsTypeName,GenericsType> placeholdersFromContext, ClassNode currentType) 
 - 
getCorrectedClassNodepublic static ClassNode getCorrectedClassNode(ClassNode type, ClassNode superClass, boolean handlingGenerics) 
 - 
isUnboundedWildcardpublic static boolean isUnboundedWildcard(GenericsType gt) 
 - 
isGStringOrGStringStringLUBpublic static boolean isGStringOrGStringStringLUB(ClassNode node) - Returns:
- true if the class node is either a GString or the LUB of String and GString.
 
 - 
isParameterizedWithGStringOrGStringStringpublic static boolean isParameterizedWithGStringOrGStringString(ClassNode node) - Parameters:
- node- the node to be tested
- Returns:
- true if the node is using generics types and one of those types is a gstring or string/gstring lub
 
 - 
isParameterizedWithStringpublic static boolean isParameterizedWithString(ClassNode node) - Parameters:
- node- the node to be tested
- Returns:
- true if the node is using generics types and one of those types is a string
 
 - 
missesGenericsTypespublic static boolean missesGenericsTypes(ClassNode cn) Determines if node is a raw type or references any generics placeholders.
 - 
evaluateExpressionpublic static java.lang.Object evaluateExpression(Expression expr, CompilerConfiguration config) Evaluates expressions as found in annotation parameters. For example, it will evaluate a constant, be it referenced directly as an integer or as a reference to a field.If the expression cannot be evaluated on its own, an exception is thrown. - Parameters:
- expr- the expression to be evaluated
- config- the compiler configuration
- Returns:
- the result of the expression
- Throws:
- GroovyBugError
 
 - 
collectAllInterfacespublic static java.util.Set<ClassNode> collectAllInterfaces(ClassNode node) Collects all interfaces of a class node, including those defined by the super class.- Parameters:
- node- a class for which we want to retrieve all interfaces
- Returns:
- a set of interfaces implemented by this class node
 
 - 
isClassClassNodeWrappingConcreteTypepublic static boolean isClassClassNodeWrappingConcreteType(ClassNode classNode) Returns true if the class node represents a the class node for the Class class and if the parametrized type is a neither a placeholder or a wildcard. For example, the class node Class<Foo> where Foo is a class would return true, but the class node for Class<?> would return false.- Parameters:
- classNode- a class node to be tested
- Returns:
- true if it is the class node for Class and its generic type is a real class
 
 - 
findSetterspublic static java.util.List<MethodNode> findSetters(ClassNode cn, java.lang.String setterName, boolean voidOnly) 
 - 
isTraitSelfpublic static ClassNode isTraitSelf(VariableExpression vexp) 
 
- 
 
-