From 82010bd5601059ef1e70c0ff8317b82207d37c11 Mon Sep 17 00:00:00 2001 From: Tanish Azad Date: Fri, 24 May 2024 02:02:24 +0530 Subject: [PATCH 1/4] fix spotless error by pinning the version --- .../tjbot/features/tags/TagManageCommand.java | 27 +++++++------------ build.gradle | 2 +- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/tags/TagManageCommand.java b/application/src/main/java/org/togetherjava/tjbot/features/tags/TagManageCommand.java index f24d517229..eb7dbecbe9 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/tags/TagManageCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/tags/TagManageCommand.java @@ -318,27 +318,18 @@ private Optional getTagContent(Subcommand subcommand, String id) { * @param event the event to send messages with * @return whether the status of the given tag is not equal to the required status */ - // ToDo: gradle task :application:spotlessJava throws internal exception if this method uses new - // when keyword - @SuppressWarnings("java:S6916") private boolean isWrongTagStatusAndHandle(TagStatus requiredTagStatus, String id, IReplyCallback event) { - switch (requiredTagStatus) { - case TagStatus.EXISTS -> { - return tagSystem.handleIsUnknownTag(id, event); - } - case TagStatus.NOT_EXISTS -> { - if (tagSystem.hasTag(id)) { - event.reply("The tag with id '%s' already exists.".formatted(id)) - .setEphemeral(true) - .queue(); - return true; - } + return switch (requiredTagStatus) { + case TagStatus.EXISTS -> tagSystem.handleIsUnknownTag(id, event); + case TagStatus status when status == TagStatus.NOT_EXISTS && tagSystem.hasTag(id) -> { + event.reply("The tag with id '%s' already exists.".formatted(id)) + .setEphemeral(true) + .queue(); + yield true; } - default -> - throw new AssertionError("Unknown tag status '%s'".formatted(requiredTagStatus)); - } - return false; + case TagStatus.NOT_EXISTS -> false; + }; } private void logAction(Subcommand subcommand, Guild guild, User author, diff --git a/build.gradle b/build.gradle index b4d44a2db1..4fd7064d10 100644 --- a/build.gradle +++ b/build.gradle @@ -78,7 +78,7 @@ subprojects { // we use it as catch-all for external dependencies like JDA // '\\#` is prefix for static imports importOrder('','org.togetherjava', 'javax', 'java', '\\#') - eclipse().configFile("${rootProject.rootDir}/meta/formatting/google-style-eclipse.xml") + eclipse("4.31").configFile("${rootProject.rootDir}/meta/formatting/google-style-eclipse.xml") } } From 047e0d36621cb125237a8a7733bc70771d2e5428 Mon Sep 17 00:00:00 2001 From: Tanish Azad Date: Fri, 24 May 2024 02:22:13 +0530 Subject: [PATCH 2/4] added default branch --- .../org/togetherjava/tjbot/features/tags/TagManageCommand.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/tags/TagManageCommand.java b/application/src/main/java/org/togetherjava/tjbot/features/tags/TagManageCommand.java index eb7dbecbe9..5d0366038c 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/tags/TagManageCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/tags/TagManageCommand.java @@ -329,6 +329,8 @@ private boolean isWrongTagStatusAndHandle(TagStatus requiredTagStatus, String id yield true; } case TagStatus.NOT_EXISTS -> false; + default -> throw new IllegalStateException( + "Unknown tag status '%s'".formatted(requiredTagStatus)); }; } From 930291342c542c86aa4068e62c69a86779961182 Mon Sep 17 00:00:00 2001 From: Tanish Azad Date: Fri, 24 May 2024 02:31:14 +0530 Subject: [PATCH 3/4] added comment --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 4fd7064d10..3f6d5863ff 100644 --- a/build.gradle +++ b/build.gradle @@ -78,6 +78,7 @@ subprojects { // we use it as catch-all for external dependencies like JDA // '\\#` is prefix for static imports importOrder('','org.togetherjava', 'javax', 'java', '\\#') + // TODO: pinning version because of spotless error https://github.com/diffplug/spotless/issues/1992 eclipse("4.31").configFile("${rootProject.rootDir}/meta/formatting/google-style-eclipse.xml") } } From 90224623f5abb88be346ae47f4ddc6d86e2dade3 Mon Sep 17 00:00:00 2001 From: Tanish Azad Date: Fri, 24 May 2024 03:12:47 +0530 Subject: [PATCH 4/4] remove default --- .../org/togetherjava/tjbot/features/tags/TagManageCommand.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/features/tags/TagManageCommand.java b/application/src/main/java/org/togetherjava/tjbot/features/tags/TagManageCommand.java index 5d0366038c..eb7dbecbe9 100644 --- a/application/src/main/java/org/togetherjava/tjbot/features/tags/TagManageCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/features/tags/TagManageCommand.java @@ -329,8 +329,6 @@ private boolean isWrongTagStatusAndHandle(TagStatus requiredTagStatus, String id yield true; } case TagStatus.NOT_EXISTS -> false; - default -> throw new IllegalStateException( - "Unknown tag status '%s'".formatted(requiredTagStatus)); }; }