From 3da9e9bc696934abece301ff5bdd0202fd6076eb Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 3 Sep 2022 17:15:21 +0200 Subject: [PATCH] Add linkage prototype --- src/de/steamwar/linkage/LinkageType.java | 40 ++++++++++++++ src/de/steamwar/linkage/Linked.java | 35 +++++++++++++ src/de/steamwar/linkage/LinkedInstance.java | 30 +++++++++++ src/de/steamwar/linkage/Writer.java | 27 ++++++++++ src/de/steamwar/linkage/plan/BuildPlan.java | 52 +++++++++++++++++++ .../steamwar/linkage/plan/FieldBuilder.java | 38 ++++++++++++++ src/de/steamwar/linkage/types/Command.java | 36 +++++++++++++ 7 files changed, 258 insertions(+) create mode 100644 src/de/steamwar/linkage/LinkageType.java create mode 100644 src/de/steamwar/linkage/Linked.java create mode 100644 src/de/steamwar/linkage/LinkedInstance.java create mode 100644 src/de/steamwar/linkage/Writer.java create mode 100644 src/de/steamwar/linkage/plan/BuildPlan.java create mode 100644 src/de/steamwar/linkage/plan/FieldBuilder.java create mode 100644 src/de/steamwar/linkage/types/Command.java diff --git a/src/de/steamwar/linkage/LinkageType.java b/src/de/steamwar/linkage/LinkageType.java new file mode 100644 index 0000000..45baad6 --- /dev/null +++ b/src/de/steamwar/linkage/LinkageType.java @@ -0,0 +1,40 @@ +/* + * 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; + +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; + } + default Class interfaceType() { + return null; + } + + String generateCode(String instance); +} diff --git a/src/de/steamwar/linkage/Linked.java b/src/de/steamwar/linkage/Linked.java new file mode 100644 index 0000000..fd091d3 --- /dev/null +++ b/src/de/steamwar/linkage/Linked.java @@ -0,0 +1,35 @@ +/* + * 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 java.lang.annotation.*; + +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.TYPE}) +@Repeatable(Linked.Linkages.class) +public @interface Linked { + Class value(); + + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.TYPE}) + @interface Linkages { + @SuppressWarnings("unused") Linked[] value() default {}; + } +} diff --git a/src/de/steamwar/linkage/LinkedInstance.java b/src/de/steamwar/linkage/LinkedInstance.java new file mode 100644 index 0000000..9636ba5 --- /dev/null +++ b/src/de/steamwar/linkage/LinkedInstance.java @@ -0,0 +1,30 @@ +/* + * 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 java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.FIELD}) +public @interface LinkedInstance { +} diff --git a/src/de/steamwar/linkage/Writer.java b/src/de/steamwar/linkage/Writer.java new file mode 100644 index 0000000..235af89 --- /dev/null +++ b/src/de/steamwar/linkage/Writer.java @@ -0,0 +1,27 @@ +/* + * 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 java.io.BufferedWriter; +import java.io.IOException; + +public interface Writer { + void write(BufferedWriter writer) throws IOException; +} diff --git a/src/de/steamwar/linkage/plan/BuildPlan.java b/src/de/steamwar/linkage/plan/BuildPlan.java new file mode 100644 index 0000000..a1d8795 --- /dev/null +++ b/src/de/steamwar/linkage/plan/BuildPlan.java @@ -0,0 +1,52 @@ +/* + * 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.plan; + +import de.steamwar.linkage.Writer; +import lombok.RequiredArgsConstructor; + +import java.io.BufferedWriter; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +@RequiredArgsConstructor +public class BuildPlan implements Writer { + + private final String packageName; + private final String className; + + private Map, FieldBuilder> fieldBuilderMap = new HashMap<>(); + + public void addField(FieldBuilder fieldBuilder) { + fieldBuilderMap.put(fieldBuilder.getType(), fieldBuilder); + } + + @Override + public void write(BufferedWriter writer) throws IOException { + writer.write("package " + packageName + ";\n"); + writer.write("\n"); + writer.write("public class " + className + " {\n"); + for (FieldBuilder fieldBuilder : fieldBuilderMap.values()) { + fieldBuilder.write(writer); + } + writer.write("}\n"); + } +} diff --git a/src/de/steamwar/linkage/plan/FieldBuilder.java b/src/de/steamwar/linkage/plan/FieldBuilder.java new file mode 100644 index 0000000..8b2379a --- /dev/null +++ b/src/de/steamwar/linkage/plan/FieldBuilder.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.plan; + +import de.steamwar.linkage.Writer; +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.io.BufferedWriter; +import java.io.IOException; + +@AllArgsConstructor +public class FieldBuilder implements Writer { + @Getter + private Class type; + + @Override + public void write(BufferedWriter writer) throws IOException { + writer.write(" private static " + type.getTypeName() + " " + type.getSimpleName() + ";"); + } +} diff --git a/src/de/steamwar/linkage/types/Command.java b/src/de/steamwar/linkage/types/Command.java new file mode 100644 index 0000000..e4eba15 --- /dev/null +++ b/src/de/steamwar/linkage/types/Command.java @@ -0,0 +1,36 @@ +/* + * 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.command.AbstractSWCommand; +import de.steamwar.linkage.LinkageType; + +public class Command implements LinkageType { + + @Override + public Class clazzType() { + return AbstractSWCommand.class; + } + + @Override + public String generateCode(String instance) { + return null; + } +}