public static Class getTypeClass()

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


    public static Class<?> getTypeClass(Type type)
    {
        if (type == null)
        {
            return null;
        }
        if (type instanceof Class<?>)
        {
            return (Class<?>)type;
        }
        else if (type instanceof ParameterizedType)
        {
            return (Class<?>)((ParameterizedType)type).getRawType();
        }
        else if (type instanceof GenericArrayType)
        {
            Type componentType = ((GenericArrayType)type).getGenericComponentType();
            Class<?> componentClass = getTypeClass(componentType);
            if (componentClass != null)
            {
                return Array.newInstance(componentClass, 0).getClass();
            }
        }
        else if (type instanceof TypeVariable)
        {
            Type[] bounds = TypeUtils.getImplicitBounds((TypeVariable)type);
            if (bounds.length == 1) return getTypeClass(bounds[0]);
        }
        else if (type instanceof WildcardType)
        {
            Type[] bounds = TypeUtils.getImplicitUpperBounds((WildcardType)type);
            if (bounds.length == 1) return getTypeClass(bounds[0]);
        }
        return null;
    }