Finalize Linkage
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2022-09-22 13:46:39 +02:00
Ursprung bbd4eeacd3
Commit 067acf5f62
7 geänderte Dateien mit 99 neuen und 86 gelöschten Zeilen

Datei anzeigen

@ -249,7 +249,7 @@ public class LinkageProcessor extends AbstractProcessor {
.filter(Objects::nonNull)
.forEach(type -> {
Class<? extends LinkageType> clazz = type.getClass();
if (!type.requirements(typeElement.getSuperclass().toString(), typeElement.getInterfaces().stream().map(TypeMirror::toString).collect(Collectors.toSet()))) {
if (!type.requirements(typeElement.getSuperclass().toString(), typeElement.getInterfaces().stream().map(TypeMirror::toString).collect(Collectors.toSet()), typeElement)) {
return;
}

Datei anzeigen

@ -23,8 +23,6 @@ import de.steamwar.linkage.plan.BuildPlan;
import de.steamwar.linkage.plan.MethodBuilder;
import javax.lang.model.element.TypeElement;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.Set;
public interface LinkageType {
@ -39,9 +37,22 @@ public interface LinkageType {
SPIGOT
}
default boolean requirements(String superClass, Set<String> interfaces) {
default boolean requirements(String superClass, Set<String> interfaces, TypeElement typeElement) {
return true;
}
void generateCode(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance, TypeElement typeElement);
default void generateCode(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance, TypeElement typeElement) {
switch (context) {
case BUNGEE:
generateCodeBungee(buildPlan, linkageTypeMethod, instance, typeElement);
break;
case SPIGOT:
generateCodeSpigot(buildPlan, linkageTypeMethod, instance, typeElement);
break;
}
}
default void generateCodeBungee(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance, TypeElement typeElement) {
}
default void generateCodeSpigot(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance, TypeElement typeElement) {
}
}

Datei anzeigen

@ -29,16 +29,17 @@ import java.util.Set;
public class Command implements LinkageType {
@Override
public boolean requirements(String superClass, Set<String> interfaces) {
public boolean requirements(String superClass, Set<String> interfaces, TypeElement typeElement) {
return superClass.equals("de.steamwar.command.SWCommand");
}
@Override
public void generateCode(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance, TypeElement typeElement) {
if (context == Context.BUNGEE) {
public void generateCodeBungee(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance, TypeElement typeElement) {
linkageTypeMethod.addLine(instance + ";");
return;
}
@Override
public void generateCodeSpigot(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance, TypeElement typeElement) {
linkageTypeMethod.addLine(instance + ".setMessage(" + getPluginMain() + ".MESSAGE);");
}
}

Datei anzeigen

@ -29,7 +29,7 @@ import java.util.Set;
public class DisableLink implements LinkageType {
@Override
public boolean requirements(String superClass, Set<String> interfaces) {
public boolean requirements(String superClass, Set<String> interfaces, TypeElement typeElement) {
return interfaces.contains("de.steamwar.linkage.api.Disable");
}

Datei anzeigen

@ -20,7 +20,6 @@
package de.steamwar.linkage.types;
import de.steamwar.linkage.LinkageType;
import de.steamwar.linkage.api.Enable;
import de.steamwar.linkage.plan.BuildPlan;
import de.steamwar.linkage.plan.MethodBuilder;
@ -30,7 +29,7 @@ import java.util.Set;
public class EnableLink implements LinkageType {
@Override
public boolean requirements(String superClass, Set<String> interfaces) {
public boolean requirements(String superClass, Set<String> interfaces, TypeElement typeElement) {
return interfaces.contains("de.steamwar.linkage.api.Enable");
}

Datei anzeigen

@ -24,7 +24,6 @@ import de.steamwar.linkage.plan.BuildPlan;
import de.steamwar.linkage.plan.FieldBuilder;
import de.steamwar.linkage.plan.MethodBuilder;
import de.steamwar.linkage.plan.ParameterBuilder;
import lombok.SneakyThrows;
import javax.lang.model.element.*;
import javax.lang.model.type.DeclaredType;
@ -35,7 +34,7 @@ import java.util.Set;
public class ListenerLink implements LinkageType {
@Override
public boolean requirements(String superClass, Set<String> interfaces) {
public boolean requirements(String superClass, Set<String> interfaces, TypeElement typeElement) {
if (context == Context.BUNGEE) {
return interfaces.contains("net.md_5.bungee.api.plugin.Listener");
} else {
@ -44,12 +43,14 @@ public class ListenerLink implements LinkageType {
}
@Override
public void generateCode(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance, TypeElement typeElement) {
if (context == Context.BUNGEE) {
public void generateCodeBungee(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance, TypeElement typeElement) {
buildPlan.addImport("net.md_5.bungee.api.ProxyServer");
buildPlan.addImport("de.steamwar.bungeecore.BungeeCore");
linkageTypeMethod.addLine("ProxyServer.getInstance().getPluginManager().registerListener(BungeeCore.get(), " + instance + ");");
} else {
}
@Override
public void generateCodeSpigot(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance, TypeElement typeElement) {
Map<String, TypeElement> eventClasses = new HashMap<>();
Map<TypeElement, ExecutableElement> eventMethods = new HashMap<>();
@ -109,5 +110,4 @@ public class ListenerLink implements LinkageType {
linkageTypeMethod.addLine(type.getSimpleName().toString() + "(" + localInstance + ", " + localInstance + "::" + executableElement.getSimpleName().toString() + ", EventPriority." + priority + ", " + ignoreCancelled + ");");
});
}
}
}

Datei anzeigen

@ -24,12 +24,13 @@ import de.steamwar.linkage.plan.BuildPlan;
import de.steamwar.linkage.plan.MethodBuilder;
import javax.lang.model.element.TypeElement;
import java.lang.reflect.Type;
import java.util.Set;
public class UnlinkListener implements LinkageType {
@Override
public boolean requirements(String superClass, Set<String> interfaces) {
public boolean requirements(String superClass, Set<String> interfaces, TypeElement typeElement) {
if (context == Context.BUNGEE) {
return interfaces.contains("net.md_5.bungee.api.plugin.Listener");
} else {
@ -38,14 +39,15 @@ public class UnlinkListener implements LinkageType {
}
@Override
public void generateCode(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance, TypeElement typeElement) {
if (context == Context.BUNGEE) {
public void generateCodeBungee(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance, TypeElement typeElement) {
buildPlan.addImport("net.md_5.bungee.api.ProxyServer");
buildPlan.addImport("de.steamwar.bungeecore.BungeeCore");
linkageTypeMethod.addLine("ProxyServer.getInstance().getPluginManager().registerListener(" + instance + ");");
} else {
}
@Override
public void generateCodeSpigot(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance, TypeElement typeElement) {
buildPlan.addImport("org.bukkit.event.HandlerList");
linkageTypeMethod.addLine("HandlerList.unregisterAll(" + instance + ");");
}
}
}