Simplify LinkageProcessor
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2022-09-26 15:58:06 +02:00
Ursprung 0c68dfd19d
Commit 860d082770

Datei anzeigen

@ -28,7 +28,10 @@ import lombok.SneakyThrows;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeMirror;
import javax.tools.Diagnostic;
@ -116,25 +119,23 @@ public class LinkageProcessor extends AbstractProcessor {
BuildPlan buildPlan = new BuildPlan(packageName, className);
Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(Linked.class);
Set<TypeElement> elements = roundEnv.getElementsAnnotatedWith(Linked.class).stream()
.filter(element -> element.getKind() == ElementKind.CLASS)
.map(TypeElement.class::cast)
.collect(Collectors.toSet());
Map<String, TypeElement> neededFields = new HashMap<>();
Set<Runnable> fieldInjections = new HashSet<>();
for (Element element : elements) {
if (element.getKind() != ElementKind.CLASS) {
continue;
}
TypeElement typeElement = (TypeElement) element;
Linked linked = element.getAnnotation(Linked.class);
if (linked == null) {
continue;
}
for (TypeElement typeElement : elements) {
if (getLinkagesOfType(typeElement).size() > 1) {
neededFields.put(typeElement.getQualifiedName().toString(), typeElement);
}
List<VariableElement> variableElements = typeElement.getEnclosedElements().stream().filter(e -> e.getKind() == ElementKind.FIELD).map(VariableElement.class::cast).filter(e -> {
return e.getAnnotation(LinkedInstance.class) != null;
}).collect(Collectors.toList());
List<VariableElement> variableElements = typeElement.getEnclosedElements().stream()
.filter(e -> e.getKind() == ElementKind.FIELD)
.map(VariableElement.class::cast)
.filter(e -> e.getAnnotation(LinkedInstance.class) != null)
.collect(Collectors.toList());
if (variableElements.isEmpty()) {
continue;
}
@ -177,12 +178,7 @@ public class LinkageProcessor extends AbstractProcessor {
fieldInjections.forEach(Runnable::run);
Map<String, MethodBuilder> methods = new HashMap<>();
for (Element element : elements) {
if (element.getKind() != ElementKind.CLASS) {
continue;
}
TypeElement typeElement = (TypeElement) element;
for (TypeElement typeElement : elements) {
System.out.println("Found element: " + typeElement.getQualifiedName().toString());
Map<String, List<LinkageType>> linkages = getLinkagesOfType(typeElement);
if (linkages.isEmpty()) {
@ -211,11 +207,11 @@ public class LinkageProcessor extends AbstractProcessor {
}
private String getElement(TypeElement typeElement, Map<String, TypeElement> neededFields) {
String s = typeElement.getSimpleName().toString();
if (neededFields.containsKey(typeElement.getQualifiedName().toString())) {
String s = typeElement.getSimpleName().toString();
return s.substring(0, 1).toLowerCase() + s.substring(1);
}
return "new " + typeElement.getSimpleName().toString() + "()";
return "new " + s + "()";
}
private void specialElements(TypeElement typeElement, BuildPlan buildPlan, Consumer<String> stringConsumer, Runnable inner) {