/** * Gets the variable of the class that represents the variable for the * field. * * @param property * The field to match the variable to. * @param typeVariable * The variable to match. * @return The variable of the declaring class. */ public static TypeVariable<?> getSuperDeclaration(final Member property, final TypeVariable<?> typeVariable) { TypeVariable<?> result = typeVariable; Class<?> declaring = property.getDeclaringType(); while (!CheckUtil.isNull(declaring)) { for (final TypeVariable<?> declaringTypeVariable : declaring.getTypeParameters()) { if (result.equals(declaringTypeVariable)) { result = declaringTypeVariable; } } declaring = declaring.getDeclaringClass(); } return result; }
final Class<?> declaringClass = GenericsUtil.getDeclaringClass(property.getDeclaringType(), typeVariable); int index = -1; final TypeVariable<?>[] typeVariables = declaringClass.getTypeParameters();
/** * Finds originating type for this field. * * @param properties * The fields to look through. * @return The true type. */ public static Type getRealType(final Deque<? extends Member> properties) { final Member property = properties.pop(); final Type fieldType = property.getGenericType(); Type result = null; if (fieldType instanceof TypeVariable) { final TypeVariable<?> typeVariable = (TypeVariable<?>) fieldType; final Class<?> declaringType = GenericsUtil.getDeclaringClass(property.getDeclaringType(), typeVariable); final TypeVariable<?> superTypeVariable = GenericsUtil.getSuperDeclaration(property, typeVariable); final int param = GenericsUtil.getRealParameter(superTypeVariable); result = GenericsUtil.getPropertyGenericType(declaringType, param, properties); } else if (fieldType instanceof Class) { result = fieldType; } else if (fieldType instanceof ParameterizedType) { final ParameterizedType pType = (ParameterizedType) fieldType; result = pType.getRawType(); } return result; }