public abstract class StaticTypeCheckingSupport extends Object
StaticTypeCheckingVisitor
.Modifier and Type | Class and Description |
---|---|
static class |
StaticTypeCheckingSupport.BooleanArrayStaticTypesHelper |
static class |
StaticTypeCheckingSupport.ByteArrayStaticTypesHelper |
static class |
StaticTypeCheckingSupport.CharArrayStaticTypesHelper |
static class |
StaticTypeCheckingSupport.DoubleArrayStaticTypesHelper |
static class |
StaticTypeCheckingSupport.FloatArrayStaticTypesHelper |
static class |
StaticTypeCheckingSupport.IntArrayStaticTypesHelper |
static class |
StaticTypeCheckingSupport.LongArrayStaticTypesHelper |
static class |
StaticTypeCheckingSupport.ObjectArrayStaticTypesHelper
A DGM-like class which adds support for method calls which are handled
specifically by the Groovy compiler.
|
static class |
StaticTypeCheckingSupport.ShortArrayStaticTypesHelper |
Modifier and Type | Field and Description |
---|---|
protected static ClassNode |
ArrayList_TYPE |
protected static ClassNode |
Collection_TYPE |
protected static ClassNode |
Deprecated_TYPE |
protected static 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.
|
protected static ExtensionMethodCache |
EXTENSION_METHOD_CACHE |
protected static ClassNode |
GSTRING_STRING_CLASSNODE |
protected static ClassNode |
Matcher_TYPE |
protected static Map<String,Integer> |
NUMBER_OPS |
protected static Map<ClassNode,Integer> |
NUMBER_TYPES |
protected static ClassNode |
UNKNOWN_PARAMETER_TYPE
This is for internal use only.
|
Constructor and Description |
---|
StaticTypeCheckingSupport() |
Modifier and Type | Method and Description |
---|---|
static int |
allParametersAndArgumentsMatch(Parameter[] parameters,
ClassNode[] argumentTypes)
Checks that arguments and parameter types match.
|
static boolean |
checkCompatibleAssignmentTypes(ClassNode left,
ClassNode right)
Returns true or false depending on whether the right classnode can be assigned to the left classnode.
|
static boolean |
checkCompatibleAssignmentTypes(ClassNode left,
ClassNode right,
Expression rightExpression) |
static boolean |
checkCompatibleAssignmentTypes(ClassNode left,
ClassNode right,
Expression rightExpression,
boolean allowConstructorCoercion) |
static List<MethodNode> |
chooseBestMethod(ClassNode receiver,
Collection<MethodNode> methods,
ClassNode... argumentTypes)
Given a list of candidate methods, returns the one which best matches the argument types
|
static void |
clearExtensionMethodCache() |
static Set<ClassNode> |
collectAllInterfaces(ClassNode node)
Collects all interfaces of a class node, including those defined by the
super class.
|
static Object |
evaluateExpression(Expression expr,
CompilerConfiguration config)
A helper method that can be used to evaluate expressions as found in annotation
parameters.
|
static List<MethodNode> |
filterMethodsByVisibility(List<MethodNode> methodNodeList,
ClassNode enclosingClassNode)
Filter methods according to visibility
|
static List<MethodNode> |
findDGMMethodsByNameAndArguments(ClassLoader loader,
ClassNode receiver,
String name,
ClassNode[] args) |
static List<MethodNode> |
findDGMMethodsByNameAndArguments(ClassLoader loader,
ClassNode receiver,
String name,
ClassNode[] args,
List<MethodNode> methods) |
static List<MethodNode> |
findDGMMethodsByNameAndArguments(ClassNode receiver,
String name,
ClassNode[] args)
Deprecated.
|
static List<MethodNode> |
findDGMMethodsByNameAndArguments(ClassNode receiver,
String name,
ClassNode[] args,
List<MethodNode> methods)
Deprecated.
|
static Set<MethodNode> |
findDGMMethodsForClassNode(ClassLoader loader,
ClassNode clazz,
String name) |
protected static void |
findDGMMethodsForClassNode(ClassLoader loader,
ClassNode clazz,
String name,
TreeSet<MethodNode> accumulator) |
protected static Set<MethodNode> |
findDGMMethodsForClassNode(ClassNode clazz,
String name)
Deprecated.
|
protected static void |
findDGMMethodsForClassNode(ClassNode clazz,
String name,
TreeSet<MethodNode> accumulator)
Deprecated.
|
static List<MethodNode> |
findSetters(ClassNode cn,
String setterName,
boolean voidOnly) |
protected static Variable |
findTargetVariable(VariableExpression ve)
Given a variable expression, returns the ultimately accessed variable.
|
protected static GenericsType |
fullyResolve(GenericsType gt,
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 ClassNode |
fullyResolveType(ClassNode type,
Map<GenericsType.GenericsTypeName,GenericsType> placeholders) |
static ClassNode |
getCorrectedClassNode(ClassNode type,
ClassNode superClass,
boolean handlingGenerics) |
static boolean |
implementsInterfaceOrIsSubclassOf(ClassNode type,
ClassNode superOrInterface) |
protected static boolean |
isArrayAccessExpression(Expression expression)
Returns true for expressions of the form x[...]
|
static boolean |
isAssignment(int op) |
static boolean |
isBeingCompiled(ClassNode node) |
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.
|
static boolean |
isCompareToBoolean(int op) |
static boolean |
isGStringOrGStringStringLUB(ClassNode node) |
static boolean |
isParameterizedWithGStringOrGStringString(ClassNode node) |
static boolean |
isParameterizedWithString(ClassNode node) |
static ClassNode |
isTraitSelf(VariableExpression vexp) |
static boolean |
isUnboundedWildcard(GenericsType gt) |
static boolean |
isUsingGenericsOrIsArrayUsingGenerics(ClassNode cn)
Returns true if a class node makes use of generic types.
|
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.
|
static boolean |
isWildcardLeftHandSide(ClassNode node)
Tells if a class is one of the "accept all" classes as the left hand side of an
assignment.
|
static boolean |
isWithCall(String name,
Expression arguments)
Called on method call checks in order to determine if a method call corresponds to the
idiomatic o.with { ...
|
static boolean |
missesGenericsTypes(ClassNode cn) |
static Parameter[] |
parameterizeArguments(ClassNode receiver,
MethodNode m)
Given a receiver and a method node, parameterize the method arguments using
available generic type information.
|
static ClassNode |
resolveClassNodeGenerics(Map<GenericsType.GenericsTypeName,GenericsType> resolvedPlaceholders,
Map<GenericsType.GenericsTypeName,GenericsType> placeholdersFromContext,
ClassNode currentType) |
protected 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.
|
protected static boolean |
typeCheckMethodsWithGenerics(ClassNode receiver,
ClassNode[] argumentTypes,
MethodNode candidateMethod) |
protected static final ClassNode Matcher_TYPE
protected static final ClassNode ArrayList_TYPE
protected static final ClassNode Collection_TYPE
protected static final ClassNode Deprecated_TYPE
protected static final ExtensionMethodCache EXTENSION_METHOD_CACHE
protected static final ClassNode GSTRING_STRING_CLASSNODE
protected static final ClassNode UNKNOWN_PARAMETER_TYPE
protected static final Comparator<MethodNode> DGM_METHOD_NODE_COMPARATOR
public static void clearExtensionMethodCache()
protected static boolean isArrayAccessExpression(Expression expression)
expression
- an expressionpublic static boolean isWithCall(String name, Expression arguments)
name
- name of the method calledarguments
- method call argumentsprotected static Variable findTargetVariable(VariableExpression ve)
ve
- a variable expression@Deprecated protected static Set<MethodNode> findDGMMethodsForClassNode(ClassNode clazz, String name)
findDGMMethodsForClassNode(ClassLoader, ClassNode, String)
insteadpublic static Set<MethodNode> findDGMMethodsForClassNode(ClassLoader loader, ClassNode clazz, String name)
@Deprecated protected static void findDGMMethodsForClassNode(ClassNode clazz, String name, TreeSet<MethodNode> accumulator)
findDGMMethodsForClassNode(ClassLoader, ClassNode, String, TreeSet)
insteadprotected static void findDGMMethodsForClassNode(ClassLoader loader, ClassNode clazz, String name, TreeSet<MethodNode> accumulator)
public static int allParametersAndArgumentsMatch(Parameter[] parameters, ClassNode[] argumentTypes)
public static boolean isCompareToBoolean(int op)
public static boolean isAssignment(int op)
public static boolean checkCompatibleAssignmentTypes(ClassNode left, ClassNode right)
left
- the class to be assigned toright
- the assignee classpublic static boolean checkCompatibleAssignmentTypes(ClassNode left, ClassNode right, Expression rightExpression)
public static boolean checkCompatibleAssignmentTypes(ClassNode left, ClassNode right, Expression rightExpression, boolean allowConstructorCoercion)
public static boolean isWildcardLeftHandSide(ClassNode node)
node
- the classnode to testpublic static boolean isBeingCompiled(ClassNode node)
public static boolean implementsInterfaceOrIsSubclassOf(ClassNode type, ClassNode superOrInterface)
@Deprecated public static List<MethodNode> findDGMMethodsByNameAndArguments(ClassNode receiver, String name, ClassNode[] args)
findDGMMethodsByNameAndArguments(ClassLoader, ClassNode, String, ClassNode[], List)
insteadpublic static List<MethodNode> findDGMMethodsByNameAndArguments(ClassLoader loader, ClassNode receiver, String name, ClassNode[] args)
@Deprecated public static List<MethodNode> findDGMMethodsByNameAndArguments(ClassNode receiver, String name, ClassNode[] args, List<MethodNode> methods)
findDGMMethodsByNameAndArguments(ClassLoader, ClassNode, String, ClassNode[], List)
insteadpublic static List<MethodNode> findDGMMethodsByNameAndArguments(ClassLoader loader, ClassNode receiver, String name, ClassNode[] args, List<MethodNode> methods)
public static boolean isUsingUncheckedGenerics(ClassNode node)
node
- the node to testpublic static List<MethodNode> chooseBestMethod(ClassNode receiver, Collection<MethodNode> methods, ClassNode... argumentTypes)
receiver
- methods
- candidate methodsargumentTypes
- argument typespublic static Parameter[] parameterizeArguments(ClassNode receiver, MethodNode m)
receiver
- the classm
- the methodpublic static boolean isUsingGenericsOrIsArrayUsingGenerics(ClassNode cn)
cn
- a class node for which to check if it is using genericsprotected static GenericsType fullyResolve(GenericsType gt, Map<GenericsType.GenericsTypeName,GenericsType> placeholders)
protected static ClassNode fullyResolveType(ClassNode type, Map<GenericsType.GenericsTypeName,GenericsType> placeholders)
protected static boolean typeCheckMethodArgumentWithGenerics(ClassNode parameterType, ClassNode argumentType, boolean lastArg)
parameterType
- the parameter type of a methodargumentType
- the type of the argument passed to the methodprotected static boolean typeCheckMethodsWithGenerics(ClassNode receiver, ClassNode[] argumentTypes, MethodNode candidateMethod)
public static ClassNode resolveClassNodeGenerics(Map<GenericsType.GenericsTypeName,GenericsType> resolvedPlaceholders, Map<GenericsType.GenericsTypeName,GenericsType> placeholdersFromContext, ClassNode currentType)
public static ClassNode getCorrectedClassNode(ClassNode type, ClassNode superClass, boolean handlingGenerics)
public static boolean isUnboundedWildcard(GenericsType gt)
public static List<MethodNode> filterMethodsByVisibility(List<MethodNode> methodNodeList, ClassNode enclosingClassNode)
methodNodeList
- method nodes to filterenclosingClassNode
- the enclosing classpublic static boolean isGStringOrGStringStringLUB(ClassNode node)
public static boolean isParameterizedWithGStringOrGStringString(ClassNode node)
node
- the node to be testedpublic static boolean isParameterizedWithString(ClassNode node)
node
- the node to be testedpublic static boolean missesGenericsTypes(ClassNode cn)
public static Object evaluateExpression(Expression expr, CompilerConfiguration config)
If this method throws an exception, then the expression cannot be evaluated on its own.
expr
- the expression to be evaluatedconfig
- the compiler configurationpublic static Set<ClassNode> collectAllInterfaces(ClassNode node)
node
- a class for which we want to retrieve all interfacespublic static boolean isClassClassNodeWrappingConcreteType(ClassNode classNode)
classNode
- a class node to be testedpublic static List<MethodNode> findSetters(ClassNode cn, String setterName, boolean voidOnly)
public static ClassNode isTraitSelf(VariableExpression vexp)