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