public static boolean isStrictMethodInvocationConvertible()

in velocity-engine-core/src/main/java/org/apache/velocity/util/introspection/IntrospectionUtils.java [271:335]


    public static boolean isStrictMethodInvocationConvertible(Type formal,
                                                              Class<?> actual,
                                                              boolean possibleVarArg)
    {
        Class<?> formalClass = getTypeClass(formal);
        if (formalClass != null)
        {
            /* Check for nullity */
            if (actual == null)
            {
                return !formalClass.isPrimitive();
            }

            /* Check for identity or widening reference conversion */
            if (formalClass.isAssignableFrom(actual))
            {
                return true;
            }

            /* Check for widening primitive conversion. */
            if (formalClass.isPrimitive())
            {
                if (formal == Short.TYPE && (actual == Byte.TYPE))
                    return true;
                if (formal == Integer.TYPE &&
                    (actual == Short.TYPE || actual == Byte.TYPE))
                    return true;
                if (formal == Long.TYPE &&
                    (actual == Integer.TYPE || actual == Short.TYPE ||
                        actual == Byte.TYPE))
                    return true;
                if (formal == Float.TYPE &&
                    (actual == Long.TYPE || actual == Integer.TYPE ||
                        actual == Short.TYPE || actual == Byte.TYPE))
                    return true;
                if (formal == Double.TYPE &&
                    (actual == Float.TYPE || actual == Long.TYPE ||
                        actual == Integer.TYPE || actual == Short.TYPE ||
                        actual == Byte.TYPE))
                    return true;
            }

            /* Check for vararg conversion. */
            if (possibleVarArg && formalClass.isArray())
            {
                if (actual.isArray())
                {
                    actual = actual.getComponentType();
                }
                return isStrictMethodInvocationConvertible(formalClass.getComponentType(),
                    actual, false);
            }
            return false;
        }
        else
        {
            // no distinction between strict and implicit, not a big deal in this case
            if (TypeUtils.isAssignable(actual, formal))
            {
                return true;
            }
            return possibleVarArg && TypeUtils.isArrayType(formal) &&
                TypeUtils.isAssignable(actual, TypeUtils.getArrayComponentType(formal));
        }
    }