Add LinkageProcessor
Dieser Commit ist enthalten in:
Ursprung
f8e18ec79f
Commit
f152d790ce
71
src/de/steamwar/linkage/LinkageProcessor.java
Normale Datei
71
src/de/steamwar/linkage/LinkageProcessor.java
Normale Datei
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
24
src/de/steamwar/linkage/api/Disable.java
Normale Datei
24
src/de/steamwar/linkage/api/Disable.java
Normale Datei
@ -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();
|
||||
}
|
24
src/de/steamwar/linkage/api/Enable.java
Normale Datei
24
src/de/steamwar/linkage/api/Enable.java
Normale Datei
@ -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();
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -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) {
|
||||
}
|
||||
}
|
||||
|
39
src/de/steamwar/linkage/types/DisableLink.java
Normale Datei
39
src/de/steamwar/linkage/types/DisableLink.java
Normale Datei
@ -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();");
|
||||
}
|
||||
}
|
38
src/de/steamwar/linkage/types/EnableLink.java
Normale Datei
38
src/de/steamwar/linkage/types/EnableLink.java
Normale Datei
@ -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();");
|
||||
}
|
||||
}
|
32
src/de/steamwar/linkage/types/Plain.java
Normale Datei
32
src/de/steamwar/linkage/types/Plain.java
Normale Datei
@ -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 + ";");
|
||||
}
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren