org.codehaus.groovy.transform.stc
Class StaticTypeCheckingSupport

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

public abstract class StaticTypeCheckingSupport
extends java.lang.Object

Static support methods for StaticTypeCheckingVisitor.


Constructor Summary
StaticTypeCheckingSupport()
           
 
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 java.util.List<MethodNode> chooseBestMethod(ClassNode receiver, java.util.Collection<MethodNode> methods, ClassNode... args)
          Given a list of candidate methods, returns the one which best matches the argument types
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)
           
static boolean implementsInterfaceOrIsSubclassOf(ClassNode type, ClassNode superOrInterface)
           
static boolean isAssignment(int op)
           
static boolean isBeingCompiled(ClassNode node)
           
static boolean isGStringOrGStringStringLUB(ClassNode node)
           
static boolean isParameterizedWithGStringOrGStringString(ClassNode node)
           
static boolean isParameterizedWithString(ClassNode node)
           
static boolean isWithCall(java.lang.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 receiver and a method node, parameterize the method arguments using available generic type information.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StaticTypeCheckingSupport

public StaticTypeCheckingSupport()
Method Detail

isWithCall

public static boolean isWithCall(java.lang.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

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

isAssignment

public static boolean isAssignment(int op)

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)

isBeingCompiled

public static boolean isBeingCompiled(ClassNode node)

implementsInterfaceOrIsSubclassOf

public static boolean implementsInterfaceOrIsSubclassOf(ClassNode type,
                                                        ClassNode superOrInterface)

findDGMMethodsByNameAndArguments

public static java.util.List<MethodNode> findDGMMethodsByNameAndArguments(ClassNode receiver,
                                                                          java.lang.String name,
                                                                          ClassNode[] args)

findDGMMethodsByNameAndArguments

public static java.util.List<MethodNode> findDGMMethodsByNameAndArguments(ClassNode receiver,
                                                                          java.lang.String name,
                                                                          ClassNode[] args,
                                                                          java.util.List<MethodNode> methods)

chooseBestMethod

public static java.util.List<MethodNode> chooseBestMethod(ClassNode receiver,
                                                          java.util.Collection<MethodNode> methods,
                                                          ClassNode... args)
Given a list of candidate methods, returns the one which best matches the argument types

Parameters:
receiver -
methods - candidate methods
args - argument types
Returns:
the list of methods which best matches the argument types. It is still possible that multiple methods match the argument types.

parameterizeArguments

public 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

isGStringOrGStringStringLUB

public static boolean isGStringOrGStringStringLUB(ClassNode node)
Returns:
true if the class node is either a GString or the LUB of String and GString.

isParameterizedWithGStringOrGStringString

public 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

isParameterizedWithString

public 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

missesGenericsTypes

public static boolean missesGenericsTypes(ClassNode cn)