From 69c8ac38610c97e2451d918ea20df40daa550d94 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 25 Sep 2022 11:55:45 +0200 Subject: [PATCH] Hotfix Plain_GENERIC generating invalid java code Hotfix weird generation of Plain method in LinkageProcessor Add Plain for eager instantiation if using custom linkages not generating link or unlink method --- src/de/steamwar/linkage/LinkageProcessor.java | 2 +- src/de/steamwar/linkage/api/Plain.java | 23 +++++++++++++++++++ .../steamwar/linkage/types/Plain_GENERIC.java | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/de/steamwar/linkage/api/Plain.java diff --git a/src/de/steamwar/linkage/LinkageProcessor.java b/src/de/steamwar/linkage/LinkageProcessor.java index f2f245c..7bdbbd4 100644 --- a/src/de/steamwar/linkage/LinkageProcessor.java +++ b/src/de/steamwar/linkage/LinkageProcessor.java @@ -279,7 +279,7 @@ public class LinkageProcessor extends AbstractProcessor { linkages.computeIfAbsent(interfaceType.method(), s -> new ArrayList<>()).add(interfaceType); } } - if (!linkages.containsKey(plain_GENERIC.method())) { + if (linkages.size() == 1 && linkages.containsKey("unlink")) { linkages.put(plain_GENERIC.method(), Collections.singletonList(plain_GENERIC)); } return linkages; diff --git a/src/de/steamwar/linkage/api/Plain.java b/src/de/steamwar/linkage/api/Plain.java new file mode 100644 index 0000000..23901ed --- /dev/null +++ b/src/de/steamwar/linkage/api/Plain.java @@ -0,0 +1,23 @@ +/* + * 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 Plain { +} diff --git a/src/de/steamwar/linkage/types/Plain_GENERIC.java b/src/de/steamwar/linkage/types/Plain_GENERIC.java index eca2830..f066d03 100644 --- a/src/de/steamwar/linkage/types/Plain_GENERIC.java +++ b/src/de/steamwar/linkage/types/Plain_GENERIC.java @@ -34,6 +34,6 @@ public class Plain_GENERIC implements LinkageType { @Override public void generateCode(BuildPlan buildPlan, MethodBuilder method, String instance, TypeElement typeElement) { - method.addLine(instance + ";"); + if (instance.startsWith("new ")) method.addLine(instance + ";"); } }