Groovy 2.2.2

org.codehaus.groovy.transform.stc
[Java] Class StaticTypeCheckingSupport

java.lang.Object
  org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport

public abstract class StaticTypeCheckingSupport
extends Object

Static support methods for StaticTypeCheckingVisitor.


Field Summary
protected static ClassNode ArrayList_TYPE

protected static ClassNode Collection_TYPE

protected static Comparator 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 ClassNode Deprecated_TYPE

protected static StaticTypeCheckingSupport.ExtensionMethodCache EXTENSION_METHOD_CACHE

protected static ClassNode GSTRING_STRING_CLASSNODE

protected static ClassNode Matcher_TYPE

protected static Map NUMBER_TYPES

protected static ClassNode UNKNOWN_PARAMETER_TYPE

This is for internal use only.

 
Method Summary
static int allParametersAndArgumentsMatch(Parameter[] params, ClassNode[] args)

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 chooseBestMethod(ClassNode receiver, Collection methods, ClassNode... args)

static Set collectAllInterfaces(ClassNode node)

static Object evaluateExpression(Expression expr, CompilerConfiguration config)

static List findDGMMethodsByNameAndArguments(ClassNode receiver, String name, ClassNode[] args)

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 List findDGMMethodsByNameAndArguments(ClassLoader loader, ClassNode receiver, String name, ClassNode[] args)

static List findDGMMethodsByNameAndArguments(ClassNode receiver, String name, ClassNode[] args, List methods)

static List findDGMMethodsByNameAndArguments(ClassLoader loader, ClassNode receiver, String name, ClassNode[] args, List methods)

protected static Set findDGMMethodsForClassNode(ClassNode clazz, String name)

@deprecated Use findDGMMethodsForClassNode(ClassLoader,ClassNode,String) instead

protected static Set findDGMMethodsForClassNode(ClassLoader loader, ClassNode clazz, String name)

protected static void findDGMMethodsForClassNode(ClassNode clazz, String name, TreeSet accumulator)

@deprecated Use findDGMMethodsForClassNode(ClassLoader, ClassNode, String, TreeSet) instead

protected static void findDGMMethodsForClassNode(ClassLoader loader, ClassNode clazz, String name, TreeSet accumulator)

protected static Variable findTargetVariable(VariableExpression ve)

Given a variable expression, returns the ultimately accessed variable.

protected static GenericsType fullyResolve(GenericsType gt, Map placeholders)

protected static ClassNode fullyResolveType(ClassNode type, Map placeholders)

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)

static boolean isGStringOrGStringStringLUB(ClassNode node)

A helper method that can be used to evaluate expressions as found in annotation parameters.

static boolean isParameterizedWithGStringOrGStringString(ClassNode node)

static boolean isParameterizedWithString(ClassNode node)

static boolean isUsingGenericsOrIsArrayUsingGenerics(ClassNode cn)

static boolean isUsingUncheckedGenerics(ClassNode node)

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 callArguments)

Called on method call checks in order to determine if a method call corresponds to the idiomatic o.with { ... } structure

static boolean missesGenericsTypes(ClassNode cn)

static Parameter[] parameterizeArguments(ClassNode receiver, MethodNode m)

Given a parameter, builds a new parameter for which the known generics placeholders are resolved.

static ClassNode resolveClassNodeGenerics(Map resolvedPlaceholders, Map placeholdersFromContext, ClassNode currentType)

protected static boolean typeCheckMethodArgumentWithGenerics(ClassNode parameterType, ClassNode argumentType, boolean lastArg)

protected static boolean typeCheckMethodsWithGenerics(ClassNode receiver, ClassNode[] arguments, MethodNode candidateMethod)

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Field Detail

ArrayList_TYPE

protected static final ClassNode ArrayList_TYPE


Collection_TYPE

protected static final ClassNode Collection_TYPE


DGM_METHOD_NODE_COMPARATOR

protected static final Comparator 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.


Deprecated_TYPE

protected static final ClassNode Deprecated_TYPE


EXTENSION_METHOD_CACHE

protected static final StaticTypeCheckingSupport.ExtensionMethodCache EXTENSION_METHOD_CACHE


GSTRING_STRING_CLASSNODE

protected static final ClassNode GSTRING_STRING_CLASSNODE


Matcher_TYPE

protected static final ClassNode Matcher_TYPE


NUMBER_TYPES

protected static final Map NUMBER_TYPES


UNKNOWN_PARAMETER_TYPE

protected 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.


 
Method Detail

allParametersAndArgumentsMatch

public static int allParametersAndArgumentsMatch(Parameter[] params, ClassNode[] args)
Checks that arguments and parameter types match.
Parameters:
params - method parameters
args - type arguments
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


checkCompatibleAssignmentTypes

public 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


checkCompatibleAssignmentTypes

public static boolean checkCompatibleAssignmentTypes(ClassNode left, ClassNode right, Expression rightExpression)


checkCompatibleAssignmentTypes

public static boolean checkCompatibleAssignmentTypes(ClassNode left, ClassNode right, Expression rightExpression, boolean allowConstructorCoercion)


