Add some api and linkage types
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Add LinkageProcessor
Dieser Commit ist enthalten in:
yoyosource 2022-09-19 09:13:07 +02:00
Ursprung f8e18ec79f
Commit f152d790ce
9 geänderte Dateien mit 240 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,71 @@
/*
* 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;
import lombok.SneakyThrows;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic;
import javax.tools.StandardLocation;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.Writer;
import java.util.Set;
@SupportedAnnotationTypes("de.steamwar.linkage.Linked")
public class LinkageProcessor extends AbstractProcessor {
private Messager messager;
private Writer writer;
private boolean processed = false;
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latestSupported();
}
@SneakyThrows
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
String name = new BufferedReader(new InputStreamReader(processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", "plugin.yml").openInputStream()))
.lines()
.filter(s -> s.startsWith("name: "))
.map(s -> s.substring(6))
.map(String::toLowerCase)
.findFirst()
.orElse(null);
if (name == null) {
messager.printMessage(Diagnostic.Kind.ERROR, "Could not find plugin name in plugin.yml");
return;
}
writer = processingEnv.getFiler().createSourceFile("de.steamwar." + name + ".linkage.LinkageUtils").openWriter();
messager = processingEnv.getMessager();
}
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
return false;
}
}

Datei anzeigen

@ -20,17 +20,10 @@
package de.steamwar.linkage;
import de.steamwar.linkage.plan.BuildPlan;
import de.steamwar.linkage.plan.MethodBuilder;
public interface LinkageType {
// String name = new BufferedReader(new InputStreamReader(processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", "plugin.yml").openInputStream()))
// .lines()
// .filter(s -> s.startsWith("main: "))
// .map(s -> s.substring(6))
// .map(s -> s.substring(s.lastIndexOf('.')))
// .findFirst()
// .orElse(null);
default Class<?> clazzType() {
return null;
}
@ -38,5 +31,5 @@ public interface LinkageType {
return null;
}
void generateCode(BuildPlan buildPlan, String instance);
void generateCode(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance);
}

Datei anzeigen

@ -0,0 +1,24 @@
/*
* 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 Disable {
void disable();
}

Datei anzeigen

@ -0,0 +1,24 @@
/*
* 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 Enable {
void enable();
}

Datei anzeigen

@ -35,6 +35,14 @@ public class MethodBuilder implements Writer {
private List<ParameterBuilder> parameters = new ArrayList<>();
private List<String> lines = new ArrayList<>();
public void addParameter(ParameterBuilder parameterBuilder) {
parameters.add(parameterBuilder);
}
public void addLine(String line) {
lines.add(line);
}
public String getMethodName() {
return name;
}

Datei anzeigen

@ -22,6 +22,7 @@ package de.steamwar.linkage.types;
import de.steamwar.command.AbstractSWCommand;
import de.steamwar.linkage.LinkageType;
import de.steamwar.linkage.plan.BuildPlan;
import de.steamwar.linkage.plan.MethodBuilder;
public class Command implements LinkageType {
@ -31,6 +32,6 @@ public class Command implements LinkageType {
}
@Override
public void generateCode(BuildPlan buildPlan, String instance) {
public void generateCode(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance) {
}
}

Datei anzeigen

@ -0,0 +1,39 @@
/*
* 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.types;
import de.steamwar.linkage.LinkageType;
import de.steamwar.linkage.api.Disable;
import de.steamwar.linkage.api.Enable;
import de.steamwar.linkage.plan.BuildPlan;
import de.steamwar.linkage.plan.MethodBuilder;
public class DisableLink implements LinkageType {
@Override
public Class<?> interfaceType() {
return Disable.class;
}
@Override
public void generateCode(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance) {
linkageTypeMethod.addLine(instance + ".disable();");
}
}

Datei anzeigen

@ -0,0 +1,38 @@
/*
* 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.types;
import de.steamwar.linkage.LinkageType;
import de.steamwar.linkage.api.Enable;
import de.steamwar.linkage.plan.BuildPlan;
import de.steamwar.linkage.plan.MethodBuilder;
public class EnableLink implements LinkageType {
@Override
public Class<?> interfaceType() {
return Enable.class;
}
@Override
public void generateCode(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance) {
linkageTypeMethod.addLine(instance + ".enable();");
}
}

Datei anzeigen

@ -0,0 +1,32 @@
/*
* 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.types;
import de.steamwar.linkage.LinkageType;
import de.steamwar.linkage.plan.BuildPlan;
import de.steamwar.linkage.plan.MethodBuilder;
public class Plain implements LinkageType {
@Override
public void generateCode(BuildPlan buildPlan, MethodBuilder linkageTypeMethod, String instance) {
linkageTypeMethod.addLine(instance + ";");
}
}