public static int getTypeParameterCount(java.lang.reflect.Type type) {
        if (type instanceof ParameterizedType) {
            return ((ParameterizedType) type).getActualTypeArguments().length;
        } else if (type instanceof TypeVariable) {
            return getTypeParameterCount(((TypeVariable) type).getBounds()[0]);
        } else {
            return 0;
        }
    }
ReflectionUtils provides Reflection related functionality

@author tiwe
querydsl-core/src/main/java/com/querydsl/core/util/ReflectionUtils.java