chooseBestMethod

public static List chooseBestMethod(ClassNode receiver, Collection methods, ClassNode... args)


collectAllInterfaces

public static Set collectAllInterfaces(ClassNode node)


evaluateExpression

public static Object evaluateExpression(Expression expr, CompilerConfiguration config)


findDGMMethodsByNameAndArguments

@Deprecatedreturn false;
public static List findDGMMethodsByNameAndArguments(ClassNode receiver, String name, ClassNode[] args)
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


findDGMMethodsByNameAndArguments

public static List findDGMMethodsByNameAndArguments(ClassLoader loader, ClassNode receiver, String name, ClassNode[] args)


findDGMMethodsByNameAndArguments

@Deprecatedpublic static List chooseBestMethod(final ClassNode receiver, Collection methods, ClassNode... args) {
public static List findDGMMethodsByNameAndArguments(ClassNode receiver, String name, ClassNode[] args, List methods)


findDGMMethodsByNameAndArguments

public static List findDGMMethodsByNameAndArguments(ClassLoader loader, ClassNode receiver, String name, ClassNode[] args, List methods)


findDGMMethodsForClassNode

@Deprecated
protected static Set findDGMMethodsForClassNode(ClassNode clazz, String name)
deprecated:
Use findDGMMethodsForClassNode(ClassLoader,ClassNode,String) instead


findDGMMethodsForClassNode

protected static Set findDGMMethodsForClassNode(ClassLoader loader, ClassNode clazz, String name)


findDGMMethodsForClassNode

@Deprecated
protected static void findDGMMethodsForClassNode(ClassNode clazz, String name, TreeSet accumulator)
deprecated:
Use findDGMMethodsForClassNode(ClassLoader, ClassNode, String, TreeSet) instead


findDGMMethodsForClassNode

protected static void findDGMMethodsForClassNode(ClassLoader loader, ClassNode clazz, String name, TreeSet accumulator)


findTargetVariable

protected static Variable findTargetVariable(VariableExpression ve)
Given a variable expression, returns the ultimately accessed variable.
Parameters:
ve - a variable expression
Returns:
the target variable


fullyResolve

protected static GenericsType fullyResolve(GenericsType gt, Map placeholders)


fullyResolveType

protected static ClassNode fullyResolveType(ClassNode type, Map placeholders)


implementsInterfaceOrIsSubclassOf

public static boolean implementsInterfaceOrIsSubclassOf(ClassNode type, ClassNode superOrInterface)


isArrayAccessExpression

protected static boolean isArrayAccessExpression(Expression expression)
Returns true for expressions of the form x[...]
Parameters:
expression - an expression
Returns:
true for array access expressions


isAssignment

public static boolean isAssignment(int op)


isBeingCompiled

public static boolean isBeingCompiled(ClassNode node)


isClassClassNodeWrappingConcreteType

public static boolean isClassClassNodeWrappingConcreteType(ClassNode classNode)


isGStringOrGStringStringLUB

public static boolean isGStringOrGStringStringLUB(ClassNode node)
A helper method that can be used to evaluate 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 this method throws an exception, then the expression cannot be evaluated on its own.
Parameters:
expr - the expression to be evaluated
config - the compiler configuration
Returns:
the result of the expression


isParameterizedWithGStringOrGStringString

public static boolean isParameterizedWithGStringOrGStringString(ClassNode node)


isParameterizedWithString

public static boolean isParameterizedWithString(ClassNode node)


isUsingGenericsOrIsArrayUsingGenerics

public static boolean isUsingGenericsOrIsArrayUsingGenerics(ClassNode cn)


isUsingUncheckedGenerics

public static boolean isUsingUncheckedGenerics(ClassNode node)


isWildcardLeftHandSide

public 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.


isWithCall

public static boolean isWithCall(String name, Expression callArguments)
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
callArguments - arguments of the method
Returns:
true if the name is "with" and arguments consist of a single closure


missesGenericsTypes

public static boolean missesGenericsTypes(ClassNode cn)


parameterizeArguments

public static Parameter[] parameterizeArguments(ClassNode receiver, MethodNode m)
Given a parameter, builds a new parameter for which the known generics placeholders are resolved.
Parameters:
genericFromReceiver - resolved generics from the receiver of the message
placeholdersFromContext, - resolved generics from the method context
methodParameter - the method parameter for which we want to resolve generic types
paramType - the (unresolved) type of the method parameter
Returns:
a new parameter with the same name and type as the original one, but with resolved generic types


resolveClassNodeGenerics

public static ClassNode resolveClassNodeGenerics(Map resolvedPlaceholders, Map placeholdersFromContext, ClassNode currentType)


typeCheckMethodArgumentWithGenerics

protected static boolean typeCheckMethodArgumentWithGenerics(ClassNode parameterType, ClassNode argumentType, boolean lastArg)


typeCheckMethodsWithGenerics

protected static boolean typeCheckMethodsWithGenerics(ClassNode receiver, ClassNode[] arguments, MethodNode candidateMethod)


 

Copyright © 2003-2013 The Codehaus. All rights reserved.