use of com.massivecraft.massivecore.command.editor.annotation.EditorTypeInner in project MassiveCore by MassiveCraft.
the class RegistryType method getInnerTypes.
// -------------------------------------------- //
// GET INNER TYPES
// -------------------------------------------- //
public static List<Type<?>> getInnerTypes(Field field, java.lang.reflect.Type fieldType, int amountRequired) {
// Annotation
if (field != null) {
try {
EditorTypeInner annotation = ReflectionUtil.getAnnotation(field, EditorTypeInner.class);
if (annotation != null) {
// Create
List<Type<?>> ret = new MassiveList<>();
// Fill
Class<?>[] innerTypeClasses = annotation.value();
for (Class<?> innerTypeClass : innerTypeClasses) {
Type<?> innerType = ReflectionUtil.getSingletonInstance(innerTypeClass);
ret.add(innerType);
}
// Return
return ret;
}
} catch (Throwable t) {
// This has to do with backwards compatibility (Usually 1.7).
// The annotations may trigger creation of type class instances.
// Those type classes may refer to Bukkit classes not present.
// This issue was first encountered for TypeDataItemStack.
}
if (fieldType == null) {
fieldType = field.getGenericType();
}
}
// Reflection
if (fieldType != null) {
if (fieldType instanceof ParameterizedType) {
// Create
List<Type<?>> ret = new MassiveList<>();
// Fill
ParameterizedType parameterizedType = (ParameterizedType) fieldType;
int count = 0;
for (java.lang.reflect.Type actualTypeArgument : parameterizedType.getActualTypeArguments()) {
boolean strictThrow = (amountRequired < 0 || count < amountRequired);
Type<?> innerType = getType(actualTypeArgument, strictThrow);
ret.add(innerType);
count++;
}
// Return
return ret;
}
throw new IllegalArgumentException("Not ParameterizedType: " + fieldType);
}
throw new IllegalArgumentException("Failure");
}
Aggregations