forked from SteamWar/SteamWar
Fix MapperHandler, SupplierHandler, ValidatorHandler
Improve HandlerForVariableElement.getAnnotations() Improve HandlerForTypeMirror.isEnum Add HandlerForTypeMirror.getTypeName
This commit is contained in:
+16
-2
@@ -19,7 +19,10 @@
|
||||
|
||||
package de.steamwar.command;
|
||||
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ElementKind;
|
||||
import javax.lang.model.type.ArrayType;
|
||||
import javax.lang.model.type.DeclaredType;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.lang.model.util.Elements;
|
||||
@@ -64,8 +67,14 @@ public class HandlerForTypeMirror implements Handler.TypeWrapper {
|
||||
|
||||
@Override
|
||||
public boolean isEnum() {
|
||||
System.out.println(type);
|
||||
return false;
|
||||
if (type.getKind() != TypeKind.DECLARED) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DeclaredType declaredType = (DeclaredType) type;
|
||||
Element element = declaredType.asElement();
|
||||
|
||||
return element.getKind() == ElementKind.ENUM;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -104,4 +113,9 @@ public class HandlerForTypeMirror implements Handler.TypeWrapper {
|
||||
public String getName() {
|
||||
return type.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeName() {
|
||||
return type.toString();
|
||||
}
|
||||
}
|
||||
|
||||
+34
-4
@@ -24,8 +24,9 @@ import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.util.Elements;
|
||||
import javax.lang.model.util.Types;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.annotation.Repeatable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -74,10 +75,39 @@ public class HandlerForVariableElement implements Handler.ParameterWrapper {
|
||||
for (AnnotationMirror annotationMirror : parameter.getAnnotationMirrors()) {
|
||||
Class<?> clazz = getClass(annotationMirror.getAnnotationType().toString());
|
||||
if (clazz == null) continue;
|
||||
annotations.addAll(Arrays.asList(parameter.getAnnotationsByType((Class<? extends Annotation>) clazz)));
|
||||
annotations.add(parameter.getAnnotation((Class<? extends Annotation>) clazz));
|
||||
}
|
||||
annotations.removeIf(annotation -> !annotation.annotationType().isAnnotationPresent(Handler.Implementation.class));
|
||||
return annotations;
|
||||
List<Annotation> annotationList = new ArrayList<>();
|
||||
for (Annotation annotation : annotations) {
|
||||
try {
|
||||
Method method = annotation.annotationType().getMethod("value");
|
||||
Class<?> returnType = method.getReturnType();
|
||||
if (!returnType.isArray()) {
|
||||
annotationList.add(annotation);
|
||||
continue;
|
||||
}
|
||||
Class<?> innerReturnType = returnType.getComponentType();
|
||||
if (!(innerReturnType.isAnnotation() && innerReturnType.isAnnotationPresent(Repeatable.class))) {
|
||||
annotationList.add(annotation);
|
||||
continue;
|
||||
}
|
||||
Repeatable repeatable = innerReturnType.getAnnotation(Repeatable.class);
|
||||
Class<? extends Annotation> containerType = repeatable.value();
|
||||
if (containerType == returnType) {
|
||||
throw new UnsupportedOperationException("Repeatable annotation must have a container annotation");
|
||||
}
|
||||
try {
|
||||
Annotation[] innerAnnotations = (Annotation[]) method.invoke(annotation);
|
||||
Collections.addAll(annotationList, innerAnnotations);
|
||||
} catch (Exception e) {
|
||||
annotationList.add(annotation);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
annotationList.add(annotation);
|
||||
}
|
||||
}
|
||||
annotationList.removeIf(annotation -> !annotation.annotationType().isAnnotationPresent(Handler.Implementation.class));
|
||||
return annotationList;
|
||||
}
|
||||
|
||||
private Class<?> getClass(String name) {
|
||||
|
||||
Reference in New Issue
Block a user