Merge branch 'master' into commonDb
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Lixfel 2022-09-26 10:05:15 +02:00
Commit 3da8d04f35
4 geänderte Dateien mit 46 neuen und 13 gelöschten Zeilen

Datei anzeigen

@ -65,13 +65,10 @@ public class LinkageProcessor extends AbstractProcessor {
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
String name = new File(System.getProperty("user.dir")).getName();
if (name.contains(".")) name = name.substring(0, name.indexOf('.'));
name = name.toLowerCase();
name = new File(System.getProperty("user.dir")).getName().replaceAll("[^a-zA-Z]", "").toLowerCase();
messager = processingEnv.getMessager();
this.name = name;
packageName = "de.steamwar." + name + ".linkage";
className = "LinkageUtils";
mainClass();
@ -118,10 +115,10 @@ public class LinkageProcessor extends AbstractProcessor {
Writer writer = processingEnv.getFiler().createSourceFile("de.steamwar." + name + ".linkage.LinkageUtils").openWriter();
BuildPlan buildPlan = new BuildPlan(packageName, className);
buildPlan.addImport("de.steamwar.linkage.LinkageType");
Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(Linked.class);
Map<String, TypeElement> neededFields = new HashMap<>();
Set<Runnable> fieldInjections = new HashSet<>();
for (Element element : elements) {
if (element.getKind() != ElementKind.CLASS) {
continue;
@ -159,8 +156,10 @@ public class LinkageProcessor extends AbstractProcessor {
TypeElement fieldType = (TypeElement) ((DeclaredType) variableElement.asType()).asElement();
neededFields.put(fieldType.getQualifiedName().toString(), fieldType);
specialElements(typeElement, buildPlan, buildPlan::addStaticLine, () -> {
buildPlan.addStaticLine(getElement(typeElement, neededFields) + "." + variableElement.getSimpleName().toString() + " = " + getElement((TypeElement) ((DeclaredType) variableElement.asType()).asElement(), neededFields) + ";");
fieldInjections.add(() -> {
specialElements(typeElement, buildPlan, buildPlan::addStaticLine, () -> {
buildPlan.addStaticLine(getElement(typeElement, neededFields) + "." + variableElement.getSimpleName().toString() + " = " + getElement((TypeElement) ((DeclaredType) variableElement.asType()).asElement(), neededFields) + ";");
});
});
}
}
@ -168,8 +167,14 @@ public class LinkageProcessor extends AbstractProcessor {
buildPlan.addImport(typeElement.getQualifiedName().toString());
String t = typeElement.getSimpleName().toString();
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<>();
for (Element element : elements) {
@ -279,7 +284,7 @@ public class LinkageProcessor extends AbstractProcessor {
linkages.computeIfAbsent(interfaceType.method(), s -> new ArrayList<>()).add(interfaceType);
}
}
if (!linkages.containsKey(plain_GENERIC.method())) {
if (linkages.size() == 1 && linkages.containsKey("unlink")) {
linkages.put(plain_GENERIC.method(), Collections.singletonList(plain_GENERIC));
}
return linkages;

Datei anzeigen

@ -0,0 +1,23 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2022 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.linkage.api;
public interface Plain {
}

Datei anzeigen

@ -53,7 +53,7 @@ public class Listener_SPIGOT implements LinkageType {
});
eventClasses.forEach((s, eventType) -> {
if (buildPlan.hasMethod(s)) return;
if (buildPlan.hasMethod(eventType.getSimpleName().toString())) return;
buildPlan.addImport("org.bukkit.event.HandlerList");
buildPlan.addImport("org.bukkit.event.Listener");
buildPlan.addImport("java.util.function.Consumer");
@ -79,7 +79,12 @@ public class Listener_SPIGOT implements LinkageType {
});
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) -> {
AnnotationMirror eventHandler = executableElement.getAnnotationMirrors().stream().filter(annotationMirror -> annotationMirror.getAnnotationType().asElement().getSimpleName().toString().equals("EventHandler")).findFirst().orElse(null);
if (eventHandler == null) {
@ -94,7 +99,7 @@ public class Listener_SPIGOT implements LinkageType {
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 + ");");
});
}
}

Datei anzeigen

@ -34,6 +34,6 @@ public class Plain_GENERIC implements LinkageType {
@Override
public void generateCode(BuildPlan buildPlan, MethodBuilder method, String instance, TypeElement typeElement) {
method.addLine(instance + ";");
if (instance.startsWith("new ")) method.addLine(instance + ";");
}
}