Add MethodBuilder
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Add ParameterBuilder
Add MinVersion
Dieser Commit ist enthalten in:
yoyosource 2022-09-19 09:01:05 +02:00
Ursprung 8c574c1975
Commit f8e18ec79f
7 geänderte Dateien mit 155 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -19,6 +19,8 @@
package de.steamwar.linkage;
import de.steamwar.linkage.plan.BuildPlan;
public interface LinkageType {
// String name = new BufferedReader(new InputStreamReader(processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", "plugin.yml").openInputStream()))
@ -36,5 +38,5 @@ public interface LinkageType {
return null;
}
String generateCode(String instance);
void generateCode(BuildPlan buildPlan, String instance);
}

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.linkage;
/**
* Only applicable in Spigot context. Will be ignored in other contexts.
*/
public @interface MinVersion {
int value();
}

Datei anzeigen

@ -34,9 +34,26 @@ public class BuildPlan implements Writer {
private final String className;
private Map<Class<?>, FieldBuilder> fieldBuilderMap = new HashMap<>();
private Map<String, MethodBuilder> methodBuilderMap = new HashMap<>();
public void addField(FieldBuilder fieldBuilder) {
fieldBuilderMap.put(fieldBuilder.getType(), fieldBuilder);
fieldBuilderMap.putIfAbsent(fieldBuilder.getType(), fieldBuilder);
}
public boolean hasField(Class<?> type) {
return fieldBuilderMap.containsKey(type);
}
public String getFieldName(Class<?> type) {
return fieldBuilderMap.get(type).getFieldName();
}
public void addMethod(MethodBuilder methodBuilder) {
methodBuilderMap.put(methodBuilder.getMethodName(), methodBuilder);
}
public boolean hasMethod(String methodName) {
return methodBuilderMap.containsKey(methodName);
}
@Override
@ -47,6 +64,12 @@ public class BuildPlan implements Writer {
for (FieldBuilder fieldBuilder : fieldBuilderMap.values()) {
fieldBuilder.write(writer);
}
if (!fieldBuilderMap.isEmpty() && !methodBuilderMap.isEmpty()) {
writer.write("\n");
}
for (MethodBuilder methodBuilder : methodBuilderMap.values()) {
methodBuilder.write(writer);
}
writer.write("}\n");
}
}

Datei anzeigen

@ -31,8 +31,12 @@ public class FieldBuilder implements Writer {
@Getter
private Class<?> type;
public String getFieldName() {
return type.getSimpleName();
}
@Override
public void write(BufferedWriter writer) throws IOException {
writer.write(" private static " + type.getTypeName() + " " + type.getSimpleName() + ";");
writer.write(" private static " + type.getTypeName() + " " + getFieldName() + ";\n");
}
}

Datei anzeigen

@ -0,0 +1,57 @@
/*
* 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.plan;
import de.steamwar.linkage.Writer;
import lombok.RequiredArgsConstructor;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@RequiredArgsConstructor
public class MethodBuilder implements Writer {
private final String name;
private final Class<?> returnType;
private List<ParameterBuilder> parameters = new ArrayList<>();
private List<String> lines = new ArrayList<>();
public String getMethodName() {
return name;
}
@Override
public void write(BufferedWriter writer) throws IOException {
writer.write(" public static " + returnType.getTypeName() + " " + getMethodName() + "(");
for (int i = 0; i < parameters.size(); i++) {
parameters.get(i).write(writer);
if (i < parameters.size() - 1) {
writer.write(", ");
}
}
writer.write(") {");
for (String line : lines) {
writer.write(" " + line);
}
writer.write(" }\n");
}
}

Datei anzeigen

@ -0,0 +1,37 @@
/*
* 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.plan;
import de.steamwar.linkage.Writer;
import lombok.AllArgsConstructor;
import java.io.BufferedWriter;
import java.io.IOException;
@AllArgsConstructor
public class ParameterBuilder implements Writer {
private Class<?> type;
private String name;
@Override
public void write(BufferedWriter writer) throws IOException {
writer.write(type.getTypeName() + " " + name);
}
}

Datei anzeigen

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