Class StaticTypeCheckingSupport

    • Field Detail

      • Matcher_TYPE

        protected static final ClassNode Matcher_TYPE
      • ArrayList_TYPE

        protected static final ClassNode ArrayList_TYPE
      • Collection_TYPE

        protected static final ClassNode Collection_TYPE
      • Deprecated_TYPE

        protected static final ClassNode Deprecated_TYPE

        protected static final EXTENSION_METHOD_CACHE

        protected static final ClassNode GSTRING_STRING_CLASSNODE

        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.

        protected static final 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.
    • Constructor Detail

      • StaticTypeCheckingSupport

        public StaticTypeCheckingSupport()
    • Method Detail

      • clearExtensionMethodCache

        public static void clearExtensionMethodCache​(ClassLoader loader)
      • isArrayAccessExpression

        protected static boolean isArrayAccessExpression​(Expression expression)
        Returns true for expressions of the form x[...]
        expression - an expression
        true for array access expressions
      • 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
        name - name of the method called
        callArguments - arguments of the method
        true if the name is "with" and arguments consist of a single closure
      • findTargetVariable

        protected static Variable findTargetVariable​(VariableExpression ve)
        Given a variable expression, returns the ultimately accessed variable.
        ve - a variable expression
        the target variable
      • allParametersAndArgumentsMatch

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

        public static boolean isCompareToBoolean​(int op)
      • 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.
        left - the class to be assigned to
        right - the assignee class
        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)
      • 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.
        node - the classnode to test
        true if it's an Object, String, boolean, Boolean or Class.
      • isBeingCompiled

        public static boolean isBeingCompiled​(ClassNode node)
      • implementsInterfaceOrIsSubclassOf

        public static boolean implementsInterfaceOrIsSubclassOf​(ClassNode type,
                                                                ClassNode superOrInterface)
      • isUsingUncheckedGenerics

        public 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() }
        node - the node to test
        true if it is using any placeholder in generics 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.
        receiver - the class
        m - the method
        the parameterized arguments
      • isUsingGenericsOrIsArrayUsingGenerics

        public 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.
        cn - a class node for which to check if it is using generics
        true if the type (or component type) is using generics
      • typeCheckMethodArgumentWithGenerics

        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.
        parameterType - the parameter type of a method
        argumentType - the type of the argument passed to the method
      • typeCheckMethodsWithGenerics

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

        public static ClassNode getCorrectedClassNode​(ClassNode type,
                                                      ClassNode superClass,
                                                      boolean handlingGenerics)
      • isUnboundedWildcard

        public static boolean isUnboundedWildcard​(GenericsType gt)
      • isGStringOrGStringStringLUB

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

        public static boolean isParameterizedWithGStringOrGStringString​(ClassNode node)
        node - the node to be tested
        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)
        node - the node to be tested
        true if the node is using generics types and one of those types is a string
      • missesGenericsTypes

        public static boolean missesGenericsTypes​(ClassNode cn)
      • evaluateExpression

        public static Object evaluateExpression​(Expression expr,
                                                CompilerConfiguration config)
        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.

        expr - the expression to be evaluated
        config - the compiler configuration
        the result of the expression
      • collectAllInterfaces

        public static Set<ClassNode> collectAllInterfaces​(ClassNode node)
        Collects all interfaces of a class node, including those defined by the super class.
        node - a class for which we want to retrieve all interfaces
        a set of interfaces implemented by this class node
      • isClassClassNodeWrappingConcreteType

        public 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.
        classNode - a class node to be tested
        true if it is the class node for Class and its generic type is a real class