Fix eager instantiation with special other annotation
Dieser Commit ist enthalten in:
Ursprung
bc7ae5cf9a
Commit
0c68dfd19d
@ -115,10 +115,10 @@ public class LinkageProcessor extends AbstractProcessor {
|
|||||||
Writer writer = processingEnv.getFiler().createSourceFile("de.steamwar." + name + ".linkage.LinkageUtils").openWriter();
|
Writer writer = processingEnv.getFiler().createSourceFile("de.steamwar." + name + ".linkage.LinkageUtils").openWriter();
|
||||||
|
|
||||||
BuildPlan buildPlan = new BuildPlan(packageName, className);
|
BuildPlan buildPlan = new BuildPlan(packageName, className);
|
||||||
buildPlan.addImport("de.steamwar.linkage.LinkageType");
|
|
||||||
|
|
||||||
Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(Linked.class);
|
Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(Linked.class);
|
||||||
Map<String, TypeElement> neededFields = new HashMap<>();
|
Map<String, TypeElement> neededFields = new HashMap<>();
|
||||||
|
Set<Runnable> fieldInjections = new HashSet<>();
|
||||||
for (Element element : elements) {
|
for (Element element : elements) {
|
||||||
if (element.getKind() != ElementKind.CLASS) {
|
if (element.getKind() != ElementKind.CLASS) {
|
||||||
continue;
|
continue;
|
||||||
@ -156,8 +156,10 @@ public class LinkageProcessor extends AbstractProcessor {
|
|||||||
TypeElement fieldType = (TypeElement) ((DeclaredType) variableElement.asType()).asElement();
|
TypeElement fieldType = (TypeElement) ((DeclaredType) variableElement.asType()).asElement();
|
||||||
neededFields.put(fieldType.getQualifiedName().toString(), fieldType);
|
neededFields.put(fieldType.getQualifiedName().toString(), fieldType);
|
||||||
|
|
||||||
specialElements(typeElement, buildPlan, buildPlan::addStaticLine, () -> {
|
fieldInjections.add(() -> {
|
||||||
buildPlan.addStaticLine(getElement(typeElement, neededFields) + "." + variableElement.getSimpleName().toString() + " = " + getElement((TypeElement) ((DeclaredType) variableElement.asType()).asElement(), neededFields) + ";");
|
specialElements(typeElement, buildPlan, buildPlan::addStaticLine, () -> {
|
||||||
|
buildPlan.addStaticLine(getElement(typeElement, neededFields) + "." + variableElement.getSimpleName().toString() + " = " + getElement((TypeElement) ((DeclaredType) variableElement.asType()).asElement(), neededFields) + ";");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -165,8 +167,14 @@ public class LinkageProcessor extends AbstractProcessor {
|
|||||||
buildPlan.addImport(typeElement.getQualifiedName().toString());
|
buildPlan.addImport(typeElement.getQualifiedName().toString());
|
||||||
String t = typeElement.getSimpleName().toString();
|
String t = typeElement.getSimpleName().toString();
|
||||||
t = t.substring(0, 1).toLowerCase() + t.substring(1);
|
t = t.substring(0, 1).toLowerCase() + t.substring(1);
|
||||||
buildPlan.addField(new FieldBuilder(typeElement.getSimpleName().toString(), t, "new " + typeElement.getSimpleName().toString() + "()"));
|
buildPlan.addField(new FieldBuilder(typeElement.getSimpleName().toString(), t));
|
||||||
|
|
||||||
|
String finalT = t;
|
||||||
|
specialElements(typeElement, buildPlan, buildPlan::addStaticLine, () -> {
|
||||||
|
buildPlan.addStaticLine(finalT + " = new " + typeElement.getSimpleName().toString() + "();");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
fieldInjections.forEach(Runnable::run);
|
||||||
|
|
||||||
Map<String, MethodBuilder> methods = new HashMap<>();
|
Map<String, MethodBuilder> methods = new HashMap<>();
|
||||||
for (Element element : elements) {
|
for (Element element : elements) {
|
||||||
|
@ -79,7 +79,12 @@ public class Listener_SPIGOT implements LinkageType {
|
|||||||
});
|
});
|
||||||
|
|
||||||
String localInstance = "local" + typeElement.getSimpleName().toString();
|
String localInstance = "local" + typeElement.getSimpleName().toString();
|
||||||
method.addLine(typeElement.getSimpleName() + " " + localInstance + " = " + instance + ";");
|
if (!instance.startsWith("new ")) {
|
||||||
|
localInstance = instance;
|
||||||
|
} else {
|
||||||
|
method.addLine(typeElement.getSimpleName() + " " + localInstance + " = " + instance + ";");
|
||||||
|
}
|
||||||
|
String finalLocalInstance = localInstance;
|
||||||
eventMethods.forEach((type, executableElement) -> {
|
eventMethods.forEach((type, executableElement) -> {
|
||||||
AnnotationMirror eventHandler = executableElement.getAnnotationMirrors().stream().filter(annotationMirror -> annotationMirror.getAnnotationType().asElement().getSimpleName().toString().equals("EventHandler")).findFirst().orElse(null);
|
AnnotationMirror eventHandler = executableElement.getAnnotationMirrors().stream().filter(annotationMirror -> annotationMirror.getAnnotationType().asElement().getSimpleName().toString().equals("EventHandler")).findFirst().orElse(null);
|
||||||
if (eventHandler == null) {
|
if (eventHandler == null) {
|
||||||
@ -94,7 +99,7 @@ public class Listener_SPIGOT implements LinkageType {
|
|||||||
ignoreCancelled = entry.getValue().getValue().toString();
|
ignoreCancelled = entry.getValue().getValue().toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
method.addLine(type.getSimpleName().toString() + "(" + localInstance + ", " + localInstance + "::" + executableElement.getSimpleName().toString() + ", EventPriority." + priority + ", " + ignoreCancelled + ");");
|
method.addLine(type.getSimpleName().toString() + "(" + finalLocalInstance + ", " + finalLocalInstance + "::" + executableElement.getSimpleName().toString() + ", EventPriority." + priority + ", " + ignoreCancelled + ");");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren