diff --git a/src/de/steamwar/linkage/LinkageProcessor.java b/src/de/steamwar/linkage/LinkageProcessor.java new file mode 100644 index 0000000..b0e8303 --- /dev/null +++ b/src/de/steamwar/linkage/LinkageProcessor.java @@ -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 . + */ + +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 annotations, RoundEnvironment roundEnv) { + return false; + } +} diff --git a/src/de/steamwar/linkage/LinkageType.java b/src/de/steamwar/linkage/LinkageType.java index 98a4719..f71ca2f 100644 --- a/src/de/steamwar/linkage/LinkageType.java +++ b/src/de/steamwar/linkage/LinkageType.java @@ -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); } diff --git a/src/de/steamwar/linkage/api/Disable.java b/src/de/steamwar/linkage/api/Disable.java new file mode 100644 index 0000000..f09b846 --- /dev/null +++ b/src/de/steamwar/linkage/api/Disable.java @@ -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 . + */ + +package de.steamwar.linkage.api; + +public interface Disable { + void disable(); +} diff --git a/src/de/steamwar/linkage/api/Enable.java b/src/de/steamwar/linkage/api/Enable.java new file mode 100644 index 0000000..5d516cd --- /dev/null +++ b/src/de/steamwar/linkage/api/Enable.java @@ -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 . + */ + +package de.steamwar.linkage.api; + +public interface Enable { + void enable(); +} diff --git a/src/de/steamwar/linkage/plan/MethodBuilder.java b/src/de/steamwar/linkage/plan/MethodBuilder.java index e1a0244..68ae453 100644 --- a/src/de/steamwar/linkage/plan/MethodBuilder.java +++ b/src/de/steamwar/linkage/plan/MethodBuilder.java @@ -35,6 +35,14 @@ public class MethodBuilder implements Writer { private List parameters = new ArrayList<>(); private List lines = new ArrayList<>(); + public void addParameter(ParameterBuilder parameterBuilder) { + parameters.add(parameterBuilder); + } + + public void addLine(String line) { + lines.add(line); + } + public String getMethodName() { return name; } diff --git a/src/de/steamwar/linkage/types/Command.java b/src/de/steamwar/linkage/types/Command.java index c7ea544..31b1491 100644 --- a/src/de/steamwar/linkage/types/Command.java +++ b/src/de/steamwar/linkage/types/Command.java @@ -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) { } } diff --git a/src/de/steamwar/linkage/types/DisableLink.java b/src/de/steamwar/linkage/types/DisableLink.java new file mode 100644 index 0000000..15175a7 --- /dev/null +++ b/src/de/steamwar/linkage/types/DisableLink.java @@ -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 . + */ + +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();"); + } +} diff --git a/src/de/steamwar/linkage/types/EnableLink.java b/src/de/steamwar/linkage/types/EnableLink.java new file mode 100644 index 0000000..400c96d --- /dev/null +++ b/src/de/steamwar/linkage/types/EnableLink.java @@ -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 . + */ + +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();"); + } +} diff --git a/src/de/steamwar/linkage/types/Plain.java b/src/de/steamwar/linkage/types/Plain.java new file mode 100644 index 0000000..d25fa48 --- /dev/null +++ b/src/de/steamwar/linkage/types/Plain.java @@ -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 . + */ + +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 + ";"); + } +}