From 2774284aca7b055aaed5d98384814ea9c5d95010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= <4096670+Citymonstret@users.noreply.github.com> Date: Tue, 13 Aug 2024 19:41:06 +0200 Subject: [PATCH] fix(annotations): allow for slash-prefixed literal aliases (#748) --- .../cloud/annotations/SyntaxParserImpl.java | 5 +- .../cloud/annotations/issue/Issue450.java | 73 +++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 cloud-annotations/src/test/java/org/incendo/cloud/annotations/issue/Issue450.java diff --git a/cloud-annotations/src/main/java/org/incendo/cloud/annotations/SyntaxParserImpl.java b/cloud-annotations/src/main/java/org/incendo/cloud/annotations/SyntaxParserImpl.java index 6a065acec..0b5f95c40 100644 --- a/cloud-annotations/src/main/java/org/incendo/cloud/annotations/SyntaxParserImpl.java +++ b/cloud-annotations/src/main/java/org/incendo/cloud/annotations/SyntaxParserImpl.java @@ -38,8 +38,9 @@ */ public final class SyntaxParserImpl implements SyntaxParser { - private static final Predicate PATTERN_ARGUMENT_LITERAL = Pattern.compile("([A-Za-z0-9\\-_]+)(|([A-Za-z0-9\\-_]+))*") - .asPredicate(); + private static final Predicate PATTERN_ARGUMENT_LITERAL = Pattern.compile( + "([A-Za-z0-9\\-_/]+)(|([A-Za-z0-9\\-_/]+))*" + ).asPredicate(); private static final Predicate PATTERN_ARGUMENT_REQUIRED = Pattern.compile("<([A-Za-z0-9\\-_]+)>") .asPredicate(); private static final Predicate PATTERN_ARGUMENT_OPTIONAL = Pattern.compile("\\[([A-Za-z0-9\\-_]+)]") diff --git a/cloud-annotations/src/test/java/org/incendo/cloud/annotations/issue/Issue450.java b/cloud-annotations/src/test/java/org/incendo/cloud/annotations/issue/Issue450.java new file mode 100644 index 000000000..b9fa17848 --- /dev/null +++ b/cloud-annotations/src/test/java/org/incendo/cloud/annotations/issue/Issue450.java @@ -0,0 +1,73 @@ +// +// MIT License +// +// Copyright (c) 2024 Incendo +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +package org.incendo.cloud.annotations.issue; + +import org.incendo.cloud.CommandManager; +import org.incendo.cloud.annotations.AnnotationParser; +import org.incendo.cloud.annotations.Command; +import org.incendo.cloud.annotations.TestCommandManager; +import org.incendo.cloud.annotations.TestCommandSender; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +/** + * Test for https://github.com/Incendo/cloud/issues/450. + */ +class Issue450 { + + private CommandManager manager; + private AnnotationParser annotationParser; + + @BeforeEach + void setup() { + this.manager = new TestCommandManager(); + this.annotationParser = new AnnotationParser<>( + this.manager, + TestCommandSender.class + ); + } + + @Test + void testPrefixedAlias() { + // Act + this.annotationParser.parse(new TestCommandClass()); + + // Assert + this.manager.commandExecutor().executeCommand( + new TestCommandSender(), + "/command" + ).join(); + this.manager.commandExecutor().executeCommand( + new TestCommandSender(), + "/cmd" + ).join(); + } + + private static class TestCommandClass { + + @Command("/command|/cmd") + public void testCommand() { + } + } +}