diff --git a/commandapi-annotations-reloaded-tests/pom.xml b/commandapi-annotations-reloaded-tests/pom.xml new file mode 100644 index 0000000000..ccf37d6bfb --- /dev/null +++ b/commandapi-annotations-reloaded-tests/pom.xml @@ -0,0 +1,139 @@ + + + + 4.0.0 + + dev.jorel + commandapi + 9.6.0-SNAPSHOT + + + commandapi-annotations-reloaded-tests + + + 16 + 16 + UTF-8 + + + + + codemc-repo + https://repo.codemc.org/repository/maven-public/ + default + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + minecraft-libraries + https://libraries.minecraft.net + + + + + + + + com.mojang + brigadier + 1.0.18 + test + + + dev.jorel + commandapi-bukkit-plugin + ${project.version} + test + + + + + dev.jorel + commandapi-bukkit-core + ${project.version} + + + dev.jorel + commandapi-annotations-reloaded + ${project.version} + compile + + + + com.google.auto.service + auto-service + ${auto-service.version} + provided + + + org.spigotmc + spigot-api + ${paper.version} + provided + + + + + + com.google.testing.compile + compile-testing + 0.19 + test + + + org.junit.jupiter + junit-jupiter + 5.10.2 + test + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + testCompile + + + + dev.jorel.commandapi.annotations.reloaded.Annotations + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M6 + + + + \ No newline at end of file diff --git a/commandapi-annotations-reloaded-tests/src/main/java/dev/jorel/commandapi/annotations/reloaded/test/AnnotatedCommandBossbar.java b/commandapi-annotations-reloaded-tests/src/main/java/dev/jorel/commandapi/annotations/reloaded/test/AnnotatedCommandBossbar.java new file mode 100644 index 0000000000..b9918c6854 --- /dev/null +++ b/commandapi-annotations-reloaded-tests/src/main/java/dev/jorel/commandapi/annotations/reloaded/test/AnnotatedCommandBossbar.java @@ -0,0 +1,203 @@ +/******************************************************************************* + * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.test; + +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.StreamSupport; + +import dev.jorel.commandapi.annotations.reloaded.annotations.Executes; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.NamespacedKey; +import org.bukkit.boss.BarColor; +import org.bukkit.boss.BarStyle; +import org.bukkit.boss.BossBar; +import org.bukkit.boss.KeyedBossBar; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.annotations.reloaded.annotations.Command; +import dev.jorel.commandapi.annotations.reloaded.annotations.Subcommand; +import dev.jorel.commandapi.annotations.reloaded.arguments.ABooleanArgument; +import dev.jorel.commandapi.annotations.reloaded.arguments.AChatComponentArgument; +import dev.jorel.commandapi.annotations.reloaded.arguments.AEntitySelectorArgument; +import dev.jorel.commandapi.annotations.reloaded.arguments.AIntegerArgument; +import dev.jorel.commandapi.annotations.reloaded.arguments.AMultiLiteralArgument; +import dev.jorel.commandapi.annotations.reloaded.arguments.ANamespacedKeyArgument; +import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException; +import net.md_5.bungee.api.chat.BaseComponent; + +/** + * The annotated equivalent of BetterBossBars from the + * examples/bukkit/commandtrees directory + */ +@Command("betterbossbar") +public class AnnotatedCommandBossbar { + + // /betterbossbar set players + // /betterbossbar set style (notched_6|notched_10|notched_12|notched_20|progress) + // /betterbossbar set value + // /betterbossbar set visible + + // /betterbossbar remove + + // /betterbossbar get players + // /betterbossbar get visible + // /betterbossbar get max + // /betterbossbar get value + + // /betterbossbar add + + // /betterbossbar list + + private Map maxValues; + + public AnnotatedCommandBossbar() { + this.maxValues = new HashMap<>(); + } + + @Subcommand("set") + class SetSubcommand { + + @ANamespacedKeyArgument + NamespacedKey id; + + @Subcommand("players") + public void players(CommandSender sender, + @AEntitySelectorArgument.ManyPlayers Collection targets) { + + Bukkit.getBossBar(id).removeAll(); + for (Player player : targets) { + Bukkit.getBossBar(id).addPlayer(player); + } + } + + @Subcommand("style") + public void style(CommandSender sender, + @AMultiLiteralArgument({ "notched_6", "notched_10", "notched_12", "notched_20", "progress" }) String style) throws WrapperCommandSyntaxException { + + Bukkit.getBossBar(id).setStyle( + switch (style) { + case "notched_6" -> BarStyle.SEGMENTED_6; + case "notched_10" -> BarStyle.SEGMENTED_10; + case "notched_12" -> BarStyle.SEGMENTED_12; + case "notched_20" -> BarStyle.SEGMENTED_20; + case "progress" -> BarStyle.SOLID; + default -> throw CommandAPI.failWithString(style + " is an invalid bossbar style"); + }); + } + + @Subcommand("value") + public void value(CommandSender sender, + @AIntegerArgument int value) { + + if (maxValues.containsKey(id)) { + Bukkit.getBossBar(id).setProgress((double) value / (double) maxValues.get(id)); + } else { + maxValues.put(id, value); + Bukkit.getBossBar(id).setProgress(1.0D); + } + } + + @Subcommand("visible") + public void visible(CommandSender sender, + @ABooleanArgument boolean visible) { + + Bukkit.getBossBar(id).setVisible(visible); + } + + } + + @Subcommand("remove") + public void remove(CommandSender sender, + @ANamespacedKeyArgument NamespacedKey id) { + + sender.sendMessage("Removed custom bossbar [" + Bukkit.getBossBar(id).getTitle() + "]"); + Bukkit.getBossBar(id).removeAll(); + Bukkit.removeBossBar(id); + } + + @Subcommand("get") + class GetSubcommand { + + @ANamespacedKeyArgument + NamespacedKey id; + + @Subcommand("players") + public void players(CommandSender sender) { + List bossBarPlayers = Bukkit.getBossBar(id).getPlayers(); + String players = bossBarPlayers.stream().map(Player::getName).collect(Collectors.joining(", ")); + sender.sendMessage("Custom bossbar [" + Bukkit.getBossBar(id).getTitle() + "] has " + bossBarPlayers.size() + " players currently online: " + players); + } + + @Subcommand("visible") + public void visible(CommandSender sender) { + BossBar bossBar = Bukkit.getBossBar(id); + sender.sendMessage("Custom bossbar [" + bossBar.getTitle() + "] is currently " + (bossBar.isVisible() ? "shown" : "hidden")); + } + + @Subcommand("max") + public void max(CommandSender sender) { + sender.sendMessage("Custom bossbar [" + Bukkit.getBossBar(id).getTitle() + "] has a maximum of " + maxValues.getOrDefault(id, 100)); + } + + @Subcommand("value") + public void value(CommandSender sender) { + BossBar bossBar = Bukkit.getBossBar(id); + + int value = (int) (bossBar.getProgress() * maxValues.getOrDefault(id, 100)); + sender.sendMessage("Custom bossbar [" + Bukkit.getBossBar(id).getTitle() + "] has a value of " + value); + } + } + + @Subcommand("add") + class AddSubcommand { + + @Executes + public void addBossbar(CommandSender sender, + @ANamespacedKeyArgument NamespacedKey id, + @AChatComponentArgument BaseComponent[] name) { + + Bukkit.createBossBar(id, BaseComponent.toLegacyText(name), BarColor.WHITE, BarStyle.SOLID); + maxValues.put(id, 100); + sender.sendMessage("Created custom bossbar [" + BaseComponent.toLegacyText(name) + ChatColor.WHITE + "]"); + } + + } + + @Subcommand("list") + public void ListSubcommand(CommandSender sender) { + Iterable bossBars = Bukkit::getBossBars; + sender.sendMessage("List of custom bossbars: " + + StreamSupport + .stream(bossBars.spliterator(), false) + .map(KeyedBossBar::getKey) + .map(NamespacedKey::toString) + .collect(Collectors.joining(", ")) + ); + } + +} diff --git a/commandapi-annotations-reloaded-tests/src/main/java/dev/jorel/commandapi/annotations/reloaded/test/AnnotatedCommandRepeatingSubcommands.java b/commandapi-annotations-reloaded-tests/src/main/java/dev/jorel/commandapi/annotations/reloaded/test/AnnotatedCommandRepeatingSubcommands.java new file mode 100644 index 0000000000..ac6673cfe8 --- /dev/null +++ b/commandapi-annotations-reloaded-tests/src/main/java/dev/jorel/commandapi/annotations/reloaded/test/AnnotatedCommandRepeatingSubcommands.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.test; + +import dev.jorel.commandapi.annotations.reloaded.annotations.Command; + +/** + * A test for repeating subcommand annotations + */ +@Command("perm") +public class AnnotatedCommandRepeatingSubcommands { + + // /perm set user + +// @Subcommand("set") +// @Subcommand("user") +// public void execute(CommandSender sender, +// @APlayerArgument Player player, +// @AStringArgument String permission) { +// // Do stuff +// } + +// class SetUserSubcommand { +// +// @APlayerArgument +// Player player; +// +// @AStringArgument +// String permission; +// +// @Subcommand +// public void execute(CommandSender sender) { +// // Do stuff +// } +// } + +} diff --git a/commandapi-annotations-reloaded-tests/src/main/java/dev/jorel/commandapi/annotations/reloaded/test/AnnotatedCommandWithExternalSubcommand.java b/commandapi-annotations-reloaded-tests/src/main/java/dev/jorel/commandapi/annotations/reloaded/test/AnnotatedCommandWithExternalSubcommand.java new file mode 100644 index 0000000000..ae50258db1 --- /dev/null +++ b/commandapi-annotations-reloaded-tests/src/main/java/dev/jorel/commandapi/annotations/reloaded/test/AnnotatedCommandWithExternalSubcommand.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.test; + +import dev.jorel.commandapi.annotations.reloaded.annotations.Command; +import dev.jorel.commandapi.annotations.reloaded.annotations.ExternalSubcommand; +import dev.jorel.commandapi.annotations.reloaded.arguments.AStringArgument; + +/** + * Annotated command that uses an external subcommand + */ +@Command("mycommand") +public class AnnotatedCommandWithExternalSubcommand { + + // /mycommand + + @AStringArgument + String name; + + @ExternalSubcommand(AnnotatedExternalSubcommand.class) + AnnotatedExternalSubcommand subcommand; + +} diff --git a/commandapi-annotations-reloaded-tests/src/main/java/dev/jorel/commandapi/annotations/reloaded/test/AnnotatedCommandWithSuggestions.java b/commandapi-annotations-reloaded-tests/src/main/java/dev/jorel/commandapi/annotations/reloaded/test/AnnotatedCommandWithSuggestions.java new file mode 100644 index 0000000000..9d1d709b84 --- /dev/null +++ b/commandapi-annotations-reloaded-tests/src/main/java/dev/jorel/commandapi/annotations/reloaded/test/AnnotatedCommandWithSuggestions.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.test; + +import java.util.function.Supplier; + +import dev.jorel.commandapi.annotations.reloaded.annotations.Executes; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import dev.jorel.commandapi.annotations.reloaded.annotations.Command; +import dev.jorel.commandapi.annotations.reloaded.annotations.Subcommand; +import dev.jorel.commandapi.annotations.reloaded.annotations.Suggestion; +import dev.jorel.commandapi.annotations.reloaded.annotations.Suggests; +import dev.jorel.commandapi.annotations.reloaded.arguments.AStringArgument; +import dev.jorel.commandapi.arguments.ArgumentSuggestions; + +/** + * Annotated command that uses suggestion classes + */ +@Command("mycommand") +public class AnnotatedCommandWithSuggestions { + + // /mycommand + + @AStringArgument + @Suggests(ListOfNames.class) + String name; + + @Executes + public void myExecutor(Player player) { + // ... + } + + @Suggestion + class ListOfNames implements Supplier> { + + @Override + public ArgumentSuggestions get() { + return ArgumentSuggestions.strings("Player1", "Player2", "Player3"); + } + + } + +} diff --git a/commandapi-annotations-reloaded-tests/src/main/java/dev/jorel/commandapi/annotations/reloaded/test/AnnotatedExternalSubcommand.java b/commandapi-annotations-reloaded-tests/src/main/java/dev/jorel/commandapi/annotations/reloaded/test/AnnotatedExternalSubcommand.java new file mode 100644 index 0000000000..f380877f6a --- /dev/null +++ b/commandapi-annotations-reloaded-tests/src/main/java/dev/jorel/commandapi/annotations/reloaded/test/AnnotatedExternalSubcommand.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.test; + +import org.bukkit.entity.Player; + +import dev.jorel.commandapi.annotations.reloaded.annotations.Executes; +import dev.jorel.commandapi.annotations.reloaded.annotations.Subcommand; +import dev.jorel.commandapi.annotations.reloaded.arguments.AIntegerArgument; + +/** + * Annotated subcommand. Note that this class uses {@code @Subcommand} instead + * of {@code @Command} + */ +@Subcommand("subcommand") +public class AnnotatedExternalSubcommand extends AnnotatedCommandWithExternalSubcommand { + + // mycommand + + @Executes + public void myMethod(Player player, @AIntegerArgument int value) { + String nameArg = name; // Inherited from parent command class + } + +} diff --git a/commandapi-annotations-reloaded-tests/src/main/java/dev/jorel/commandapi/annotations/reloaded/test/HordeCommand2.java b/commandapi-annotations-reloaded-tests/src/main/java/dev/jorel/commandapi/annotations/reloaded/test/HordeCommand2.java new file mode 100644 index 0000000000..e41ebfc700 --- /dev/null +++ b/commandapi-annotations-reloaded-tests/src/main/java/dev/jorel/commandapi/annotations/reloaded/test/HordeCommand2.java @@ -0,0 +1,169 @@ +/******************************************************************************* + * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.test; + +import java.util.function.Supplier; + +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import dev.jorel.commandapi.annotations.reloaded.annotations.ArgumentParser; +import dev.jorel.commandapi.annotations.reloaded.annotations.Command; +import dev.jorel.commandapi.annotations.reloaded.annotations.Permission; +import dev.jorel.commandapi.annotations.reloaded.annotations.Subcommand; +import dev.jorel.commandapi.annotations.reloaded.annotations.Suggestion; +import dev.jorel.commandapi.annotations.reloaded.annotations.Suggests; +import dev.jorel.commandapi.annotations.reloaded.arguments.AIntegerArgument; +import dev.jorel.commandapi.annotations.reloaded.arguments.AStringArgument; +import dev.jorel.commandapi.arguments.ArgumentSuggestions; +import dev.jorel.commandapi.arguments.CustomArgument.CustomArgumentException; +import dev.jorel.commandapi.arguments.CustomArgument.CustomArgumentInfo; +import dev.jorel.commandapi.arguments.CustomArgument.CustomArgumentInfoParser; +import dev.jorel.commandapi.arguments.SafeSuggestions; + +@Command("horde") +public class HordeCommand2 { + + final int val; + + // Some constructor + public HordeCommand2(int val) { + this.val = val; + } + + @AStringArgument + String hiiiiii; + + @AIntegerArgument + int byeeeeee; + + @Subcommand("hazard") + class HazardCommand { + + @Subcommand("create") + class CreateCommand { + + @Subcommand("fire") + public void fire(CommandSender executor, @AStringArgument String name) { + } + } + + @Subcommand("modify") + class ModifyCommand { + + @Permission("hello") + @Suggests(HazardSuggestions.class) + @AStringArgument + String name; + + // horde hazard modify area + @Subcommand("area") + public void area(Player player, @AIntegerArgument int size) { + } + + // horde hazard modify area + @Permission("hoard.hazard.modify.area") + @Subcommand("area") + public void area(CommandSender sender, @AIntegerArgument int size) { + } + + // TODO: This should fail because String is not an +// @Subcommand("area") +// public void area2(CommandSender sender, @AIntegerArgument String size) { +// } + + @Suggestion + class HazardSuggestions implements Supplier { + + @Override + public ArgumentSuggestions get() { + return ArgumentSuggestions.strings("fire", "water", "poison"); + } + + } + + @Suggestion + class LocationSuggestions implements Supplier> { + + @Override + public SafeSuggestions get() { + return SafeSuggestions.suggest(new Location[0]); + } + + } + } + + @Subcommand("toggle") + public void toggle(CommandSender sender) { + } + } + + + + @Suggestion + class EnableSuggestions implements Supplier { + + @Override + public ArgumentSuggestions get() { + return ArgumentSuggestions.strings("fire", "water", "poison"); + } + + } + + @Suggestion + class LocationSuggestions implements Supplier> { + + @Override + public SafeSuggestions get() { + return SafeSuggestions.suggest(new Location[0]); + } + + } + + @Subcommand("enable") + public void enable(Player sender) { + } + + @Subcommand("disable") + public void disable(CommandSender sender) { + } + + // TODO: When testing, try moving this to its own separate .java file and see if that links properly + @ArgumentParser + class WorldArgument implements CustomArgumentInfoParser { + + @Override + public World apply(CustomArgumentInfo info) throws CustomArgumentException { + // TODO Auto-generated method stub + return null; + } + + } + + // TODO: For both custom arguments and suggestions, we should have a check to see if there are + // any unused @ArgumentParser or @Suggestion classes +// @Subcommand("custom") +// public void custom(CommandSender sender, @ACustomArgument(WorldArgument.class) World world) { +// +// } +} \ No newline at end of file diff --git a/commandapi-annotations-reloaded-tests/src/main/java/dev/jorel/commandapi/annotations/reloaded/test/MyCommand.java b/commandapi-annotations-reloaded-tests/src/main/java/dev/jorel/commandapi/annotations/reloaded/test/MyCommand.java new file mode 100644 index 0000000000..73357d1cb8 --- /dev/null +++ b/commandapi-annotations-reloaded-tests/src/main/java/dev/jorel/commandapi/annotations/reloaded/test/MyCommand.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.test; + +import dev.jorel.commandapi.annotations.reloaded.annotations.Executes; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import dev.jorel.commandapi.annotations.reloaded.annotations.Command; +import dev.jorel.commandapi.annotations.reloaded.annotations.Subcommand; +import dev.jorel.commandapi.annotations.reloaded.arguments.APlayerArgument; + +// mycommand hi - says hi to everyone +// mycommand nested - says hi to a player +// mycommand nested hello - says hello to everyone + +@Command("mycommand") +public class MyCommand { + + @Subcommand("hi") + public class Hi { + + @Executes + public void hi(CommandSender sender) { + System.out.println("Hi"); + } + + } + + // TODO: This should be a valid case which does the same thing as the thing + // above it +// @Subcommand("hi") +// public void hi(CommandSender sender) { +// System.out.println("Hi"); +// } + + @Subcommand("nested") + public class Nested { + + @Executes + public void toPlayer(CommandSender sender, @APlayerArgument Player player) { + System.out.println("Hi " + player.getName()); + } + + @Subcommand("hello") + public class Hello { + + @Executes + public void hello(CommandSender sender) { + System.out.println("Hello"); + } + + } + + } + +} diff --git a/commandapi-annotations-reloaded-tests/src/test/java/dev/jorel/commandapi/annotations/reloaded/TestConfiguration.java b/commandapi-annotations-reloaded-tests/src/test/java/dev/jorel/commandapi/annotations/reloaded/TestConfiguration.java new file mode 100644 index 0000000000..cda2a57551 --- /dev/null +++ b/commandapi-annotations-reloaded-tests/src/test/java/dev/jorel/commandapi/annotations/reloaded/TestConfiguration.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded; + +import javax.annotation.Nonnull; +import java.util.UUID; + +public class TestConfiguration extends DefaultConfiguration { + @Nonnull + @Override + public String getCommandsClassName() { + return "Commands_Test_%s".formatted(UUID.randomUUID().toString().replace("-", "_")); + } +} diff --git a/commandapi-annotations-reloaded-tests/src/test/java/dev/jorel/commandapi/annotations/reloaded/test/AnnotationTests.java b/commandapi-annotations-reloaded-tests/src/test/java/dev/jorel/commandapi/annotations/reloaded/test/AnnotationTests.java new file mode 100644 index 0000000000..ba18cc4c7c --- /dev/null +++ b/commandapi-annotations-reloaded-tests/src/test/java/dev/jorel/commandapi/annotations/reloaded/test/AnnotationTests.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.test; + +import com.google.testing.compile.Compilation; +import dev.jorel.commandapi.annotations.reloaded.Annotations; +import dev.jorel.commandapi.annotations.reloaded.TestConfiguration; +import org.junit.jupiter.api.Test; + +import static com.google.testing.compile.CompilationSubject.assertThat; +import static com.google.testing.compile.Compiler.javac; +import static com.google.testing.compile.JavaFileObjects.forResource; +import static com.google.testing.compile.JavaFileObjects.forSourceString; + +public class AnnotationTests { + + Compilation compile(String classToCompile) { + return javac().withProcessors(new Annotations(new TestConfiguration())).compile(forResource(classToCompile)); + } + + /** + * Testing that the testing framework works + */ + @Test + void googleCompileTestingInit() { + Compilation compilation = javac().compile(forSourceString("HelloWorld", "public class HelloWorld {}")); + assertThat(compilation).succeeded(); + } + + @Test + void googleCompileTestingInitFail() { + Compilation compilation = javac().compile(forSourceString("HelloWorld", "public class HelloWorld {} blah")); + assertThat(compilation).failed(); + } + + @Test + void hordeTest() { +// Compilation compilation = javac() +// .withProcessors(new Annotations()) +// .compile(forResource("HordeCommand.java")); +// assertThat(compilation).succeeded(); + } + + /** + * Testing that a {@code @Command} on a type inside another type with {@code @Command} fails to compile + */ + @Test + void noNestedCommands() { + assertThat(compile("NestedCommand.java")) + .hadErrorContaining("@Command can only go on a top level class") + .inFile(forResource("NestedCommand.java")) + .onLine(27); + } + + /** + * Testing that a {@code @Command} class has at least one executor + */ + @Test + void checkCommandHasExecutor() { + assertThat(compile("ClassWithNoExecutor.java")) + .hadWarningContaining("@Command class has no executors") + .inFile(forResource("ClassWithNoExecutor.java")) + .onLine(24); + } + +} \ No newline at end of file diff --git a/commandapi-annotations-reloaded-tests/src/test/java/dev/jorel/commandapi/annotations/reloaded/test/PermissionTests.java b/commandapi-annotations-reloaded-tests/src/test/java/dev/jorel/commandapi/annotations/reloaded/test/PermissionTests.java new file mode 100644 index 0000000000..1978900162 --- /dev/null +++ b/commandapi-annotations-reloaded-tests/src/test/java/dev/jorel/commandapi/annotations/reloaded/test/PermissionTests.java @@ -0,0 +1,73 @@ +package dev.jorel.commandapi.annotations.reloaded.test; /******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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. + *******************************************************************************/ +import com.google.testing.compile.Compilation; +import dev.jorel.commandapi.annotations.reloaded.Annotations; +import dev.jorel.commandapi.annotations.reloaded.TestConfiguration; +import org.junit.jupiter.api.Test; + +import static com.google.testing.compile.CompilationSubject.assertThat; +import static com.google.testing.compile.Compiler.javac; +import static com.google.testing.compile.JavaFileObjects.forResource; +import static com.google.testing.compile.JavaFileObjects.forSourceString; + +public class PermissionTests { + + Compilation compile(String classToCompile) { + return javac().withProcessors(new Annotations(new TestConfiguration())).compile(forResource(classToCompile)); + } + + /* + * Testing that the testing framework works + */ + + @Test + void googleCompileTestingInit() { + Compilation compilation = javac().compile(forSourceString("HelloWorld", "public class HelloWorld {}")); + assertThat(compilation).succeeded(); + } + + @Test + void googleCompileTestingInitFail() { + Compilation compilation = javac().compile(forSourceString("HelloWorld", "public class HelloWorld {} blah")); + assertThat(compilation).failed(); + } + + @Test + void hordeTest() { +// Compilation compilation = javac() +// .withProcessors(new Annotations()) +// .compile(forResource("HordeCommand.java")); +// assertThat(compilation).succeeded(); + } + + @Test + /** + * Testing that a {@code @Command} on a type inside another type with {@code @Command} fails to compile + */ + void noNestedCommands() { + assertThat(compile("NestedCommand.java")) + .hadErrorContaining("@Command can only go on a top level class") + .inFile(forResource("NestedCommand.java")) + .onLine(27); + } + + +} \ No newline at end of file diff --git a/commandapi-annotations-reloaded-tests/src/test/java/dev/jorel/commandapi/annotations/reloaded/test/RegisteringTest.java b/commandapi-annotations-reloaded-tests/src/test/java/dev/jorel/commandapi/annotations/reloaded/test/RegisteringTest.java new file mode 100644 index 0000000000..3031b33bdb --- /dev/null +++ b/commandapi-annotations-reloaded-tests/src/test/java/dev/jorel/commandapi/annotations/reloaded/test/RegisteringTest.java @@ -0,0 +1,56 @@ +package dev.jorel.commandapi.annotations.reloaded.test; /******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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. + *******************************************************************************/ +import dev.jorel.commandapi.annotations.reloaded.test.HordeCommand2; +import org.junit.jupiter.api.Test; + +public class RegisteringTest { + + /** + * Registers a command. Used with the CommandAPI's Annotation API. + * @param commandClass the class to register + * @param instance the instance of the class to use + */ + public static void registerCommand(Class commandClass, T instance) { + try { + final Class commandsClass = Class.forName("Commands"); + final Object commandsClassInstance = commandsClass.getDeclaredConstructor().newInstance(); + commandsClass.getDeclaredMethod("register", commandClass).invoke(commandsClassInstance, instance); + } catch (ReflectiveOperationException e) { + boolean shouldPrint = true; + if (e.getCause() instanceof IllegalStateException illegalStateException) { + if (illegalStateException.getMessage().contains("Tried to access CommandAPIHandler instance")) { + // Shh shh shh, there there... + shouldPrint = false; + } + } + + if (shouldPrint) { + e.printStackTrace(); + } + } + } + + @Test + public void register() { + registerCommand(HordeCommand2.class, new HordeCommand2(123)); + } + +} diff --git a/commandapi-annotations-reloaded-tests/src/test/resources/ClassWithNoExecutor.java b/commandapi-annotations-reloaded-tests/src/test/resources/ClassWithNoExecutor.java new file mode 100644 index 0000000000..89de98ba54 --- /dev/null +++ b/commandapi-annotations-reloaded-tests/src/test/resources/ClassWithNoExecutor.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License + * + * 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. + *******************************************************************************/ +import dev.jorel.commandapi.annotations.reloaded.annotations.Command; + +@Command("run") +public class ClassWithNoExecutor { +} \ No newline at end of file diff --git a/commandapi-annotations-reloaded-tests/src/test/resources/DocumentationWarpCommand.java b/commandapi-annotations-reloaded-tests/src/test/resources/DocumentationWarpCommand.java new file mode 100644 index 0000000000..0518698e6d --- /dev/null +++ b/commandapi-annotations-reloaded-tests/src/test/resources/DocumentationWarpCommand.java @@ -0,0 +1,155 @@ +/******************************************************************************* + * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License + * + * 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. + *******************************************************************************/ +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.Location; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import dev.jorel.commandapi.CommandAPI; +import dev.jorel.commandapi.CommandAPICommand; +import dev.jorel.commandapi.annotations.reloaded.annotations.Command; +import dev.jorel.commandapi.annotations.reloaded.annotations.Permission; +import dev.jorel.commandapi.annotations.reloaded.annotations.Subcommand; +import dev.jorel.commandapi.annotations.reloaded.arguments.AStringArgument; +import dev.jorel.commandapi.arguments.ArgumentSuggestions; +import dev.jorel.commandapi.arguments.StringArgument; + +/* ANCHOR: warps */ +/* ANCHOR: warps_command */ +@Command("warp") +public class DocumentationWarpCommand { +/* ANCHOR_END: warps_command */ + + // List of warp names and their locations + static Map warps = new HashMap<>(); + + @Subcommand + public static void warp(CommandSender sender) { + sender.sendMessage("--- Warp help ---"); + sender.sendMessage("/warp - Show this help"); + sender.sendMessage("/warp - Teleport to "); + sender.sendMessage("/warp create - Creates a warp at your current location"); + } + + @Subcommand + public static void warp(Player player, @AStringArgument String warpName) { + player.teleport(warps.get(warpName)); + } + + @Subcommand("create") + @Permission("warps.create") + public static void createWarp(Player player, @AStringArgument String warpName) { + warps.put(warpName, player.getLocation()); + } + +} +/* ANCHOR_END: warps */ + +class A { + { +/* ANCHOR: warps_register */ +CommandAPI.registerCommand(DocumentationWarpCommand.class); +/* ANCHOR_END: warps_register */ + } + + static Map warps = new HashMap<>(); + +/* ANCHOR: warps_help */ +@Subcommand +public static void warp(CommandSender sender) { + sender.sendMessage("--- Warp help ---"); + sender.sendMessage("/warp - Show this help"); + sender.sendMessage("/warp - Teleport to "); + sender.sendMessage("/warp create - Creates a warp at your current location"); +} +/* ANCHOR_END: warps_help */ + +/* ANCHOR: warps_warp */ +@Subcommand +public static void warp(Player player, @AStringArgument String warpName) { + player.teleport(warps.get(warpName)); +} +/* ANCHOR_END: warps_warp */ + +/* ANCHOR: warps_create */ +@Subcommand("create") +@Permission("warps.create") +public static void createWarp(Player player, @AStringArgument String warpName) { + warps.put(warpName, player.getLocation()); +} +/* ANCHOR_END: warps_create */ + +} + +class Examples { +{ +/* ANCHOR: old_warps */ +Map warps = new HashMap<>(); + +// /warp +new CommandAPICommand("warp") + .executes((sender, args) -> { + sender.sendMessage("--- Warp help ---"); + sender.sendMessage("/warp - Show this help"); + sender.sendMessage("/warp - Teleport to "); + sender.sendMessage("/warp create - Creates a warp at your current location"); + }) + .register(); + +// /warp +new CommandAPICommand("warp") + .withArguments(new StringArgument("warp").replaceSuggestions(ArgumentSuggestions.strings(info -> + warps.keySet().toArray(new String[0]) + ))) + .executesPlayer((player, args) -> { + player.teleport(warps.get((String) args[0])); + }) + .register(); + +// /warp create +new CommandAPICommand("warp") + .withSubcommand( + new CommandAPICommand("create") + .withPermission("warps.create") + .withArguments(new StringArgument("warpname")) + .executesPlayer((player, args) -> { + warps.put((String) args[0], player.getLocation()); + }) + ) + .register(); +/* ANCHOR_END: old_warps */ +} + +/* ANCHOR: warp_register2 */ +class MyPlugin extends JavaPlugin { + + @Override + public void onLoad() { + CommandAPI.registerCommand(DocumentationWarpCommand.class); + } + +} +/* ANCHOR_END: warp_register2 */ + +} \ No newline at end of file diff --git a/commandapi-annotations-reloaded-tests/src/test/resources/FlattenedCommand.java b/commandapi-annotations-reloaded-tests/src/test/resources/FlattenedCommand.java new file mode 100644 index 0000000000..2435995b7e --- /dev/null +++ b/commandapi-annotations-reloaded-tests/src/test/resources/FlattenedCommand.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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. + *******************************************************************************/ +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.Location; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; + +import dev.jorel.commandapi.annotations.reloaded.annotations.Command; +import dev.jorel.commandapi.annotations.reloaded.annotations.Executors; +import dev.jorel.commandapi.annotations.reloaded.annotations.Help; +import dev.jorel.commandapi.annotations.reloaded.annotations.Permission; +import dev.jorel.commandapi.annotations.reloaded.annotations.Subcommand; +import dev.jorel.commandapi.annotations.reloaded.arguments.APlayerArgument; +import dev.jorel.commandapi.annotations.reloaded.arguments.AStringArgument; +import dev.jorel.commandapi.executors.ExecutorType; + +@Command("warp") +@Help(value = "Manages all warps on the server", shortDescription = "Manages warps") +public class FlattenedCommand { + + // List of warp names and their locations + final Map warps; + + public FlattenedCommand() { + warps = new HashMap<>(); + } + + // /warp + @Subcommand + public void warp(CommandSender sender) { + sender.sendMessage("--- Warp help ---"); + sender.sendMessage("/warp - Show this help"); + sender.sendMessage("/warp - Teleport to "); + sender.sendMessage("/warp create - Creates a warp at your current location"); + sender.sendMessage("/warp tp - Teleports a player to a warp"); + } + + // /warp + @Subcommand + public void warp(Player player, @AStringArgument String warpName) { + player.teleport(warps.get(warpName)); + } + + // /warp create + @Subcommand("create") + @Permission("warps.create") + @Executors({ExecutorType.ENTITY, ExecutorType.PLAYER}) + public void createWarp(CommandSender sender, @AStringArgument String warpName) { + warps.put(warpName, ((LivingEntity) sender).getLocation()); + } + + // /warp tp + @Subcommand("tp") + @Permission("warps.tp") + public void tpWarp(Player player, @AStringArgument String warpName) { + player.teleport(warps.get(warpName)); + } + + // /warp tp + @Subcommand("tp") + @Permission("warps.tp.other") + public void tpWarp(CommandSender sender, @APlayerArgument OfflinePlayer target, @AStringArgument String warpName) { + if(target.isOnline() && target instanceof Player onlineTarget) { + onlineTarget.teleport(warps.get(warpName)); + } + } + +} \ No newline at end of file diff --git a/commandapi-annotations-reloaded-tests/src/test/resources/HordeCommand.java b/commandapi-annotations-reloaded-tests/src/test/resources/HordeCommand.java new file mode 100644 index 0000000000..7bc1e4a1b3 --- /dev/null +++ b/commandapi-annotations-reloaded-tests/src/test/resources/HordeCommand.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License + * + * 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. + *******************************************************************************/ +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import dev.jorel.commandapi.annotations.reloaded.annotations.Command; +import dev.jorel.commandapi.annotations.reloaded.annotations.Subcommand; +import dev.jorel.commandapi.annotations.reloaded.arguments.AStringArgument; + +@Command("horde") +public class HordeCommand { + + @Subcommand("hazard") + class HazardCommand { + + @Subcommand("create") + class CreateCommand { + + @Subcommand("fire") + public void fire(CommandSender executor, String name) { + } + } + + @Subcommand("modify") + class ModifyCommand { + + @AStringArgument + String name; + + // horde hazard modify area + @Subcommand("area") + public void area(Player player, int size) { + } + + // horde hazard modify area + @Subcommand("area") + public void area(CommandSender sender, int size) { + } + } + + @Subcommand("toggle") + public void toggle() { + } + } +} \ No newline at end of file diff --git a/commandapi-annotations-reloaded-tests/src/test/resources/InvalidCommand.java b/commandapi-annotations-reloaded-tests/src/test/resources/InvalidCommand.java new file mode 100644 index 0000000000..f75f7eed5c --- /dev/null +++ b/commandapi-annotations-reloaded-tests/src/test/resources/InvalidCommand.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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. + *******************************************************************************/ +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.Location; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import dev.jorel.commandapi.annotations.reloaded.annotations.Command; +import dev.jorel.commandapi.annotations.reloaded.annotations.Help; +import dev.jorel.commandapi.annotations.reloaded.annotations.Permission; +import dev.jorel.commandapi.annotations.reloaded.annotations.Subcommand; +import dev.jorel.commandapi.annotations.reloaded.arguments.APlayerArgument; +import dev.jorel.commandapi.annotations.reloaded.arguments.AStringArgument; +import dev.jorel.commandapi.arguments.SafeSuggestions; + +@Command("warp") +@Help(value = "Manages all warps on the server", shortDescription = "Manages warps") +public class InvalidCommand { + + // List of warp names and their locations + final Map warps; + + public InvalidCommand() { + warps = new HashMap<>(); + } + + // /warp + @Subcommand + public void warp(CommandSender sender) { + sender.sendMessage("--- Warp help ---"); + sender.sendMessage("/warp - Show this help"); + sender.sendMessage("/warp - Teleport to "); + sender.sendMessage("/warp create - Creates a warp at your current location"); + sender.sendMessage("/warp tp - Teleports a player to a warp"); + } + + // /warp + @Subcommand + public void warp(Player player, @AStringArgument String warpName) { + player.teleport(warps.get(warpName)); + } + +// @Suggestion +// public ArgumentSuggestions aaaaa() { +// return ArgumentSuggestions.strings("hi", "bye"); +// } + + public SafeSuggestions aaaaaaaaaaa() { + return SafeSuggestions.suggest(new Location(null, 1, 2, 3)); + } + +// @Subcommand("create") +// @Permission("warps.create") +// @Executors({ExecutorType.ENTITY, ExecutorType.PLAYER}) +// public void createWarp( +// CommandSender sender, +// @Suggests("aaaaa") @AStringArgument String warpName +// ) throws WrapperCommandSyntaxException { +// +// warps.put(warpName, ((LivingEntity) sender).getLocation()); +// throw CommandAPI.fail(""); +// +// } + + @Subcommand("create") + @Permission("warps.create") + public void tpWarp(CommandSender sender, @APlayerArgument OfflinePlayer target, @AStringArgument String warpName) { + if(target.isOnline() && target instanceof Player onlineTarget) { + onlineTarget.teleport(warps.get(warpName)); + } + } + +} \ No newline at end of file diff --git a/commandapi-annotations-reloaded-tests/src/test/resources/NestedCommand.java b/commandapi-annotations-reloaded-tests/src/test/resources/NestedCommand.java new file mode 100644 index 0000000000..e5c45b8ad3 --- /dev/null +++ b/commandapi-annotations-reloaded-tests/src/test/resources/NestedCommand.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License + * + * 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. + *******************************************************************************/ +import dev.jorel.commandapi.annotations.reloaded.annotations.Command; + +@Command("outer") +public class NestedCommand { + + @Command("inner") + class InnerCommand { + } +} \ No newline at end of file diff --git a/commandapi-annotations-reloaded-tests/src/test/resources/TestCommand.java b/commandapi-annotations-reloaded-tests/src/test/resources/TestCommand.java new file mode 100644 index 0000000000..fa6a6b69ad --- /dev/null +++ b/commandapi-annotations-reloaded-tests/src/test/resources/TestCommand.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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. + *******************************************************************************/ +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.Location; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import dev.jorel.commandapi.annotations.reloaded.annotations.Command; +import dev.jorel.commandapi.annotations.reloaded.annotations.Help; +import dev.jorel.commandapi.annotations.reloaded.annotations.Permission; +import dev.jorel.commandapi.annotations.reloaded.annotations.Subcommand; +import dev.jorel.commandapi.annotations.reloaded.arguments.APlayerArgument; +import dev.jorel.commandapi.annotations.reloaded.arguments.AStringArgument; + +@Command("warp") +@Help(value = "Manages all warps on the server", shortDescription = "Manages warps") +public class TestCommand { + + // List of warp names and their locations + static Map warps = new HashMap<>(); + + @Subcommand + public static void warp(CommandSender sender) { + sender.sendMessage("--- Warp help ---"); + sender.sendMessage("/warp - Show this help"); + sender.sendMessage("/warp - Teleport to "); + sender.sendMessage("/warp create - Creates a warp at your current location"); + sender.sendMessage("/warp tp - Teleports a player to a warp"); + } + + @Subcommand + public static void warp(Player player, @AStringArgument String warpName) { + player.teleport(warps.get(warpName)); + } + + @Subcommand("create") + @Permission("warps.create") + public static void createWarp(Player player, @AStringArgument String warpName) { + warps.put(warpName, player.getLocation()); + } + + @Subcommand("create") + @Permission("warps.create") + public static void tpWarp(CommandSender sender, @APlayerArgument OfflinePlayer target, @AStringArgument String warpName) { + if(target.isOnline() && target instanceof Player onlineTarget) { + onlineTarget.teleport(warps.get(warpName)); + } + } + + +} \ No newline at end of file diff --git a/commandapi-annotations-reloaded-tests/src/test/resources/ValidCommand.java b/commandapi-annotations-reloaded-tests/src/test/resources/ValidCommand.java new file mode 100644 index 0000000000..688a10a787 --- /dev/null +++ b/commandapi-annotations-reloaded-tests/src/test/resources/ValidCommand.java @@ -0,0 +1,100 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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. + *******************************************************************************/ +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.Location; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; + +import dev.jorel.commandapi.annotations.reloaded.annotations.Command; +import dev.jorel.commandapi.annotations.reloaded.annotations.Executors; +import dev.jorel.commandapi.annotations.reloaded.annotations.Help; +import dev.jorel.commandapi.annotations.reloaded.annotations.Permission; +import dev.jorel.commandapi.annotations.reloaded.annotations.Subcommand; +import dev.jorel.commandapi.annotations.reloaded.arguments.APlayerArgument; +import dev.jorel.commandapi.annotations.reloaded.arguments.AStringArgument; +import dev.jorel.commandapi.executors.ExecutorType; + +@Command("warp") +@Help(value = "Manages all warps on the server", shortDescription = "Manages warps") +public class ValidCommand { + + // List of warp names and their locations + final Map warps; + + public ValidCommand() { + warps = new HashMap<>(); + } + + // /warp + @Subcommand + public void warp(CommandSender sender) { + sender.sendMessage("--- Warp help ---"); + sender.sendMessage("/warp - Show this help"); + sender.sendMessage("/warp - Teleport to "); + sender.sendMessage("/warp create - Creates a warp at your current location"); + sender.sendMessage("/warp tp - Teleports a player to a warp"); + } + + // /warp + @Subcommand + public void warp(Player player, @AStringArgument String warpName) { + player.teleport(warps.get(warpName)); + } + + @Subcommand("create") + class WarpCreate { + + // /warp create + @Subcommand + @Permission("warps.create") + @Executors({ExecutorType.ENTITY, ExecutorType.PLAYER}) + public void createWarp(CommandSender sender, @AStringArgument String warpName) { + warps.put(warpName, ((LivingEntity) sender).getLocation()); + } + + } + + @Subcommand("tp") + class WarpTp { + + // /warp tp + @Subcommand + @Permission("warps.tp") + public void tpWarp(Player player, @AStringArgument String warpName) { + player.teleport(warps.get(warpName)); + } + + // /warp tp + @Subcommand + @Permission("warps.tp.other") + public void tpWarp(CommandSender sender, @APlayerArgument OfflinePlayer target, @AStringArgument String warpName) { + if(target.isOnline() && target instanceof Player onlineTarget) { + onlineTarget.teleport(warps.get(warpName)); + } + } + + } + +} \ No newline at end of file diff --git a/commandapi-annotations-reloaded/.gitignore b/commandapi-annotations-reloaded/.gitignore new file mode 100644 index 0000000000..c71ea97aba --- /dev/null +++ b/commandapi-annotations-reloaded/.gitignore @@ -0,0 +1 @@ +/.apt_generated/ diff --git a/commandapi-annotations-reloaded/pom.xml b/commandapi-annotations-reloaded/pom.xml new file mode 100644 index 0000000000..ba54ffefeb --- /dev/null +++ b/commandapi-annotations-reloaded/pom.xml @@ -0,0 +1,136 @@ + + + 4.0.0 + + dev.jorel + commandapi + 9.6.0-SNAPSHOT + + + commandapi-annotations-reloaded + + + + codemc-repo + https://repo.codemc.org/repository/maven-public/ + default + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + minecraft-libraries + https://libraries.minecraft.net + + + + + + + + com.mojang + brigadier + 1.0.18 + test + + + dev.jorel + commandapi-bukkit-plugin + ${project.version} + test + + + + + dev.jorel + commandapi-bukkit-core + ${project.version} + + + com.google.auto.service + auto-service + ${auto-service.version} + provided + + + org.spigotmc + spigot-api + ${paper.version} + provided + + + + + + org.junit.jupiter + junit-jupiter + 5.10.2 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.10.2 + test + + + org.mockito + mockito-core + 5.11.0 + test + + + org.mockito + mockito-junit-jupiter + 5.11.0 + test + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + testCompile + + + + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M6 + + + + + \ No newline at end of file diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/AnnotationUtils.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/AnnotationUtils.java new file mode 100644 index 0000000000..5e28c90fce --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/AnnotationUtils.java @@ -0,0 +1,131 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded; + +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.AnnotationValue; +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.NestingKind; +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.TypeMirror; +import java.lang.annotation.Annotation; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +public class AnnotationUtils { + + /** + * Get the AnnotationMirror for a specific annotation on an element + */ + public Optional getAnnotationMirror(Element element, Class annotationClass) { + String className = annotationClass.getCanonicalName(); + return element.getAnnotationMirrors().stream() + .filter(mirror -> mirror.getAnnotationType().toString().equals(className)) + .findFirst(); + } + + /** + * Get the TypeMirror from an annotation + */ + public Optional getAnnotationValue(Element element, Class annotationClass) { + return getAnnotationMirror(element, annotationClass) + .flatMap(annotationMirror -> annotationMirror.getElementValues().entrySet().stream() + .filter(entry -> entry.getKey().getSimpleName().toString().equals("value")) + .map(Map.Entry::getValue) + .findFirst()); + } + + /** + * Get the TypeMirror from an annotation which has a value of type {@code Class<>} + */ + public Optional getAnnotationClassValue(Element element, Class annotationClass) { + return getAnnotationValue(element, annotationClass) + .map(AnnotationValue::getValue) + .map(TypeMirror.class::cast); + } + + /** + * @return True, if the element contains the given annotation + */ + public boolean hasAnnotation(Element element, Class annotationClass) { + return element.getAnnotation(annotationClass) != null; + } + + /** + * @return True, if the element contains any of the given annotations + */ + @SafeVarargs + public final boolean hasAnyAnnotation(Element element, Class... annotationClasses) { + for (Class annotationClass : annotationClasses) { + if (hasAnnotation(element, annotationClass)) { + return true; + } + } + return false; + } + + /** + * @return True, if the element contains none of the given annotations + */ + @SafeVarargs + public final boolean doesNotHaveAnnotations(Element element, Class... annotationClasses) { + return !hasAnyAnnotation(element, annotationClasses); + } + + /** + * @param element The element to find enclosed elements within + * @param annotationClass The annotation to look for in enclosed elements + * @return A list of all enclosed elements with the given annotation + */ + public List getEnclosedElementsWithAnnotation(Element element, Class annotationClass) { + return element.getEnclosedElements().stream() + .filter(enclosed -> hasAnnotation(enclosed, annotationClass)) + .toList(); + } + + /** + * @param element The element to find enclosed methods within + * @param annotationClass The annotation to look for in enclosed methods + * @return A list of all enclosed methods with the given annotation + */ + public List getEnclosedMethodsWithAnnotation(Element element, Class annotationClass) { + return getEnclosedElementsWithAnnotation(element, annotationClass).stream() + .filter(enclosed -> enclosed.getKind() == ElementKind.METHOD) + .map(ExecutableElement.class::cast) + .toList(); + } + + /** + * @param element The element to find the top-level class of + * @return The top-level class of this element + */ + public TypeElement getTopLevelClass(Element element) { + if (element instanceof TypeElement typeElement) { + if (typeElement.getNestingKind() == NestingKind.TOP_LEVEL) { + return typeElement; + } + } + return getTopLevelClass(element.getEnclosingElement()); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/Annotations.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/Annotations.java new file mode 100644 index 0000000000..c0086463fb --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/Annotations.java @@ -0,0 +1,150 @@ +/******************************************************************************* + * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License + *

+ * 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 dev.jorel.commandapi.annotations.reloaded; + +import com.google.auto.service.AutoService; +import dev.jorel.commandapi.annotations.reloaded.annotations.Command; +import dev.jorel.commandapi.annotations.reloaded.generators.IndentedWriter; +import dev.jorel.commandapi.annotations.reloaded.modules.base.CommandsClassGeneratorContext; +import dev.jorel.commandapi.annotations.reloaded.modules.base.CommandsClassModule; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRuleContextData; +import dev.jorel.commandapi.annotations.reloaded.parser.ParserUtils; + +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.Processor; +import javax.annotation.processing.RoundEnvironment; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.TypeElement; +import javax.tools.JavaFileObject; +import java.io.IOException; +import java.io.PrintWriter; +import java.time.ZonedDateTime; +import java.util.Comparator; +import java.util.Optional; +import java.util.Set; +import java.util.TreeSet; +import java.util.stream.Collectors; + +/** + * The main annotation processor for annotation-based arguments + */ +@AutoService(Processor.class) +public class Annotations extends AbstractProcessor { + private final Configuration configuration; + + /** + * Default constructor, uses default configuration + */ + public Annotations() { + this(new DefaultConfiguration()); + } + + /** + * Constructor used for commandapi-annotations tests. Allows an alternate + * configuration to be provided for testing purposes. + */ + public Annotations(Configuration configuration) { + this.configuration = configuration; + } + + // List of stuff we can deal with + @Override + public Set getSupportedAnnotationTypes() { + return configuration.getSupportedAnnotationTypes(); + } + + @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latestSupported(); + } + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + Logging logging = new Logging(processingEnv); + CommandsClassModule baseModule = configuration.getBaseModule(); + + // We need to do multiple "phases". + // Firstly, we perform semantic analysis (checking that we've not got two @Default + // annotations, type checking of annotations to method parameter types, ensuring + // suggestions map to what they should), ensuring we've not got two commands of + // the same name... + SemanticRuleContextData semanticsContext = new SemanticRuleContextData( + logging, + processingEnv, + roundEnv, + configuration.getAnnotationUtils() + ); + logging.info("Performing semantic checks"); + boolean semanticsPassed = baseModule.allPass(semanticsContext); + logging.info("Semantic checks %s".formatted(semanticsPassed ? "passed" : "failed")); + + // We then need to construct a context + // for each @Command class, which outlines the list of suggestion methods, its + // varying types, etc. You can think of this as a lexing/syntax analysis step. + + TreeSet commandClasses = roundEnv.getElementsAnnotatedWith(Command.class).stream() + .map(TypeElement.class::cast) // Change the type of commandClasses - + // we're asserting it's a TypeElement (it literally can't be anything else) + .collect(Collectors.toCollection(() -> // We want things sorted :) + new TreeSet<>(Comparator.comparing(it -> it.getQualifiedName().toString()))) + ); + logging.info("Found %d @%s classes".formatted(commandClasses.size(), Command.class.getSimpleName())); + if (commandClasses.isEmpty()) { + logging.info("Nothing to do. Aborting."); + return true; + } + + logging.info("Parsing contexts"); + ParserUtils parserUtils = new ParserUtils( + logging, + processingEnv, + configuration.getImportsBuilder(), + configuration.getAnnotationUtils() + ); + Optional maybeContexts = baseModule.parseAllContexts( + parserUtils, + configuration.getCommandsClassName(), + ZonedDateTime.now(), + commandClasses + ); + logging.info("Contexts parsed %s".formatted(maybeContexts.isPresent() ? "successfully" : "unsuccessfully")); + + if (!semanticsPassed || maybeContexts.isEmpty()) { + logging.info("Aborting"); + return true; + } + CommandsClassGeneratorContext allContexts = maybeContexts.orElseThrow(); + try { + logging.info("Generating %s class".formatted(configuration.getCommandsClassName())); + JavaFileObject builderFile = processingEnv + .getFiler() + .createSourceFile(configuration.getCommandsClassName()); + try (PrintWriter out = new PrintWriter(builderFile.openWriter())) { + baseModule.generate(new IndentedWriter(out), allContexts); + } + logging.info("%s class generated".formatted(configuration.getCommandsClassName())); + } catch (IOException e) { + e.printStackTrace(); + } + logging.info("Done"); + return true; + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/BackReference.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/BackReference.java new file mode 100644 index 0000000000..b43e61487a --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/BackReference.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded; + +import java.lang.ref.WeakReference; +import java.util.Objects; + +/** + * A reference back to an object previously added to a data structure to allow for cyclical structures. + *

+ * This is intended to be used to handle situations where nesting occurs. Such as parsing subclasses within subclasses. + * //TODO this could be moved to a more general location + * + * @param The type of object referenced + */ +public class BackReference { + // Use a weak reference to make things easier on the garbage collector + private WeakReference objRef = null; + + /** + * @param obj The object to store a reference to + * @throws IllegalStateException on an attempt to re-initialise. It is not possible to re-use. + * @throws NullPointerException if obj was null + */ + public void initialise(T obj) { + if (objRef != null) { + throw new IllegalStateException("Attempted to initialise twice"); + } + objRef = new WeakReference<>(Objects.requireNonNull(obj)); + } + + /** + * @return The object that was stored earlier + * @throws IllegalStateException if there was no call to {@link #initialise(Object)} + */ + public T get() { + if (objRef == null) { + throw new IllegalStateException("Attempted to get before initialisation"); + } + return Objects.requireNonNull(objRef.get()); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/Configuration.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/Configuration.java new file mode 100644 index 0000000000..a4db2a3f44 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/Configuration.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded; + +import dev.jorel.commandapi.annotations.reloaded.modules.base.CommandsClassModule; +import dev.jorel.commandapi.annotations.reloaded.parser.ImportsBuilder; + +import java.lang.annotation.Annotation; +import java.util.Set; + +/** + * Interface for configuration data needed by the CommandAPI annotation system + */ +public interface Configuration { + /** + * Allows the Commands class name to be altered to prevent conflicts when running test cases + * + * @return The Commands class name to use when generating the class + */ + String getCommandsClassName(); + + /** + * @return A set of all supported command argument annotations + */ + Set> getArgumentAnnotations(); + + /** + * @return A set of all other supported command annotations + */ + Set> getOtherAnnotations(); + + /** + * @return A set of the canonical names of all supported annotations + */ + Set getSupportedAnnotationTypes(); + + /** + * @return The base module that contains the modular hierarchy for all features of the annotation processor + */ + CommandsClassModule getBaseModule(); + + /** + * @return The imports builder to use for the generated commands class + */ + ImportsBuilder getImportsBuilder(); + + /** + * @return Utility functions for working with java annotations + */ + AnnotationUtils getAnnotationUtils(); +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/DefaultConfiguration.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/DefaultConfiguration.java new file mode 100644 index 0000000000..edf3641ad8 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/DefaultConfiguration.java @@ -0,0 +1,171 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded; + +import dev.jorel.commandapi.annotations.reloaded.annotations.Command; +import dev.jorel.commandapi.annotations.reloaded.annotations.Executes; +import dev.jorel.commandapi.annotations.reloaded.annotations.Help; +import dev.jorel.commandapi.annotations.reloaded.annotations.NeedsOp; +import dev.jorel.commandapi.annotations.reloaded.annotations.Permission; +import dev.jorel.commandapi.annotations.reloaded.annotations.Subcommand; +import dev.jorel.commandapi.annotations.reloaded.annotations.Subcommands; +import dev.jorel.commandapi.annotations.reloaded.annotations.Suggestion; +import dev.jorel.commandapi.annotations.reloaded.annotations.Suggests; +import dev.jorel.commandapi.annotations.reloaded.arguments.ArgumentAnnotations; +import dev.jorel.commandapi.annotations.reloaded.modules.arguments.CommandExecutorMethodArgumentsModule; +import dev.jorel.commandapi.annotations.reloaded.modules.base.CommandsClassImportsGenerator; +import dev.jorel.commandapi.annotations.reloaded.modules.base.CommandsClassJavadocGenerator; +import dev.jorel.commandapi.annotations.reloaded.modules.base.CommandsClassModule; +import dev.jorel.commandapi.annotations.reloaded.modules.base.CommandsClassPackageGenerator; +import dev.jorel.commandapi.annotations.reloaded.modules.commands.CommandExecutorMethodBaseCommandNameParser; +import dev.jorel.commandapi.annotations.reloaded.modules.commands.CommandExecutorMethodExecutorModule; +import dev.jorel.commandapi.annotations.reloaded.modules.commands.CommandExecutorMethodModule; +import dev.jorel.commandapi.annotations.reloaded.modules.commands.CommandExecutorsModule; +import dev.jorel.commandapi.annotations.reloaded.modules.commands.CommandNamesParser; +import dev.jorel.commandapi.annotations.reloaded.modules.commands.CommandRegisterMethodJavadocGenerator; +import dev.jorel.commandapi.annotations.reloaded.modules.commands.CommandRegisterMethodModule; +import dev.jorel.commandapi.annotations.reloaded.modules.commands.RuleCommandCanOnlyGoOnTopLevelClasses; +import dev.jorel.commandapi.annotations.reloaded.modules.permissions.CommandExecutorMethodPermissionsModule; +import dev.jorel.commandapi.annotations.reloaded.modules.subcommands.RuleNonTopLevelTypeSubCommandsMustGoInsideCommandOrSubcommandClasses; +import dev.jorel.commandapi.annotations.reloaded.modules.subcommands.RuleNonTopLevelTypeSubcommandsCanOnlyGoInsideClasses; +import dev.jorel.commandapi.annotations.reloaded.modules.subcommands.RuleTopLevelSubCommandClassesMustExtendCommandOrSubcommandClass; +import dev.jorel.commandapi.annotations.reloaded.modules.subcommands.RuleTopLevelSubCommandClassesMustExtendParentClassWithExternalSubcommand; +import dev.jorel.commandapi.annotations.reloaded.modules.subcommands.RuleTopLevelSubCommandClassesMustHaveASuperClass; +import dev.jorel.commandapi.annotations.reloaded.modules.subcommands.RuleTypeSubCommandsCanOnlyGoOnNormalClasses; +import dev.jorel.commandapi.annotations.reloaded.modules.subcommands.SubcommandClassModule; +import dev.jorel.commandapi.annotations.reloaded.modules.subcommands.SubcommandClassesModule; +import dev.jorel.commandapi.annotations.reloaded.modules.subcommands.SubcommandMethodsModule; +import dev.jorel.commandapi.annotations.reloaded.modules.subcommands.SubcommandsModule; +import dev.jorel.commandapi.annotations.reloaded.parser.ImportsBuilder; +import dev.jorel.commandapi.annotations.reloaded.parser.ImportsBuilderImpl; + +import java.lang.annotation.Annotation; +import java.util.Collection; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * The default configuration for the CommandAPI annotation system + */ +public class DefaultConfiguration implements Configuration { + private static final String COMMANDS_CLASS_NAME = "Commands"; + + private static final Set> OTHER_ANNOTATIONS = Set.of( + Command.class, + NeedsOp.class, + Permission.class, + Help.class, + Suggestion.class, + Subcommand.class, + Subcommands.class, + Suggests.class, + Executes.class + ); + + @Override + public String getCommandsClassName() { + return COMMANDS_CLASS_NAME; + } + + @Override + public Set> getArgumentAnnotations() { + return ArgumentAnnotations.ALL; + } + + @Override + public Set> getOtherAnnotations() { + return OTHER_ANNOTATIONS; + } + + @Override + public Set getSupportedAnnotationTypes() { + return Stream.of( + getArgumentAnnotations(), + getOtherAnnotations() + ) + .flatMap(Collection::stream) + .map(Class::getCanonicalName) + .collect(Collectors.toSet()); + } + + private SubcommandClassModule getSubcommandClassModule() { + BackReference subcommandClassModuleRef = new BackReference<>(); + SubcommandClassModule subcommandClassModule = new SubcommandClassModule( + new SubcommandClassesModule( + subcommandClassModuleRef + ), new SubcommandMethodsModule( + new CommandExecutorMethodModule( + new CommandExecutorMethodBaseCommandNameParser( + new CommandNamesParser() + ), + new CommandExecutorMethodPermissionsModule(), + new CommandExecutorMethodArgumentsModule(), + new CommandExecutorMethodExecutorModule() + ) + ), + new CommandExecutorsModule( + new CommandExecutorMethodModule( + new CommandExecutorMethodBaseCommandNameParser( + new CommandNamesParser() + ), + new CommandExecutorMethodPermissionsModule(), + new CommandExecutorMethodArgumentsModule(), + new CommandExecutorMethodExecutorModule() + ) + ) + ); + subcommandClassModuleRef.initialise(subcommandClassModule); + return subcommandClassModule; + } + + @Override + public CommandsClassModule getBaseModule() { + return new CommandsClassModule( + new CommandsClassPackageGenerator(), + new CommandsClassImportsGenerator(), + new CommandsClassJavadocGenerator(), + new CommandRegisterMethodModule( + new RuleCommandCanOnlyGoOnTopLevelClasses(), + new CommandRegisterMethodJavadocGenerator(), + new SubcommandsModule( + new RuleNonTopLevelTypeSubCommandsMustGoInsideCommandOrSubcommandClasses(), + new RuleNonTopLevelTypeSubcommandsCanOnlyGoInsideClasses(), + new RuleTypeSubCommandsCanOnlyGoOnNormalClasses(), + new RuleTopLevelSubCommandClassesMustExtendParentClassWithExternalSubcommand(), + new RuleTopLevelSubCommandClassesMustHaveASuperClass(), + new RuleTopLevelSubCommandClassesMustExtendCommandOrSubcommandClass(), + getSubcommandClassModule() + ) + ) + ); + } + + @Override + public ImportsBuilder getImportsBuilder() { + return new ImportsBuilderImpl(); + } + + @Override + public AnnotationUtils getAnnotationUtils() { + return new AnnotationUtils(); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/Logging.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/Logging.java new file mode 100644 index 0000000000..4af7a38662 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/Logging.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded; + +import javax.annotation.processing.Messager; +import javax.annotation.processing.ProcessingEnvironment; +import javax.lang.model.element.Element; +import javax.tools.Diagnostic.Kind; + +/** + * A logger for the CommandAPI annotation system annotation processor + */ +public class Logging { + + private final ProcessingEnvironment processingEnv; + + public Logging(ProcessingEnvironment processor) { + this.processingEnv = processor; + } + + public void complain(Element element, String message) { + System.out.println(message + " at " + element); + getMessager().printMessage(Kind.ERROR, message, element); + } + + public void complain(String message) { + System.out.println(message); + getMessager().printMessage(Kind.ERROR, message); + } + + public void warn(Element element, String message) { + getMessager().printMessage(Kind.MANDATORY_WARNING, message, element); + } + + public void info(Element element, String message) { + getMessager().printMessage(Kind.NOTE, message, element); + } + + public void info(Object message) { + getMessager().printMessage(Kind.NOTE, String.valueOf(message)); + } + + public Messager getMessager() { + return processingEnv.getMessager(); + } + + /* + typeElement.getAnnotationMirrors().forEach(mirror -> { + mirror.getElementValues(); + logging.getMessager().printMessage(Kind.MANDATORY_WARNING, mirror.getElementValues().toString()); + logging.getMessager().printMessage(Kind.MANDATORY_WARNING, mirror.getElementValues().toString(), typeElement, (AnnotationMirror)mirror); + }); + */ + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/ReturnTypesAreNonnullByDefault.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/ReturnTypesAreNonnullByDefault.java new file mode 100644 index 0000000000..a7ef167421 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/ReturnTypesAreNonnullByDefault.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded; + +import javax.annotation.Nonnull; +import javax.annotation.meta.TypeQualifierDefault; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * To be used in package-info.java to mark all return values as non-null by default + * // TODO: Move this to a more general location for the project + */ +@Nonnull +@TypeQualifierDefault(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +public @interface ReturnTypesAreNonnullByDefault { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/ArgumentParser.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/ArgumentParser.java new file mode 100644 index 0000000000..9d6c4ade2a --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/ArgumentParser.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright 2022 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation to indicate that this class is a + * {@link dev.jorel.commandapi.arguments.CustomArgument.CustomArgumentInfoParser} to be used for a + * {@link dev.jorel.commandapi.annotations.reloaded.arguments.ACustomArgument} in the CommandAPI annotation system + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.SOURCE) +public @interface ArgumentParser { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/Command.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/Command.java new file mode 100644 index 0000000000..71f271b776 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/Command.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * The annotation to indicate that this class is a command + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.SOURCE) +public @interface Command { + + /** + * @return The name of the command that this class represents + */ + String[] value(); +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/Executes.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/Executes.java new file mode 100644 index 0000000000..4bdbd89a06 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/Executes.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * The annotation to indicate that this method can be used as an executor for a command or subcommand + */ +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.SOURCE) +public @interface Executes { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/ExternalSubcommand.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/ExternalSubcommand.java new file mode 100644 index 0000000000..001921972f --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/ExternalSubcommand.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * The annotation to indicate that this method is a subcommand defined in another class + */ +@Target({ ElementType.FIELD }) +@Retention(RetentionPolicy.SOURCE) +public @interface ExternalSubcommand { + + /** + * @return The names (and thus, aliases) of this subcommand + */ + Class value(); +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/Help.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/Help.java new file mode 100644 index 0000000000..ff9e17e1bc --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/Help.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * The annotation which includes information about the help for a command + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.SOURCE) +public @interface Help { + + /** + * @return The full description for this command's help + */ + String value(); + + /** + * @return The short description for this command's help + */ + String shortDescription() default ""; +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/NeedsOp.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/NeedsOp.java new file mode 100644 index 0000000000..23a68bec19 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/NeedsOp.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * The annotation to apply to indicate that a command or subcommand requires being OP to use. + */ +@Target({ElementType.METHOD, ElementType.TYPE, ElementType.FIELD}) +@Retention(RetentionPolicy.SOURCE) +public @interface NeedsOp { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/NodeName.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/NodeName.java new file mode 100644 index 0000000000..a280b1fc19 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/NodeName.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright 2022 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Explicitly state a node name, instead of using the field or parameter name + */ +@Target({ElementType.PARAMETER, ElementType.FIELD}) +@Retention(RetentionPolicy.SOURCE) +public @interface NodeName { + + /** + * @return The name of this argument's node as shown in help + */ + String value(); +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/Permission.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/Permission.java new file mode 100644 index 0000000000..6ce46195e7 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/Permission.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * The annotation to apply a permission to a command or subcommand + */ +@Target({ElementType.METHOD, ElementType.TYPE, ElementType.FIELD}) +@Retention(RetentionPolicy.SOURCE) +public @interface Permission { + + /** + * The permission literal that this argument represents + * @return the permission literal that this argument represents + */ + String value(); +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/Subcommand.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/Subcommand.java new file mode 100644 index 0000000000..c630d96476 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/Subcommand.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * The annotation to indicate that this method is a subcommand + */ +@Target( { ElementType.METHOD, ElementType.TYPE }) +@Retention(RetentionPolicy.SOURCE) +@Repeatable(Subcommands.class) +public @interface Subcommand { + + /** + * The names (and thus, aliases) of this subcommand + * @return the names that this subcommand produces + */ + String[] value() default {}; +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/Subcommands.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/Subcommands.java new file mode 100644 index 0000000000..dc475f92b7 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/Subcommands.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * When Subcommand is used multiple times on the same element, this contains all of them. + */ +@Retention(RetentionPolicy.SOURCE) +@Target( { ElementType.METHOD, ElementType.TYPE }) +public @interface Subcommands { + + /** + * @return An ordered array of all Subcommand annotations on this element + */ + Subcommand[] value(); +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/Suggestion.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/Suggestion.java new file mode 100644 index 0000000000..46f1560b47 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/Suggestion.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright 2022 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.SOURCE) +public @interface Suggestion { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/Suggests.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/Suggests.java new file mode 100644 index 0000000000..a39dd6f0d5 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/Suggests.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright 2022 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.annotations; + +import dev.jorel.commandapi.arguments.ISuggestions; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.function.Supplier; + +/** + * The annotation which contains a list of suggestions for an argument + */ +@Target({ElementType.PARAMETER, ElementType.FIELD}) +@Retention(RetentionPolicy.SOURCE) +public @interface Suggests { + + /** + * @return A class that supplies a list of suggestions for an argument + */ + Class> value(); +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/package-info.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/package-info.java new file mode 100644 index 0000000000..1bb281b127 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/annotations/package-info.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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. + *******************************************************************************/ +/** + * Annotations which can be used with the CommandAPI annotation system. + */ +@ParametersAreNonnullByDefault +@ReturnTypesAreNonnullByDefault +package dev.jorel.commandapi.annotations.reloaded.annotations; + +import javax.annotation.ParametersAreNonnullByDefault; +import dev.jorel.commandapi.annotations.reloaded.ReturnTypesAreNonnullByDefault; \ No newline at end of file diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AAdvancementArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AAdvancementArgument.java new file mode 100644 index 0000000000..d06a1579f9 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AAdvancementArgument.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.AdvancementArgument; + +/** + * Annotation equivalent of the {@link AdvancementArgument} + */ +@Primitive("org.bukkit.advancement.Advancement") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface AAdvancementArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AAdventureChatArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AAdventureChatArgument.java new file mode 100644 index 0000000000..3ff505f7e1 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AAdventureChatArgument.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.AdventureChatArgument; + +/** + * Annotation equivalent of the {@link AdventureChatArgument} + */ +@Primitive("net.kyori.adventure.text.Component") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface AAdventureChatArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AAdventureChatComponentArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AAdventureChatComponentArgument.java new file mode 100644 index 0000000000..2aa99e6481 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AAdventureChatComponentArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2021 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.AdventureChatComponentArgument; + +/** + * Annotation equivalent of the {@link AdventureChatComponentArgument} + */ +@Primitive("net.kyori.adventure.text.Component") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface AAdventureChatComponentArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AAngleArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AAngleArgument.java new file mode 100644 index 0000000000..d046059a4b --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AAngleArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.AngleArgument; + +/** + * Annotation equivalent of the {@link AngleArgument} + */ +@Primitive("float") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface AAngleArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AAxisArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AAxisArgument.java new file mode 100644 index 0000000000..056caf24b3 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AAxisArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.AxisArgument; + +/** + * Annotation equivalent of the {@link AxisArgument} + */ +@Primitive("java.util.EnumSet") +@Retention(RetentionPolicy.SOURCE) +@Target({ ElementType.PARAMETER, ElementType.FIELD }) +public @interface AAxisArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ABiomeArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ABiomeArgument.java new file mode 100644 index 0000000000..4ea2db758b --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ABiomeArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.BiomeArgument; + +/** + * Annotation equivalent of the {@link BiomeArgument} + */ +@Primitive("org.bukkit.block.Biome") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface ABiomeArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ABlockPredicateArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ABlockPredicateArgument.java new file mode 100644 index 0000000000..aa9fa71311 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ABlockPredicateArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.BlockPredicateArgument; + +/** + * Annotation equivalent of the {@link BlockPredicateArgument} + */ +@Primitive("java.util.function.Predicate") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface ABlockPredicateArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ABlockStateArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ABlockStateArgument.java new file mode 100644 index 0000000000..16a180f306 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ABlockStateArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.BlockStateArgument; + +/** + * Annotation equivalent of the {@link BlockStateArgument} + */ +@Primitive("org.bukkit.block.data.BlockData") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface ABlockStateArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ABooleanArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ABooleanArgument.java new file mode 100644 index 0000000000..22c6d1983f --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ABooleanArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.BooleanArgument; + +/** + * Annotation equivalent of the {@link BooleanArgument} + */ +@Primitive("boolean") +@Retention(RetentionPolicy.SOURCE) +@Target({ ElementType.PARAMETER, ElementType.FIELD }) +public @interface ABooleanArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AChatArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AChatArgument.java new file mode 100644 index 0000000000..2bea3b886b --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AChatArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.ChatArgument; + +/** + * Annotation equivalent of the {@link ChatArgument} + */ +@Primitive("net.md_5.bungee.api.chat.BaseComponent[]") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface AChatArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AChatColorArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AChatColorArgument.java new file mode 100644 index 0000000000..6ccb9890c3 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AChatColorArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.ChatColorArgument; + +/** + * Annotation equivalent of the {@link ChatColorArgument} + */ +@Primitive("org.bukkit.ChatColor") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface AChatColorArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AChatComponentArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AChatComponentArgument.java new file mode 100644 index 0000000000..fab0508dc9 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AChatComponentArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.ChatComponentArgument; + +/** + * Annotation equivalent of the {@link ChatComponentArgument} + */ +@Primitive("net.md_5.bungee.api.chat.BaseComponent[]") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface AChatComponentArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ACustomArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ACustomArgument.java new file mode 100644 index 0000000000..38d62cc8f7 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ACustomArgument.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.ChatComponentArgument; +import dev.jorel.commandapi.arguments.CustomArgument.CustomArgumentInfoParser; + +/** + * Annotation equivalent of the {@link dev.jorel.commandapi.arguments.CustomArgument} + */ +@Primitive("void") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface ACustomArgument { + + /** + * @return The class that parses the custom argument info + */ + Class> value(); + + /** + * @return Whether this custom argument uses a NamespaceKeyedArgument as the base + */ + boolean keyed() default false; + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ADoubleArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ADoubleArgument.java new file mode 100644 index 0000000000..2c2fccceb7 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ADoubleArgument.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.DoubleArgument; + +/** + * Annotation equivalent of the {@link DoubleArgument} + */ +@Primitive("double") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface ADoubleArgument { + + /** + * @return The minimum value this argument can take (inclusive) + */ + double min() default -Double.MAX_VALUE; + + /** + * @return The maximum value this argument can take (inclusive) + */ + double max() default Double.MAX_VALUE; + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AEnchantmentArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AEnchantmentArgument.java new file mode 100644 index 0000000000..9fb7271a0a --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AEnchantmentArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.EnchantmentArgument; + +/** + * Annotation equivalent of the {@link EnchantmentArgument} + */ +@Primitive("org.bukkit.enchantments.Enchantment") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface AEnchantmentArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AEntitySelectorArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AEntitySelectorArgument.java new file mode 100644 index 0000000000..d78a394c8d --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AEntitySelectorArgument.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.EntitySelectorArgument; + +/** + * Annotation equivalent of the {@link EntitySelectorArgument} + */ +@Retention(RetentionPolicy.SOURCE) +@Target({}) +public @interface AEntitySelectorArgument { + /** + * Annotation equivalent of the {@link EntitySelectorArgument.ManyPlayers} + */ + @Primitive("java.util.Collection") + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.PARAMETER, ElementType.FIELD}) + @interface ManyPlayers { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + } + + /** + * Annotation equivalent of the {@link EntitySelectorArgument.OnePlayer} + */ + @Primitive("org.bukkit.entity.Player") + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.PARAMETER, ElementType.FIELD}) + @interface OnePlayer { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + } + + /** + * Annotation equivalent of the {@link EntitySelectorArgument.ManyEntities} + */ + @Primitive("java.util.Collection") + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.PARAMETER, ElementType.FIELD}) + @interface ManyEntities { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + } + + /** + * Annotation equivalent of the {@link EntitySelectorArgument.OneEntity} + */ + @Primitive("org.bukkit.entity.Entity") + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.PARAMETER, ElementType.FIELD}) + @interface OneEntity { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AEntityTypeArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AEntityTypeArgument.java new file mode 100644 index 0000000000..27420342f7 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AEntityTypeArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.EntityTypeArgument; + +/** + * Annotation equivalent of the {@link EntityTypeArgument} + */ +@Primitive("org.bukkit.entity.EntityType") +@Retention(RetentionPolicy.SOURCE) +@Target({ ElementType.PARAMETER, ElementType.FIELD }) +public @interface AEntityTypeArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AFloatArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AFloatArgument.java new file mode 100644 index 0000000000..7b2bf9ed44 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AFloatArgument.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.FloatArgument; + +/** + * Annotation equivalent of the {@link FloatArgument} + */ +@Primitive("float") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface AFloatArgument { + + /** + * @return The minimum value this argument can take (inclusive) + */ + float min() default -Float.MAX_VALUE; + + /** + * @return The maximum value this argument can take (inclusive) + */ + float max() default Float.MAX_VALUE; + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AFloatRangeArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AFloatRangeArgument.java new file mode 100644 index 0000000000..4325ad5bed --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AFloatRangeArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.FloatRangeArgument; + +/** + * Annotation equivalent of the {@link FloatRangeArgument} + */ +@Primitive("dev.jorel.commandapi.wrappers.FloatRange") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface AFloatRangeArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AFunctionArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AFunctionArgument.java new file mode 100644 index 0000000000..681fc318eb --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AFunctionArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.FunctionArgument; + +/** + * Annotation equivalent of the {@link FunctionArgument} + */ +@Primitive("dev.jorel.commandapi.wrappers.FunctionWrapper[]") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface AFunctionArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AGreedyStringArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AGreedyStringArgument.java new file mode 100644 index 0000000000..e0280de058 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AGreedyStringArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.EntitySelectorArgument; + +/** + * Annotation equivalent of the {@link EntitySelectorArgument} + */ +@Primitive("java.lang.String") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface AGreedyStringArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AIntegerArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AIntegerArgument.java new file mode 100644 index 0000000000..9e57f185ef --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AIntegerArgument.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.IntegerArgument; + +/** + * Annotation equivalent of the {@link IntegerArgument} + */ +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +@Primitive("int") +public @interface AIntegerArgument { + + /** + * @return The minimum value this argument can take (inclusive) + */ + int min() default Integer.MIN_VALUE; + + /** + * @return The maximum value this argument can take (inclusive) + */ + int max() default Integer.MAX_VALUE; + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} \ No newline at end of file diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AIntegerRangeArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AIntegerRangeArgument.java new file mode 100644 index 0000000000..55ef386576 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AIntegerRangeArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.IntegerRangeArgument; + +/** + * Annotation equivalent of the {@link IntegerRangeArgument} + */ +@Primitive("dev.jorel.commandapi.wrappers.IntegerRange") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface AIntegerRangeArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AItemStackArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AItemStackArgument.java new file mode 100644 index 0000000000..762e4a9fb3 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AItemStackArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.ItemStackArgument; + +/** + * Annotation equivalent of the {@link ItemStackArgument} + */ +@Primitive("org.bukkit.inventory.ItemStack") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface AItemStackArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AItemStackPredicateArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AItemStackPredicateArgument.java new file mode 100644 index 0000000000..a495703d39 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AItemStackPredicateArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.ItemStackPredicateArgument; + +/** + * Annotation equivalent of the {@link ItemStackPredicateArgument} + */ +@Primitive("java.util.function.Predicate") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface AItemStackPredicateArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ALiteralArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ALiteralArgument.java new file mode 100644 index 0000000000..21cd7280b9 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ALiteralArgument.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.LiteralArgument; + +/** + * Annotation equivalent of the {@link LiteralArgument} + */ +@Primitive("java.lang.String") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +@Deprecated(forRemoval = false, since = "8.0.0") +public @interface ALiteralArgument { + + /** + * @return the string literal that this argument will represent + */ + String value(); + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ALocation2DArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ALocation2DArgument.java new file mode 100644 index 0000000000..81c2f2f050 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ALocation2DArgument.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.Location2DArgument; +import dev.jorel.commandapi.arguments.LocationType; + +/** + * Annotation equivalent of the {@link Location2DArgument} + */ +@Primitive("dev.jorel.commandapi.wrappers.Location2D") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface ALocation2DArgument { + + /** + * @return the location type of this location, either + * {@link LocationType#BLOCK_POSITION} or + * {@link LocationType#PRECISE_POSITION}. Defaults to + * {@link LocationType#PRECISE_POSITION} + */ + LocationType value() default LocationType.PRECISE_POSITION; + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ALocationArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ALocationArgument.java new file mode 100644 index 0000000000..a513e643e3 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ALocationArgument.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.LocationArgument; +import dev.jorel.commandapi.arguments.LocationType; + +/** + * Annotation equivalent of the {@link LocationArgument} + */ +@Primitive("org.bukkit.Location") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface ALocationArgument { + + /** + * @return the location type of this location, either + * {@link LocationType#BLOCK_POSITION} or + * {@link LocationType#PRECISE_POSITION}. Defaults to + * {@link LocationType#PRECISE_POSITION} + */ + LocationType value() default LocationType.PRECISE_POSITION; + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ALongArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ALongArgument.java new file mode 100644 index 0000000000..55d5941a05 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ALongArgument.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.LongArgument; + +/** + * Annotation equivalent of the {@link LongArgument} + */ +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +@Primitive("long") +public @interface ALongArgument { + + /** + * @return The minimum value this argument can take (inclusive) + */ + long min() default Long.MIN_VALUE; + + /** + * @return The maximum value this argument can take (inclusive) + */ + long max() default Long.MAX_VALUE; + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} \ No newline at end of file diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ALootTableArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ALootTableArgument.java new file mode 100644 index 0000000000..007c4e6520 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ALootTableArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.LootTableArgument; + +/** + * Annotation equivalent of the {@link LootTableArgument} + */ +@Primitive("org.bukkit.loot.LootTable") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface ALootTableArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AMathOperationArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AMathOperationArgument.java new file mode 100644 index 0000000000..2f1d29a164 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AMathOperationArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.MathOperationArgument; + +/** + * Annotation equivalent of the {@link MathOperationArgument} + */ +@Primitive("dev.jorel.commandapi.wrappers.MathOperation") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface AMathOperationArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AMultiLiteralArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AMultiLiteralArgument.java new file mode 100644 index 0000000000..146d7d31e1 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AMultiLiteralArgument.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.MultiLiteralArgument; + +/** + * Annotation equivalent of the {@link MultiLiteralArgument} + */ +@Primitive("java.lang.String") +@Retention(RetentionPolicy.SOURCE) +@Target({ ElementType.PARAMETER, ElementType.FIELD }) +public @interface AMultiLiteralArgument { + + /** + * @return the literals that this argument represents + */ + String[] value(); + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ANBTCompoundArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ANBTCompoundArgument.java new file mode 100644 index 0000000000..133d07d27d --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ANBTCompoundArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.NBTCompoundArgument; + +/** + * Annotation equivalent of the {@link NBTCompoundArgument} + */ +@Primitive({}) +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface ANBTCompoundArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ANamespacedKeyArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ANamespacedKeyArgument.java new file mode 100644 index 0000000000..04cb2b7078 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ANamespacedKeyArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.NamespacedKeyArgument; + +/** + * Annotation equivalent of the {@link NamespacedKeyArgument} + */ +@Primitive("org.bukkit.NamespacedKey") +@Retention(RetentionPolicy.SOURCE) +@Target({ ElementType.PARAMETER, ElementType.FIELD }) +public @interface ANamespacedKeyArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AObjectiveArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AObjectiveArgument.java new file mode 100644 index 0000000000..9af682f37f --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AObjectiveArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.ObjectiveArgument; + +/** + * Annotation equivalent of the {@link ObjectiveArgument} + */ +@Primitive("java.lang.String") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface AObjectiveArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AObjectiveCriteriaArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AObjectiveCriteriaArgument.java new file mode 100644 index 0000000000..250960b3ed --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AObjectiveCriteriaArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.ObjectiveCriteriaArgument; + +/** + * Annotation equivalent of the {@link ObjectiveCriteriaArgument} + */ +@Primitive("java.lang.String") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface AObjectiveCriteriaArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AOfflinePlayerArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AOfflinePlayerArgument.java new file mode 100644 index 0000000000..bb7f5bc1f1 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AOfflinePlayerArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.OfflinePlayerArgument; + +/** + * Annotation equivalent of the {@link OfflinePlayerArgument} + */ +@Primitive("org.bukkit.OfflinePlayer") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface AOfflinePlayerArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AParticleArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AParticleArgument.java new file mode 100644 index 0000000000..8156dd710d --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AParticleArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.ParticleArgument; + +/** + * Annotation equivalent of the {@link ParticleArgument} + */ +@Primitive("org.bukkit.Particle") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface AParticleArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/APlayerArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/APlayerArgument.java new file mode 100644 index 0000000000..6f1a22e246 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/APlayerArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.PlayerArgument; + +/** + * Annotation equivalent of the {@link PlayerArgument} + */ +@Primitive("org.bukkit.entity.Player") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface APlayerArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/APotionEffectArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/APotionEffectArgument.java new file mode 100644 index 0000000000..495534906a --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/APotionEffectArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.PotionEffectArgument; + +/** + * Annotation equivalent of the {@link PotionEffectArgument} + */ +@Primitive("org.bukkit.potion.PotionEffectType") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface APotionEffectArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ARecipeArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ARecipeArgument.java new file mode 100644 index 0000000000..c0b48a5d6c --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ARecipeArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.RecipeArgument; + +/** + * Annotation equivalent of the {@link RecipeArgument} + */ +@Primitive("org.bukkit.inventory.Recipe") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface ARecipeArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ARotationArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ARotationArgument.java new file mode 100644 index 0000000000..093c20d967 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ARotationArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.RotationArgument; + +/** + * Annotation equivalent of the {@link RotationArgument} + */ +@Primitive("dev.jorel.commandapi.wrappers.Rotation") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface ARotationArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AScoreHolderArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AScoreHolderArgument.java new file mode 100644 index 0000000000..1cca95453b --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AScoreHolderArgument.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.ScoreHolderArgument; + +/** + * Annotation equivalent of the {@link ScoreHolderArgument} + */ +@Retention(RetentionPolicy.SOURCE) +@Target({}) +public @interface AScoreHolderArgument { + /** + * Annotation equivalent of the {@link ScoreHolderArgument.Single} + */ + @Primitive("java.lang.String") + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.PARAMETER, ElementType.FIELD}) + @interface Single { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + } + + /** + * Annotation equivalent of the {@link ScoreHolderArgument.Multiple} + */ + @Primitive("java.util.Collection") + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.PARAMETER, ElementType.FIELD}) + @interface Multiple { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AScoreboardSlotArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AScoreboardSlotArgument.java new file mode 100644 index 0000000000..5103578bb9 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AScoreboardSlotArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.ScoreboardSlotArgument; + +/** + * Annotation equivalent of the {@link ScoreboardSlotArgument} + */ +@Primitive("dev.jorel.commandapi.wrappers.ScoreboardSlot") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface AScoreboardSlotArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ASoundArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ASoundArgument.java new file mode 100644 index 0000000000..57c9390b48 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ASoundArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.SoundArgument; + +/** + * Annotation equivalent of the {@link SoundArgument} + */ +@Primitive("org.bukkit.Sound") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface ASoundArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AStringArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AStringArgument.java new file mode 100644 index 0000000000..bc9db3ad35 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AStringArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.StringArgument; + +/** + * Annotation equivalent of the {@link StringArgument} + */ +@Primitive("java.lang.String") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface AStringArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ATeamArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ATeamArgument.java new file mode 100644 index 0000000000..f6b13c135d --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ATeamArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.TeamArgument; + +/** + * Annotation equivalent of the {@link TeamArgument} + */ +@Primitive("java.lang.String") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface ATeamArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ATextArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ATextArgument.java new file mode 100644 index 0000000000..ed7ec9fcda --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ATextArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.TextArgument; + +/** + * Annotation equivalent of the {@link TextArgument} + */ +@Primitive("java.lang.String") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface ATextArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ATimeArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ATimeArgument.java new file mode 100644 index 0000000000..61bbabcd08 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ATimeArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.TimeArgument; + +/** + * Annotation equivalent of the {@link TimeArgument} + */ +@Primitive("int") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface ATimeArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AUUIDArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AUUIDArgument.java new file mode 100644 index 0000000000..b099330e95 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AUUIDArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.UUIDArgument; + +/** + * Annotation equivalent of the {@link UUIDArgument} + */ +@Primitive("java.util.UUID") +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.PARAMETER, ElementType.FIELD}) +public @interface AUUIDArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AWorldArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AWorldArgument.java new file mode 100644 index 0000000000..016072d997 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/AWorldArgument.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2022 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import dev.jorel.commandapi.arguments.WorldArgument; + +/** + * Annotation equivalent of the {@link WorldArgument} + */ +@Primitive("org.bukkit.World") +@Retention(RetentionPolicy.SOURCE) +@Target(ElementType.PARAMETER) +public @interface AWorldArgument { + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional() default false; + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ArgumentAnnotations.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ArgumentAnnotations.java new file mode 100644 index 0000000000..2f1182effb --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/ArgumentAnnotations.java @@ -0,0 +1,193 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import dev.jorel.commandapi.annotations.reloaded.arguments.utils.ArgumentAnnotation; +import dev.jorel.commandapi.annotations.reloaded.arguments.utils.ArgumentAnnotationProperties; +import dev.jorel.commandapi.annotations.reloaded.arguments.utils.ArgumentListedOption; +import dev.jorel.commandapi.annotations.reloaded.arguments.utils.CustomArgumentAnnotationProperties; +import dev.jorel.commandapi.annotations.reloaded.arguments.utils.DoubleArgumentAnnotationProperties; +import dev.jorel.commandapi.annotations.reloaded.arguments.utils.FloatArgumentAnnotationProperties; +import dev.jorel.commandapi.annotations.reloaded.arguments.utils.IntegerArgumentAnnotationProperties; +import dev.jorel.commandapi.annotations.reloaded.arguments.utils.LocationArgumentAnnotationProperties; +import dev.jorel.commandapi.annotations.reloaded.arguments.utils.LongArgumentAnnotationProperties; +import dev.jorel.commandapi.annotations.reloaded.arguments.utils.MultiLiteralArgumentAnnotationProperties; +import dev.jorel.commandapi.annotations.reloaded.arguments.utils.PrimitiveType; +import dev.jorel.commandapi.arguments.AdvancementArgument; +import dev.jorel.commandapi.arguments.AdventureChatArgument; +import dev.jorel.commandapi.arguments.AdventureChatComponentArgument; +import dev.jorel.commandapi.arguments.AngleArgument; +import dev.jorel.commandapi.arguments.AxisArgument; +import dev.jorel.commandapi.arguments.BiomeArgument; +import dev.jorel.commandapi.arguments.BlockPredicateArgument; +import dev.jorel.commandapi.arguments.BlockStateArgument; +import dev.jorel.commandapi.arguments.BooleanArgument; +import dev.jorel.commandapi.arguments.ChatArgument; +import dev.jorel.commandapi.arguments.ChatColorArgument; +import dev.jorel.commandapi.arguments.ChatComponentArgument; +import dev.jorel.commandapi.arguments.CustomArgument; +import dev.jorel.commandapi.arguments.DoubleArgument; +import dev.jorel.commandapi.arguments.EnchantmentArgument; +import dev.jorel.commandapi.arguments.EntitySelectorArgument; +import dev.jorel.commandapi.arguments.EntityTypeArgument; +import dev.jorel.commandapi.arguments.FloatArgument; +import dev.jorel.commandapi.arguments.FloatRangeArgument; +import dev.jorel.commandapi.arguments.FunctionArgument; +import dev.jorel.commandapi.arguments.GreedyStringArgument; +import dev.jorel.commandapi.arguments.IntegerArgument; +import dev.jorel.commandapi.arguments.IntegerRangeArgument; +import dev.jorel.commandapi.arguments.ItemStackArgument; +import dev.jorel.commandapi.arguments.ItemStackPredicateArgument; +import dev.jorel.commandapi.arguments.LiteralArgument; +import dev.jorel.commandapi.arguments.Location2DArgument; +import dev.jorel.commandapi.arguments.LocationArgument; +import dev.jorel.commandapi.arguments.LongArgument; +import dev.jorel.commandapi.arguments.LootTableArgument; +import dev.jorel.commandapi.arguments.MathOperationArgument; +import dev.jorel.commandapi.arguments.MultiLiteralArgument; +import dev.jorel.commandapi.arguments.NBTCompoundArgument; +import dev.jorel.commandapi.arguments.NamespacedKeyArgument; +import dev.jorel.commandapi.arguments.ObjectiveArgument; +import dev.jorel.commandapi.arguments.ObjectiveCriteriaArgument; +import dev.jorel.commandapi.arguments.OfflinePlayerArgument; +import dev.jorel.commandapi.arguments.ParticleArgument; +import dev.jorel.commandapi.arguments.PlayerArgument; +import dev.jorel.commandapi.arguments.PotionEffectArgument; +import dev.jorel.commandapi.arguments.RecipeArgument; +import dev.jorel.commandapi.arguments.RotationArgument; +import dev.jorel.commandapi.arguments.ScoreHolderArgument; +import dev.jorel.commandapi.arguments.ScoreboardSlotArgument; +import dev.jorel.commandapi.arguments.SoundArgument; +import dev.jorel.commandapi.arguments.StringArgument; +import dev.jorel.commandapi.arguments.TeamArgument; +import dev.jorel.commandapi.arguments.TextArgument; +import dev.jorel.commandapi.arguments.TimeArgument; +import dev.jorel.commandapi.arguments.UUIDArgument; +import dev.jorel.commandapi.arguments.WorldArgument; + +import java.lang.annotation.Annotation; +import java.util.LinkedHashSet; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * TODO: This class should be generated automatically + */ +@SuppressWarnings("deprecation") +public class ArgumentAnnotations { + /** + * Using a LinkedHashSet to maintain order. We want to have primitives early + * on in the list so that they are chosen early in predictions + */ + public static final Set> ALL = Stream.of( + AAdvancementArgument.class, AAdventureChatArgument.class, AAdventureChatComponentArgument.class, + AAngleArgument.class, AAxisArgument.class, ABiomeArgument.class, ABlockPredicateArgument.class, + ABlockStateArgument.class, ABooleanArgument.class, AChatArgument.class, AChatColorArgument.class, + AChatComponentArgument.class, ADoubleArgument.class, AEnchantmentArgument.class, + + AEntitySelectorArgument.ManyPlayers.class, + AEntitySelectorArgument.OnePlayer.class, + AEntitySelectorArgument.ManyEntities.class, + AEntitySelectorArgument.OneEntity.class, + + AEntityTypeArgument.class, AFloatArgument.class, AFloatRangeArgument.class, AFunctionArgument.class, + AGreedyStringArgument.class, AIntegerArgument.class, AIntegerRangeArgument.class, + AItemStackArgument.class, AItemStackPredicateArgument.class, ALiteralArgument.class, + ALocation2DArgument.class, ALocationArgument.class, ALongArgument.class, ALootTableArgument.class, + AMathOperationArgument.class, AMultiLiteralArgument.class, ANamespacedKeyArgument.class, + ANBTCompoundArgument.class, AObjectiveArgument.class, AObjectiveCriteriaArgument.class, + AOfflinePlayerArgument.class, AParticleArgument.class, APlayerArgument.class, + APotionEffectArgument.class, ARecipeArgument.class, ARotationArgument.class, + AScoreboardSlotArgument.class, + + AScoreHolderArgument.Single.class, + AScoreHolderArgument.Multiple.class, + + ASoundArgument.class, + AStringArgument.class, ATeamArgument.class, ATextArgument.class, ATimeArgument.class, + AUUIDArgument.class, AWorldArgument.class + ) + .collect(Collectors.toCollection(LinkedHashSet::new)); + + public static ArgumentAnnotation from(Annotation annotation, String nodeName) { + Class type = annotation.annotationType(); + PrimitiveType primitiveType = new PrimitiveType(type.getAnnotation(Primitive.class).value()); + if (annotation instanceof AAdvancementArgument arg) { return new ArgumentAnnotationProperties(type, AdvancementArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AAdventureChatArgument arg) { return new ArgumentAnnotationProperties(type, AdventureChatArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AAdventureChatComponentArgument arg) { return new ArgumentAnnotationProperties(type, AdventureChatComponentArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AAngleArgument arg) { return new ArgumentAnnotationProperties(type, AngleArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AAxisArgument arg) { return new ArgumentAnnotationProperties(type, AxisArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof ABiomeArgument arg) { return new ArgumentAnnotationProperties(type, BiomeArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof ABlockPredicateArgument arg) { return new ArgumentAnnotationProperties(type, BlockPredicateArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof ABlockStateArgument arg) { return new ArgumentAnnotationProperties(type, BlockStateArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof ABooleanArgument arg) { return new ArgumentAnnotationProperties(type, BooleanArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AChatArgument arg) { return new ArgumentAnnotationProperties(type, ChatArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AChatColorArgument arg) { return new ArgumentAnnotationProperties(type, ChatColorArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AChatComponentArgument arg) { return new ArgumentAnnotationProperties(type, ChatComponentArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof ACustomArgument arg) { return new CustomArgumentAnnotationProperties(type, CustomArgument.class, primitiveType, nodeName, arg.optional(), arg.value(), arg.keyed()); + } else if (annotation instanceof ADoubleArgument arg) { return new DoubleArgumentAnnotationProperties(type, DoubleArgument.class, primitiveType, nodeName, arg.optional(), arg.min(), arg.max()); + } else if (annotation instanceof AEnchantmentArgument arg) { return new ArgumentAnnotationProperties(type, EnchantmentArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AEntitySelectorArgument.ManyEntities arg) { return new ArgumentAnnotationProperties(type, EntitySelectorArgument.ManyEntities.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AEntitySelectorArgument.ManyPlayers arg) { return new ArgumentAnnotationProperties(type, EntitySelectorArgument.ManyPlayers.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AEntitySelectorArgument.OneEntity arg) { return new ArgumentAnnotationProperties(type, EntitySelectorArgument.OneEntity.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AEntitySelectorArgument.OnePlayer arg) { return new ArgumentAnnotationProperties(type, EntitySelectorArgument.OnePlayer.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AEntityTypeArgument arg) { return new ArgumentAnnotationProperties(type, EntityTypeArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AFloatArgument arg) { return new FloatArgumentAnnotationProperties(type, FloatArgument.class, primitiveType, nodeName, arg.optional(), arg.min(), arg.max()); + } else if (annotation instanceof AFloatRangeArgument arg) { return new ArgumentAnnotationProperties(type, FloatRangeArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AFunctionArgument arg) { return new ArgumentAnnotationProperties(type, FunctionArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AGreedyStringArgument arg) { return new ArgumentAnnotationProperties(type, GreedyStringArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AIntegerArgument arg) { return new IntegerArgumentAnnotationProperties(type, IntegerArgument.class, primitiveType, nodeName, arg.optional(), arg.min(), arg.max()); + } else if (annotation instanceof AIntegerRangeArgument arg) { return new ArgumentAnnotationProperties(type, IntegerRangeArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AItemStackArgument arg) { return new ArgumentAnnotationProperties(type, ItemStackArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AItemStackPredicateArgument arg) { return new ArgumentAnnotationProperties(type, ItemStackPredicateArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof ALiteralArgument arg) { return new ArgumentAnnotationProperties(type, LiteralArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof ALocation2DArgument arg) { return new LocationArgumentAnnotationProperties(type, Location2DArgument.class, primitiveType, nodeName, arg.optional(), arg.value()); + } else if (annotation instanceof ALocationArgument arg) { return new LocationArgumentAnnotationProperties(type, LocationArgument.class, primitiveType, nodeName, arg.optional(), arg.value()); + } else if (annotation instanceof ALongArgument arg) { return new LongArgumentAnnotationProperties(type, LongArgument.class, primitiveType, nodeName, arg.optional(), arg.min(), arg.max()); + } else if (annotation instanceof ALootTableArgument arg) { return new ArgumentAnnotationProperties(type, LootTableArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AMathOperationArgument arg) { return new ArgumentAnnotationProperties(type, MathOperationArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AMultiLiteralArgument arg) { return new MultiLiteralArgumentAnnotationProperties(type, MultiLiteralArgument.class, primitiveType, nodeName, ArgumentListedOption.DEFAULT, arg.optional(), arg.value()); + } else if (annotation instanceof ANBTCompoundArgument arg) { return new ArgumentAnnotationProperties(type, NBTCompoundArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof ANamespacedKeyArgument arg) { return new ArgumentAnnotationProperties(type, NamespacedKeyArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AObjectiveArgument arg) { return new ArgumentAnnotationProperties(type, ObjectiveArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AObjectiveCriteriaArgument arg) { return new ArgumentAnnotationProperties(type, ObjectiveCriteriaArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AOfflinePlayerArgument arg) { return new ArgumentAnnotationProperties(type, OfflinePlayerArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AParticleArgument arg) { return new ArgumentAnnotationProperties(type, ParticleArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof APlayerArgument arg) { return new ArgumentAnnotationProperties(type, PlayerArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof APotionEffectArgument arg) { return new ArgumentAnnotationProperties(type, PotionEffectArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof ARecipeArgument arg) { return new ArgumentAnnotationProperties(type, RecipeArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof ARotationArgument arg) { return new ArgumentAnnotationProperties(type, RotationArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AScoreHolderArgument.Multiple arg) { return new ArgumentAnnotationProperties(type, ScoreHolderArgument.Multiple.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AScoreHolderArgument.Single arg) { return new ArgumentAnnotationProperties(type, ScoreHolderArgument.Single.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AScoreboardSlotArgument arg) { return new ArgumentAnnotationProperties(type, ScoreboardSlotArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof ASoundArgument arg) { return new ArgumentAnnotationProperties(type, SoundArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AStringArgument arg) { return new ArgumentAnnotationProperties(type, StringArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof ATeamArgument arg) { return new ArgumentAnnotationProperties(type, TeamArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof ATextArgument arg) { return new ArgumentAnnotationProperties(type, TextArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof ATimeArgument arg) { return new ArgumentAnnotationProperties(type, TimeArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AUUIDArgument arg) { return new ArgumentAnnotationProperties(type, UUIDArgument.class, primitiveType, nodeName, arg.optional()); + } else if (annotation instanceof AWorldArgument arg) { return new ArgumentAnnotationProperties(type, WorldArgument.class, primitiveType, nodeName, arg.optional()); + } + throw new IllegalArgumentException("%s is not a %s" + .formatted(annotation, ArgumentAnnotation.class)); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/Primitive.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/Primitive.java new file mode 100644 index 0000000000..f766c1d825 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/Primitive.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Tells the annotation processor that this primitive argument's casting type is + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface Primitive { + + /** + * @return The class or classes that this argument represents. This should be fully qualified (with dots) and + * include any generics (also fully qualified) + */ + String[] value(); + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/package-info.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/package-info.java new file mode 100644 index 0000000000..0b86ec871b --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/package-info.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright 2018, 2023 Jorel Ali (Skepter) - MIT License + * + * 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. + *******************************************************************************/ +/** + * Argument annotations which can be used with the CommandAPI annotation system. + */ +package dev.jorel.commandapi.annotations.reloaded.arguments; \ No newline at end of file diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/ArgumentAnnotation.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/ArgumentAnnotation.java new file mode 100644 index 0000000000..54e4441b96 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/ArgumentAnnotation.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments.utils; + +import dev.jorel.commandapi.arguments.Argument; + +import java.lang.annotation.Annotation; +import java.util.List; + +/** + * An interface that applies to all argument annotation classes + */ +public interface ArgumentAnnotation { + /** + * @return The class of the annotation this mirrors + */ + Class annotationType(); + + /** + * @return The class of the argument this uses + */ + @SuppressWarnings("rawtypes") + Class argumentType(); + + /** + * @return The variable types this argument parses to + */ + PrimitiveType primitiveType(); + + /** + * @return The name of the command node and the variable this annotation is attached to + */ + String nodeName(); + + /** + * @return Whether this argument should be marked as an optional argument + */ + boolean optional(); + + /** + * @return True, if this argument should be listed in the Object args[] of the command executor + */ + default ArgumentListedOption listed() { + return ArgumentListedOption.DEFAULT; + } + + /** + * @return The serialized arguments to be passed to the constructor + */ + default List constructorParameters() { + return List.of(nodeName()); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/ArgumentAnnotationProperties.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/ArgumentAnnotationProperties.java new file mode 100644 index 0000000000..72da510eef --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/ArgumentAnnotationProperties.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments.utils; + +import dev.jorel.commandapi.arguments.Argument; + +import java.lang.annotation.Annotation; + +/** + * A set of properties that all argument annotations share + */ +@SuppressWarnings("rawtypes") +public record ArgumentAnnotationProperties( + Class annotationType, + Class argumentType, + PrimitiveType primitiveType, + String nodeName, + @ArgumentAnnotationProperty("whether this argument should be marked as an optional argument") + @ArgumentAnnotationProperty.Default("false") + boolean optional +) implements ArgumentAnnotation { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/ArgumentAnnotationProperty.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/ArgumentAnnotationProperty.java new file mode 100644 index 0000000000..45c1a2b1fc --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/ArgumentAnnotationProperty.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments.utils; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + + +/** + * The annotation to indicate that this record component mirrors the property of an argument annotation + *

+ * TODO: This really belongs in an annotation processor to automatically build the set of argument annotations + */ +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.RECORD_COMPONENT}) +public @interface ArgumentAnnotationProperty { + /** + * @return The javadoc for the auto-generated annotation property + */ + String value(); + + /** + * The annotation for the default value of this annotation property + */ + @Retention(RetentionPolicy.SOURCE) + @Target({ElementType.RECORD_COMPONENT}) + @interface Default { + String value(); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/ArgumentListedOption.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/ArgumentListedOption.java new file mode 100644 index 0000000000..d339ac96c2 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/ArgumentListedOption.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments.utils; + +/** + * Determines whether this argument should be listed in the arguments during command execution + */ +public enum ArgumentListedOption { + /** + * Use the default value for this type of argument. E.g. literal arguments aren't listed but most others are + */ + DEFAULT, + /** + * Make this argument listed in the command arguments regardless of what it normally is + */ + OVERRIDE_TRUE, + /** + * Do not list this argument in the command arguments regardless of what it normally is + */ + OVERRIDE_FALSE +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/CustomArgumentAnnotation.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/CustomArgumentAnnotation.java new file mode 100644 index 0000000000..9bae01030c --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/CustomArgumentAnnotation.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments.utils; + +import dev.jorel.commandapi.arguments.CustomArgument; + +/** + * An interface that applies to custom argument annotation classes + */ +public interface CustomArgumentAnnotation extends ArgumentAnnotation { + /** + * @return The class that parses the custom argument info + */ + Class> value(); + + /** + * @return Whether this custom argument uses a NamespaceKeyedArgument as the base + */ + boolean keyed(); +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/CustomArgumentAnnotationProperties.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/CustomArgumentAnnotationProperties.java new file mode 100644 index 0000000000..329c59be18 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/CustomArgumentAnnotationProperties.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments.utils; + +import dev.jorel.commandapi.arguments.Argument; +import dev.jorel.commandapi.arguments.CustomArgument; + +import java.lang.annotation.Annotation; + +/** + * A set of properties that apply to all custom argument annotations + */ +@SuppressWarnings("rawtypes") +public record CustomArgumentAnnotationProperties( + Class annotationType, + Class argumentType, + PrimitiveType primitiveType, + String nodeName, + boolean optional, + Class> value, + boolean keyed +) implements CustomArgumentAnnotation { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/DoubleArgumentAnnotation.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/DoubleArgumentAnnotation.java new file mode 100644 index 0000000000..88603dffe3 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/DoubleArgumentAnnotation.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments.utils; + +import java.util.List; + +/** + * An interface that applies to all double-precision floating point argument annotations + */ +public interface DoubleArgumentAnnotation extends ArgumentAnnotation { + /** + * @return The minimum value this argument can take (inclusive) + */ + double min(); + + /** + * @return The maximum value this argument can take (inclusive) + */ + double max(); + + @Override + default List constructorParameters() { + return List.of(nodeName(), min(), max()); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/DoubleArgumentAnnotationProperties.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/DoubleArgumentAnnotationProperties.java new file mode 100644 index 0000000000..c74a42af69 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/DoubleArgumentAnnotationProperties.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments.utils; + +import dev.jorel.commandapi.arguments.Argument; + +import java.lang.annotation.Annotation; + +/** + * A set of properties that all double-precision floating-point argument annotations share + */ +@SuppressWarnings("rawtypes") +public record DoubleArgumentAnnotationProperties( + Class annotationType, + Class argumentType, + PrimitiveType primitiveType, + String nodeName, + boolean optional, + double min, + double max +) implements DoubleArgumentAnnotation { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/FloatArgumentAnnotation.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/FloatArgumentAnnotation.java new file mode 100644 index 0000000000..b6acee1ebd --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/FloatArgumentAnnotation.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments.utils; + +import java.util.List; + +/** + * An interface that applies to all single-precision floating point argument annotations + */ +public interface FloatArgumentAnnotation extends ArgumentAnnotation { + /** + * @return The minimum value this argument can take (inclusive) + */ + float min(); + + /** + * @return The maximum value this argument can take (inclusive) + */ + float max(); + + @Override + default List constructorParameters() { + return List.of(nodeName(), min(), max()); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/FloatArgumentAnnotationProperties.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/FloatArgumentAnnotationProperties.java new file mode 100644 index 0000000000..20cb7f3a0d --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/FloatArgumentAnnotationProperties.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments.utils; + +import dev.jorel.commandapi.arguments.Argument; + +import java.lang.annotation.Annotation; + +/** + * A set of properties that all single-precision floating-point argument annotations share + */ +@SuppressWarnings("rawtypes") +public record FloatArgumentAnnotationProperties( + Class annotationType, + Class argumentType, + PrimitiveType primitiveType, + String nodeName, + boolean optional, + float min, + float max +) implements FloatArgumentAnnotation { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/IntegerArgumentAnnotation.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/IntegerArgumentAnnotation.java new file mode 100644 index 0000000000..650ab379ae --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/IntegerArgumentAnnotation.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments.utils; + +import java.util.List; + +/** + * An interface that applies to all integer argument annotation types + */ +public interface IntegerArgumentAnnotation extends ArgumentAnnotation { + /** + * @return The minimum value this argument can take (inclusive) + */ + int min(); + + /** + * @return The maximum value this argument can take (inclusive) + */ + int max(); + + @Override + default List constructorParameters() { + return List.of(nodeName(), min(), max()); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/IntegerArgumentAnnotationProperties.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/IntegerArgumentAnnotationProperties.java new file mode 100644 index 0000000000..ec180f114a --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/IntegerArgumentAnnotationProperties.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments.utils; + +import dev.jorel.commandapi.arguments.Argument; + +import java.lang.annotation.Annotation; + +/** + * A set of properties that all integer argument annotations share + */ +@SuppressWarnings("rawtypes") +public record IntegerArgumentAnnotationProperties( + Class annotationType, + Class argumentType, + PrimitiveType primitiveType, + String nodeName, + boolean optional, + int min, + int max +) implements IntegerArgumentAnnotation { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/LiteralArgumentAnnotation.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/LiteralArgumentAnnotation.java new file mode 100644 index 0000000000..d2e30eac4f --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/LiteralArgumentAnnotation.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments.utils; + +import java.util.List; + +/** + * An interface that applies to all literal argument annotation types + */ +public interface LiteralArgumentAnnotation extends ArgumentAnnotation { + /** + * @return the string literal that this argument will represent + */ + String value(); + + @Override + default List constructorParameters() { + return List.of(value()); + } + + @Override + default ArgumentListedOption listed() { + return ArgumentListedOption.OVERRIDE_TRUE; + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/LiteralArgumentAnnotationProperties.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/LiteralArgumentAnnotationProperties.java new file mode 100644 index 0000000000..0a60a4d3e3 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/LiteralArgumentAnnotationProperties.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments.utils; + +import dev.jorel.commandapi.arguments.Argument; + +import java.lang.annotation.Annotation; + +/** + * A set of properties that all literal argument annotations share + */ +@SuppressWarnings("rawtypes") +public record LiteralArgumentAnnotationProperties( + Class annotationType, + Class argumentType, + PrimitiveType primitiveType, + String nodeName, + boolean optional, + String value +) implements LiteralArgumentAnnotation { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/LocationArgumentAnnotation.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/LocationArgumentAnnotation.java new file mode 100644 index 0000000000..9610460d34 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/LocationArgumentAnnotation.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments.utils; + +import dev.jorel.commandapi.arguments.LocationType; + +import java.util.List; + +/** + * An interface that applies to all location argument + */ +public interface LocationArgumentAnnotation extends ArgumentAnnotation { + /** + * @return the location type of this location, either + * {@link LocationType#BLOCK_POSITION} or + * {@link LocationType#PRECISE_POSITION}. Defaults to + * {@link LocationType#PRECISE_POSITION} + */ + LocationType value(); + + @Override + default List constructorParameters() { + return List.of(nodeName(), value()); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/LocationArgumentAnnotationProperties.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/LocationArgumentAnnotationProperties.java new file mode 100644 index 0000000000..f618e98e33 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/LocationArgumentAnnotationProperties.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments.utils; + +import dev.jorel.commandapi.arguments.Argument; +import dev.jorel.commandapi.arguments.LocationType; + +import java.lang.annotation.Annotation; + +public record LocationArgumentAnnotationProperties( + Class annotationType, + Class argumentType, + PrimitiveType primitiveType, + String nodeName, + boolean optional, + LocationType value +) implements LocationArgumentAnnotation { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/LongArgumentAnnotation.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/LongArgumentAnnotation.java new file mode 100644 index 0000000000..86cbc0288e --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/LongArgumentAnnotation.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments.utils; + +import java.util.List; + +/** + * An interface that applies to all long-integer argument annotations + */ +public interface LongArgumentAnnotation extends ArgumentAnnotation { + /** + * @return The minimum value this argument can take (inclusive) + */ + long min(); + + /** + * @return The maximum value this argument can take (inclusive) + */ + long max(); + + @Override + default List constructorParameters() { + return List.of(nodeName(), min(), max()); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/LongArgumentAnnotationProperties.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/LongArgumentAnnotationProperties.java new file mode 100644 index 0000000000..8b2ca9482e --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/LongArgumentAnnotationProperties.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments.utils; + +import dev.jorel.commandapi.arguments.Argument; + +import java.lang.annotation.Annotation; + +/** + * A set of properties that all long-integer argument annotations share + */ +@SuppressWarnings("rawtypes") +public record LongArgumentAnnotationProperties( + Class annotationType, + Class argumentType, + PrimitiveType primitiveType, + String nodeName, + boolean optional, + long min, + long max +) implements LongArgumentAnnotation { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/MultiLiteralArgumentAnnotation.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/MultiLiteralArgumentAnnotation.java new file mode 100644 index 0000000000..763ba4b91b --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/MultiLiteralArgumentAnnotation.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments.utils; + +import java.util.Arrays; +import java.util.List; + +/** + * An interface that applies to all multi-literal argument annotations + */ +public interface MultiLiteralArgumentAnnotation extends ArgumentAnnotation { + /** + * @return The literals that this argument represents + */ + String[] values(); + + @Override + default List constructorParameters() { + return Arrays.asList(values()); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/MultiLiteralArgumentAnnotationProperties.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/MultiLiteralArgumentAnnotationProperties.java new file mode 100644 index 0000000000..87c01f0c3f --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/MultiLiteralArgumentAnnotationProperties.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments.utils; + +import dev.jorel.commandapi.arguments.Argument; + +import java.lang.annotation.Annotation; + +/** + * A set of properties that all multi-literal argument annotations share + */ +@SuppressWarnings("rawtypes") +public record MultiLiteralArgumentAnnotationProperties( + Class annotationType, + Class argumentType, + PrimitiveType primitiveType, + String nodeName, + ArgumentListedOption listed, + boolean optional, + String[] values +) implements MultiLiteralArgumentAnnotation { + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/PrimitiveType.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/PrimitiveType.java new file mode 100644 index 0000000000..561db20f51 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/PrimitiveType.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments.utils; + +/** + * @param values The variable types an argument parses to + */ +public record PrimitiveType(String... values) { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/SuggestionsType.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/SuggestionsType.java new file mode 100644 index 0000000000..cf48237282 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/SuggestionsType.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.arguments.utils; + +import dev.jorel.commandapi.arguments.ArgumentSuggestions; +import dev.jorel.commandapi.arguments.SafeSuggestions; + +/** + * Indicates the type of suggestions attached to an argument + */ +public enum SuggestionsType { + /** + * No suggestions. Uses the built-in defaults + */ + NONE, + /** + * Uses {@link dev.jorel.commandapi.arguments.SafeOverrideable#replaceSuggestions(ArgumentSuggestions)} + */ + NORMAL, + /** + * Uses {@link dev.jorel.commandapi.arguments.SafeOverrideable#replaceSafeSuggestions(SafeSuggestions)} + */ + SAFE +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/package-info.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/package-info.java new file mode 100644 index 0000000000..666572d2b8 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/arguments/utils/package-info.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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. + *******************************************************************************/ +/** + * A set of utilities for working with CommandAPI argument annotations. + */ +@ParametersAreNonnullByDefault +@ReturnTypesAreNonnullByDefault +package dev.jorel.commandapi.annotations.reloaded.arguments.utils; + +import javax.annotation.ParametersAreNonnullByDefault; +import dev.jorel.commandapi.annotations.reloaded.ReturnTypesAreNonnullByDefault; \ No newline at end of file diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/generators/CodeGenerator.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/generators/CodeGenerator.java new file mode 100644 index 0000000000..f9fe7e15ff --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/generators/CodeGenerator.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.generators; + +/** + * Interface for classes that generate code + * + * @param The contextual information available to the generator + */ +public interface CodeGenerator { + /** + * @param out Where the generated code should be output to + * @param context The contextual information needed to generate the code + */ + void generate(IndentedWriter out, AContext context); +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/generators/ConstructorClassNameRenderer.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/generators/ConstructorClassNameRenderer.java new file mode 100644 index 0000000000..7a60ebaf64 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/generators/ConstructorClassNameRenderer.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.generators; + +/** + * Renders class names for use in Java class construction statements + */ +public class ConstructorClassNameRenderer implements Renderer> { + + @Override + public String render(Class clazz) { + Class nestHost = clazz.getNestHost(); + if (clazz != nestHost) { + return "%s.%s".formatted(render(nestHost), clazz.getSimpleName()); + } else { + return clazz.getSimpleName(); + } + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/generators/GeneratorContext.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/generators/GeneratorContext.java new file mode 100644 index 0000000000..cee0238467 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/generators/GeneratorContext.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.generators; + +/** + * An interface for all {@link CodeGenerator} contexts + */ +public interface GeneratorContext { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/generators/IndentedWriter.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/generators/IndentedWriter.java new file mode 100644 index 0000000000..c47ba12c2d --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/generators/IndentedWriter.java @@ -0,0 +1,143 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.generators; + +import java.io.IOException; +import java.io.StringWriter; +import java.io.Writer; +import java.util.function.Consumer; + +/** + * A writer for outputting indented lines of code + */ +public class IndentedWriter { + /** + * The underlying writer to output to + */ + private final Writer out; + /** + * The prefix to indent each line with + */ + private final String prefix; + + /** + * @see #IndentedWriter(Writer, String) + */ + public IndentedWriter(Writer out) { + this(out, ""); + } + + /** + * @param out The underlying writer that should be output to + * @param prefix The initial prefix to indent this code with + */ + public IndentedWriter(Writer out, String prefix) { + this.out = out; + this.prefix = prefix; + } + + /** + * Writes directly to the underlying writer. Any {@link IOException} are rethrown unchecked. It is assumed that + * compilation should halt if this occurs. + * + * @param text Text to output to the underlying writer + */ + private void uncheckedWrite(String text) { + try { + out.write(text); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + /** + * Writes a single new-line character to the output. This is intended for creating empty, non-indented lines in the + * generated code. + */ + public void printEmptyLine() { + uncheckedWrite("\n"); + } + + /** + * Writes a new-line character, followed by the current prefix. This is intended for starting a new indented line + * in the generated code. + */ + public void startNewLine() { + uncheckedWrite("\n%s".formatted(prefix)); + } + + /** + * Writes a new-line character, followed by the current prefix, then the given text. This is intended for writing + * a whole line in the generated code. + * + * @param line The text to write on a new line + */ + public void printOnNewLine(String line) { + startNewLine(); + uncheckedWrite(line); + } + + /** + * Writes the given text directly to the output. This is intended for apprending text to the end of the current + * line of code. + * + * @param text The text to append + */ + public void appendInLine(String text) { + uncheckedWrite(text); + } + + /** + * Write output to a buffer rather than the output writer. This is intended for situations where you need to do + * something with the text before it gets written to the output. + * + * @param withWriter Provides a new writer that outputs to a buffer rather than the output writer + * @return The buffered text + */ + public String buffer(Consumer withWriter) { + StringWriter buffer = new StringWriter(); + withWriter.accept(new IndentedWriter(buffer, prefix)); + return buffer.toString(); + } + + /** + * Write something with increased indentation. + * + * @param withWriter Provides a new writer with the indentation increased by one tab character + */ + public void indent(Consumer withWriter) { + withWriter.accept(new IndentedWriter(out, prefix + "\t")); + } + + /** + * This is a combination of both {@link #buffer(Consumer)} and {@link #indent(Consumer)} at the same time. + * + * @param withWriter Provides a new writer that outputs to a buffer and increments the prefix by one tab + * @return The buffered text + * @see #buffer(Consumer) + * @see #indent(Consumer) + */ + public String indentToBuffer(Consumer withWriter) { + StringWriter buffer = new StringWriter(); + withWriter.accept(new IndentedWriter(buffer, prefix + "\t")); + return buffer.toString(); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/generators/InvocationParametersRenderer.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/generators/InvocationParametersRenderer.java new file mode 100644 index 0000000000..03e2a31a62 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/generators/InvocationParametersRenderer.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.generators; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * This renders the parameters list for a Java method invocation + */ +public class InvocationParametersRenderer implements Renderer> { + + private final LiteralValueRenderer literalValueRenderer; + + public InvocationParametersRenderer() { + this(new LiteralValueRenderer()); + } + + public InvocationParametersRenderer(LiteralValueRenderer literalValueRenderer) { + this.literalValueRenderer = literalValueRenderer; + } + + @Override + public String render(List parameters) { + return parameters.stream() + .map(literalValueRenderer::render) + .collect(Collectors.joining(", ")); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/generators/LiteralValueRenderer.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/generators/LiteralValueRenderer.java new file mode 100644 index 0000000000..27c43746b0 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/generators/LiteralValueRenderer.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.generators; + +/** + * Renders Java literal values + */ +public class LiteralValueRenderer implements Renderer { + private final ConstructorClassNameRenderer constructorClassNameRenderer; + + public LiteralValueRenderer() { + this(new ConstructorClassNameRenderer()); + } + + public LiteralValueRenderer(ConstructorClassNameRenderer constructorClassNameRenderer) { + this.constructorClassNameRenderer = constructorClassNameRenderer; + } + + @Override + public String render(Object obj) { + if (obj instanceof Byte val) { + return "%d".formatted(val); + } else if (obj instanceof Short val) { + return "%d".formatted(val); + } else if (obj instanceof Integer val) { + return "%d".formatted(val); + } else if (obj instanceof Long val) { + return "%dL".formatted(val); + } else if (obj instanceof Float val) { + return "%fF".formatted(val); + } else if (obj instanceof Double val) { + return "%fD".formatted(val); + } else if (obj instanceof Character val) { + return "'%c'".formatted(val); + } else if (obj instanceof String val) { + return "\"%s\"".formatted(val); + } else if (obj instanceof Boolean val) { + return "%b".formatted(val); + } else if (obj instanceof Enum val) { + return "%s.%s".formatted(val.getDeclaringClass().getSimpleName(), val.name()); + } else if (obj instanceof Class val) { + return constructorClassNameRenderer.render(val); + } else { + return "%s".formatted(obj); + } + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/generators/Renderer.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/generators/Renderer.java new file mode 100644 index 0000000000..f0cbdc3b0f --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/generators/Renderer.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.generators; + +/** + * An interface for text renderers + * + * @param Contextual information needed to render the text + */ +public interface Renderer { + /** + * @param context The context needed to render the text + * @return The rendered text + */ + String render(RenderingContext context); +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/generators/package-info.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/generators/package-info.java new file mode 100644 index 0000000000..6a266255be --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/generators/package-info.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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. + *******************************************************************************/ +/** + * Code generators used in the CommandAPI annotation system. + */ +@ParametersAreNonnullByDefault +@ReturnTypesAreNonnullByDefault +package dev.jorel.commandapi.annotations.reloaded.generators; + +import javax.annotation.ParametersAreNonnullByDefault; +import dev.jorel.commandapi.annotations.reloaded.ReturnTypesAreNonnullByDefault; \ No newline at end of file diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/AnalyzerParserGeneratorModule.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/AnalyzerParserGeneratorModule.java new file mode 100644 index 0000000000..da043377cb --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/AnalyzerParserGeneratorModule.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules; + +import dev.jorel.commandapi.annotations.reloaded.generators.CodeGenerator; +import dev.jorel.commandapi.annotations.reloaded.generators.GeneratorContext; +import dev.jorel.commandapi.annotations.reloaded.parser.AnnotationParser; +import dev.jorel.commandapi.annotations.reloaded.parser.AnnotationParserContext; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticAnalyzer; + +import javax.lang.model.element.Element; + +/** + * A module for containing a discrete feature of the annotation system. + * + * @param The element that the relevant CommandAPI annotation is applied to + * @param Context needed to parse all data for this feature + * @param Context needed to generate all needed code for this feature + */ +public interface AnalyzerParserGeneratorModule< + AnElement extends Element, + AParserContext extends AnnotationParserContext, + AGeneratorContext extends GeneratorContext + > extends + SemanticAnalyzer, + AnnotationParser, + CodeGenerator { + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/ExecutableElementAnalyzerParserGeneratorModule.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/ExecutableElementAnalyzerParserGeneratorModule.java new file mode 100644 index 0000000000..73c328fda9 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/ExecutableElementAnalyzerParserGeneratorModule.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules; + +import dev.jorel.commandapi.annotations.reloaded.generators.GeneratorContext; +import dev.jorel.commandapi.annotations.reloaded.parser.ExecutableElementParserContext; + +import javax.lang.model.element.ExecutableElement; + +/** + * A convenience interface for {@link AnalyzerParserGeneratorModule} for annotations that are applied to executable + * elements such as methods. + */ +public interface ExecutableElementAnalyzerParserGeneratorModule< + AGeneratorContext extends GeneratorContext + > extends AnalyzerParserGeneratorModule { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/TypeElementAnalyzerParserGeneratorModule.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/TypeElementAnalyzerParserGeneratorModule.java new file mode 100644 index 0000000000..6ae4970f14 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/TypeElementAnalyzerParserGeneratorModule.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules; + +import dev.jorel.commandapi.annotations.reloaded.generators.GeneratorContext; +import dev.jorel.commandapi.annotations.reloaded.parser.TypeElementParserContext; + +import javax.lang.model.element.TypeElement; + +/** + * A convenience interface for {@link AnalyzerParserGeneratorModule} for annotations that are applied to type + * elements such as classes. + */ +public interface TypeElementAnalyzerParserGeneratorModule< + AGeneratorContext extends GeneratorContext + > extends AnalyzerParserGeneratorModule { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/VariableElementAnalyzerParserGeneratorModule.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/VariableElementAnalyzerParserGeneratorModule.java new file mode 100644 index 0000000000..d2fe41f150 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/VariableElementAnalyzerParserGeneratorModule.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules; + +import dev.jorel.commandapi.annotations.reloaded.generators.GeneratorContext; +import dev.jorel.commandapi.annotations.reloaded.parser.VariableElementParserContext; + +import javax.lang.model.element.VariableElement; + +/** + * A convenience interface for {@link AnalyzerParserGeneratorModule} for annotations that are applied to variable + * elements such as fields. + */ +public interface VariableElementAnalyzerParserGeneratorModule< + AGeneratorContext extends GeneratorContext + > extends AnalyzerParserGeneratorModule { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/ArgumentGeneratorContext.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/ArgumentGeneratorContext.java new file mode 100644 index 0000000000..5dfa629081 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/ArgumentGeneratorContext.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.arguments; + +import dev.jorel.commandapi.annotations.reloaded.arguments.utils.ArgumentAnnotation; +import dev.jorel.commandapi.annotations.reloaded.generators.GeneratorContext; +import dev.jorel.commandapi.annotations.reloaded.modules.arguments.listed.ArgumentListedOptionGeneratorContext; +import dev.jorel.commandapi.annotations.reloaded.modules.arguments.permissions.ArgumentPermissionGeneratorContext; +import dev.jorel.commandapi.annotations.reloaded.modules.arguments.requirements.ArgumentRequirementsGeneratorContext; +import dev.jorel.commandapi.annotations.reloaded.modules.arguments.suggestions.ArgumentSuggestionsGeneratorContext; + +import javax.lang.model.element.Element; + +/** + * Context needed to generate a CommandAPI argument + * + * @param element The argument field or parameter + * @param argumentAnnotation The CommandAPI argument annotation properties assigned to this argument + * @param argumentPermissionGeneratorContext Context needed to generate the permissions option + * @param argumentRequirementsGeneratorContext Context needed to generate the requirements option + * @param argumentSuggestionsGeneratorContext Context needed to generate the suggestions option + * @param argumentListedOptionGeneratorContext Context needed to generate the listed option + */ +public record ArgumentGeneratorContext( + Element element, + ArgumentAnnotation argumentAnnotation, + ArgumentPermissionGeneratorContext argumentPermissionGeneratorContext, + ArgumentRequirementsGeneratorContext argumentRequirementsGeneratorContext, + ArgumentSuggestionsGeneratorContext argumentSuggestionsGeneratorContext, + ArgumentListedOptionGeneratorContext argumentListedOptionGeneratorContext +) implements GeneratorContext { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/ArgumentModule.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/ArgumentModule.java new file mode 100644 index 0000000000..39e098319a --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/ArgumentModule.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.arguments; + +import dev.jorel.commandapi.annotations.reloaded.arguments.utils.ArgumentAnnotation; +import dev.jorel.commandapi.annotations.reloaded.generators.InvocationParametersRenderer; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticAnalyzer; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRule; +import dev.jorel.commandapi.annotations.reloaded.generators.ConstructorClassNameRenderer; +import dev.jorel.commandapi.annotations.reloaded.generators.IndentedWriter; +import dev.jorel.commandapi.annotations.reloaded.modules.VariableElementAnalyzerParserGeneratorModule; +import dev.jorel.commandapi.annotations.reloaded.modules.arguments.listed.ArgumentListedOptionGenerator; +import dev.jorel.commandapi.annotations.reloaded.modules.arguments.permissions.ArgumentPermissionsModule; +import dev.jorel.commandapi.annotations.reloaded.modules.arguments.requirements.ArgumentRequirementsModule; +import dev.jorel.commandapi.annotations.reloaded.modules.arguments.suggestions.ArgumentSuggestionsModule; +import dev.jorel.commandapi.annotations.reloaded.parser.VariableElementParserContext; + +import java.util.List; +import java.util.Optional; + +/** + * Contains everything to do with generating CommandAPI arguments + */ +public class ArgumentModule implements VariableElementAnalyzerParserGeneratorModule< + ArgumentGeneratorContext + > { + + private final ConstructorClassNameRenderer constructorClassNameRenderer; + private final InvocationParametersRenderer invocationParametersRenderer; + private final ArgumentListedOptionGenerator listedOptionGenerator; + private final ArgumentPermissionsModule permissionsModule; + private final ArgumentRequirementsModule requirementsModule; + private final ArgumentSuggestionsModule suggestionsModule; + + public ArgumentModule( + ConstructorClassNameRenderer constructorClassNameRenderer, + InvocationParametersRenderer invocationParametersRenderer, + ArgumentListedOptionGenerator listedOptionGenerator, + ArgumentPermissionsModule permissionsModule, + ArgumentRequirementsModule requirementsModule, + ArgumentSuggestionsModule suggestionsModule + ) { + this.constructorClassNameRenderer = constructorClassNameRenderer; + this.invocationParametersRenderer = invocationParametersRenderer; + this.listedOptionGenerator = listedOptionGenerator; + this.permissionsModule = permissionsModule; + this.requirementsModule = requirementsModule; + this.suggestionsModule = suggestionsModule; + } + + @Override + public void generate(IndentedWriter out, ArgumentGeneratorContext context) { + ArgumentAnnotation argumentAnnotation = context.argumentAnnotation(); + String options = out.indentToBuffer(buffer -> { + suggestionsModule.generate(buffer, context.argumentSuggestionsGeneratorContext()); + permissionsModule.generate(buffer, context.argumentPermissionGeneratorContext()); + requirementsModule.generate(buffer, context.argumentRequirementsGeneratorContext()); + listedOptionGenerator.generate(buffer, context.argumentListedOptionGeneratorContext()); + }); + out.printOnNewLine(".%s(new %s(%s)%s".formatted( + argumentAnnotation.optional() ? "withOptionalArguments" : "withArguments", + constructorClassNameRenderer.render(argumentAnnotation.argumentType()), + invocationParametersRenderer.render(argumentAnnotation.constructorParameters()), + options + )); + if (options.isEmpty()) { + out.appendInLine(")"); + } else { + out.printOnNewLine(")"); + } + } + + @Override + public Optional parse(VariableElementParserContext context) { + throw new UnsupportedOperationException("%s: Parsing not yet implemented".formatted(context.element())); + } + + @Override + public List subAnalyzers() { + return List.of( + permissionsModule, + requirementsModule, + suggestionsModule + ); + } + + @Override + public List rules() { + return List.of(); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/CommandExecutorMethodArgumentsGeneratorContext.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/CommandExecutorMethodArgumentsGeneratorContext.java new file mode 100644 index 0000000000..7dee58cc8e --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/CommandExecutorMethodArgumentsGeneratorContext.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.arguments; + +import dev.jorel.commandapi.annotations.reloaded.generators.GeneratorContext; + +/** + * The context needed to generate the arguments option of a CommandAPI command + */ +public record CommandExecutorMethodArgumentsGeneratorContext( + //TODO +) implements GeneratorContext { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/CommandExecutorMethodArgumentsModule.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/CommandExecutorMethodArgumentsModule.java new file mode 100644 index 0000000000..ebe91b1d73 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/CommandExecutorMethodArgumentsModule.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.arguments; + +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticAnalyzer; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRule; +import dev.jorel.commandapi.annotations.reloaded.generators.IndentedWriter; +import dev.jorel.commandapi.annotations.reloaded.modules.ExecutableElementAnalyzerParserGeneratorModule; +import dev.jorel.commandapi.annotations.reloaded.parser.ExecutableElementParserContext; + +import java.util.List; +import java.util.Optional; + +/** + * Contains everything to do with generating the arguments option for a CommandAPI command + */ +public class CommandExecutorMethodArgumentsModule implements ExecutableElementAnalyzerParserGeneratorModule { + + @Override + public Optional parse(ExecutableElementParserContext context) { + return Optional.of(new CommandExecutorMethodArgumentsGeneratorContext()); //TODO + } + + @Override + public void generate(IndentedWriter out, CommandExecutorMethodArgumentsGeneratorContext context) { + //TODO + } + + @Override + public List subAnalyzers() { + return List.of(); + } + + @Override + public List rules() { + return List.of(); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/listed/ArgumentListedOptionGenerator.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/listed/ArgumentListedOptionGenerator.java new file mode 100644 index 0000000000..ee23d2e42d --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/listed/ArgumentListedOptionGenerator.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.arguments.listed; + +import dev.jorel.commandapi.annotations.reloaded.generators.CodeGenerator; +import dev.jorel.commandapi.annotations.reloaded.generators.IndentedWriter; + +/** + * Generates the listed option for CommandAPI arguments + */ +public class ArgumentListedOptionGenerator implements CodeGenerator { + @Override + public void generate(IndentedWriter out, ArgumentListedOptionGeneratorContext context) { + switch (context.listedOption()) { + case OVERRIDE_TRUE -> out.printOnNewLine(".setListed(true)"); + case OVERRIDE_FALSE -> out.printOnNewLine(".setListed(false)"); + } + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/listed/ArgumentListedOptionGeneratorContext.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/listed/ArgumentListedOptionGeneratorContext.java new file mode 100644 index 0000000000..53cc1fe919 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/listed/ArgumentListedOptionGeneratorContext.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.arguments.listed; + +import dev.jorel.commandapi.annotations.reloaded.arguments.utils.ArgumentListedOption; +import dev.jorel.commandapi.annotations.reloaded.generators.GeneratorContext; + +/** + * The context needed to generate the listed option for an argument + * + * @param listedOption Whether to include the listed option and what value it should have + */ +public record ArgumentListedOptionGeneratorContext( + ArgumentListedOption listedOption +) implements GeneratorContext { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/listed/package-info.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/listed/package-info.java new file mode 100644 index 0000000000..12a9f0fbe2 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/listed/package-info.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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. + *******************************************************************************/ +/** + * Components for working with the listed option for CommandAPI arguments + */ +@ParametersAreNonnullByDefault +@ReturnTypesAreNonnullByDefault +package dev.jorel.commandapi.annotations.reloaded.modules.arguments.listed; + +import javax.annotation.ParametersAreNonnullByDefault; + +import dev.jorel.commandapi.annotations.reloaded.ReturnTypesAreNonnullByDefault; diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/package-info.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/package-info.java new file mode 100644 index 0000000000..a74a04d6a7 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/package-info.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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. + *******************************************************************************/ +/** + * Components for generating the arguments for a CommandAPI command + */ +@ParametersAreNonnullByDefault +@ReturnTypesAreNonnullByDefault +package dev.jorel.commandapi.annotations.reloaded.modules.arguments; + +import javax.annotation.ParametersAreNonnullByDefault; +import dev.jorel.commandapi.annotations.reloaded.ReturnTypesAreNonnullByDefault; \ No newline at end of file diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/parsers/NodeNameParser.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/parsers/NodeNameParser.java new file mode 100644 index 0000000000..5811451603 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/parsers/NodeNameParser.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.arguments.parsers; + +import dev.jorel.commandapi.annotations.reloaded.annotations.NodeName; +import dev.jorel.commandapi.annotations.reloaded.parser.AnnotationParser; +import dev.jorel.commandapi.annotations.reloaded.parser.AnnotationParserContext; + +import javax.lang.model.element.Element; +import java.util.Optional; + +/** + * Parses the node name for an argument, using the {@link NodeName} annotation + * if one is present, or the parameter or field name if not. + */ +public class NodeNameParser implements AnnotationParser, String> { + @Override + public Optional parse(AnnotationParserContext context) { + Element element = context.element(); + if (element.getAnnotation(NodeName.class) != null) { + return Optional.of(element.getAnnotation(NodeName.class).value()); + } else { + return Optional.of(element.getSimpleName().toString()); + } + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/parsers/package-info.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/parsers/package-info.java new file mode 100644 index 0000000000..d59534f3c5 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/parsers/package-info.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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. + *******************************************************************************/ +/** + * Annotation parsers for CommandAPI arguments + */ +@ParametersAreNonnullByDefault +@ReturnTypesAreNonnullByDefault +package dev.jorel.commandapi.annotations.reloaded.modules.arguments.parsers; + +import javax.annotation.ParametersAreNonnullByDefault; + +import dev.jorel.commandapi.annotations.reloaded.ReturnTypesAreNonnullByDefault; diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/permissions/ArgumentPermissionGeneratorContext.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/permissions/ArgumentPermissionGeneratorContext.java new file mode 100644 index 0000000000..472c1234cf --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/permissions/ArgumentPermissionGeneratorContext.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.arguments.permissions; + +import dev.jorel.commandapi.CommandPermission; +import dev.jorel.commandapi.annotations.reloaded.generators.GeneratorContext; + +/** + * The context needed to generate the permission requirement for a CommandAPI argument + * + * @param permission The permission to require for the argument + */ +public record ArgumentPermissionGeneratorContext( + CommandPermission permission +) implements GeneratorContext { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/permissions/ArgumentPermissionsModule.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/permissions/ArgumentPermissionsModule.java new file mode 100644 index 0000000000..a76a5634c3 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/permissions/ArgumentPermissionsModule.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.arguments.permissions; + +import dev.jorel.commandapi.CommandPermission; +import dev.jorel.commandapi.annotations.reloaded.generators.IndentedWriter; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticAnalyzer; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRule; +import dev.jorel.commandapi.annotations.reloaded.modules.VariableElementAnalyzerParserGeneratorModule; +import dev.jorel.commandapi.annotations.reloaded.parser.VariableElementParserContext; + +import java.util.List; +import java.util.Optional; + +/** + * A module containing everything to do with generating permissions for a CommandAPI argument + */ +public class ArgumentPermissionsModule implements VariableElementAnalyzerParserGeneratorModule< + ArgumentPermissionGeneratorContext + > { + + @Override + public void generate(IndentedWriter out, ArgumentPermissionGeneratorContext context) { + CommandPermission permission = context.permission(); + if (permission.equals(CommandPermission.NONE)) { + // Do nothing + return; + } + if (permission.equals(CommandPermission.OP)) { + out.printOnNewLine(".withPermission(CommandPermission.OP)"); + return; + } + permission.getPermission().ifPresent(permissionValue -> + out.printOnNewLine(".%s(\"%s\")".formatted( + permission.isNegated() ? "withoutPermission" : "withPermission", + permissionValue + )) + ); + } + + @Override + public Optional parse(VariableElementParserContext context) { + throw new UnsupportedOperationException("%s: Parsing %s is not yet implemented".formatted(context.element(), getClass().getSimpleName())); //TODO + } + + @Override + public List subAnalyzers() { + return List.of(); + } + + @Override + public List rules() { + return List.of(); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/permissions/package-info.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/permissions/package-info.java new file mode 100644 index 0000000000..d91104e583 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/permissions/package-info.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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. + *******************************************************************************/ +/** + * Components for working with permissions of CommandAPI arguments + */ +@ParametersAreNonnullByDefault +@ReturnTypesAreNonnullByDefault +package dev.jorel.commandapi.annotations.reloaded.modules.arguments.permissions; + +import javax.annotation.ParametersAreNonnullByDefault; + +import dev.jorel.commandapi.annotations.reloaded.ReturnTypesAreNonnullByDefault; diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/requirements/ArgumentRequirementsGeneratorContext.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/requirements/ArgumentRequirementsGeneratorContext.java new file mode 100644 index 0000000000..7256ad13fc --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/requirements/ArgumentRequirementsGeneratorContext.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.arguments.requirements; + +import dev.jorel.commandapi.annotations.reloaded.generators.GeneratorContext; + +/** + * Context needed to generate the requirements option for a CommandAPI argument + */ +public record ArgumentRequirementsGeneratorContext( + //TODO +) implements GeneratorContext { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/requirements/ArgumentRequirementsModule.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/requirements/ArgumentRequirementsModule.java new file mode 100644 index 0000000000..a140365882 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/requirements/ArgumentRequirementsModule.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.arguments.requirements; + +import dev.jorel.commandapi.annotations.reloaded.generators.IndentedWriter; +import dev.jorel.commandapi.annotations.reloaded.parser.TypeElementParserContext; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticAnalyzer; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRule; +import dev.jorel.commandapi.annotations.reloaded.modules.TypeElementAnalyzerParserGeneratorModule; + +import java.util.List; +import java.util.Optional; + +/** + * Contains everything to do with generating the requirements option for a CommandAPI argument + */ +public class ArgumentRequirementsModule implements TypeElementAnalyzerParserGeneratorModule< + ArgumentRequirementsGeneratorContext + > { + @Override + public void generate(IndentedWriter out, ArgumentRequirementsGeneratorContext context) { + //TODO + } + + @Override + public List subAnalyzers() { + return List.of(); + } + + @Override + public List rules() { + return List.of(); + } + + @Override + public Optional parse(TypeElementParserContext context) { + throw new UnsupportedOperationException("%s: Parsing %s is not yet implemented".formatted(context.element(), getClass().getSimpleName())); //TODO + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/requirements/package-info.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/requirements/package-info.java new file mode 100644 index 0000000000..2f3fbc8f30 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/requirements/package-info.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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. + *******************************************************************************/ +/** + * Components for generating the requirements option of CommandAPI arguments + */ +@ParametersAreNonnullByDefault +@ReturnTypesAreNonnullByDefault +package dev.jorel.commandapi.annotations.reloaded.modules.arguments.requirements; + +import javax.annotation.ParametersAreNonnullByDefault; + +import dev.jorel.commandapi.annotations.reloaded.ReturnTypesAreNonnullByDefault; diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/suggestions/ArgumentSuggestionsGeneratorContext.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/suggestions/ArgumentSuggestionsGeneratorContext.java new file mode 100644 index 0000000000..fc9b857260 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/suggestions/ArgumentSuggestionsGeneratorContext.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.arguments.suggestions; + +import dev.jorel.commandapi.annotations.reloaded.arguments.utils.SuggestionsType; +import dev.jorel.commandapi.annotations.reloaded.generators.GeneratorContext; + +import java.util.Queue; + +/** + * Context needed to generate the suggestions option of a CommandAPI argument + * + * @param suggestionsType Whether a suggestion should be set, and whether it is safe or normal + * @param typeStack A set of types for generating the constructor invocation for the suggestions provider + */ +public record ArgumentSuggestionsGeneratorContext( + SuggestionsType suggestionsType, + Queue typeStack +) implements GeneratorContext { + + public boolean isSafe() { + return suggestionsType == SuggestionsType.SAFE; + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/suggestions/ArgumentSuggestionsModule.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/suggestions/ArgumentSuggestionsModule.java new file mode 100644 index 0000000000..b0ad23f71b --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/suggestions/ArgumentSuggestionsModule.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.arguments.suggestions; + +import dev.jorel.commandapi.annotations.reloaded.arguments.utils.SuggestionsType; +import dev.jorel.commandapi.annotations.reloaded.generators.IndentedWriter; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticAnalyzer; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRule; +import dev.jorel.commandapi.annotations.reloaded.modules.TypeElementAnalyzerParserGeneratorModule; +import dev.jorel.commandapi.annotations.reloaded.parser.TypeElementParserContext; + +import java.util.List; +import java.util.Optional; + +/** + * Contains everything to do with generating the suggestions option for a CommandAPI argument + */ +public class ArgumentSuggestionsModule implements TypeElementAnalyzerParserGeneratorModule< + ArgumentSuggestionsGeneratorContext + > { + + private final SafeSuggestionsAppliedToSafeOverrideableArgument safeSuggestionsAppliedToSafeOverrideableArgument; + private final SafeSuggestionsPrimitiveMatchesArgument safeSuggestionsPrimitiveMatchesArgument; + + public ArgumentSuggestionsModule(SafeSuggestionsAppliedToSafeOverrideableArgument safeSuggestionsAppliedToSafeOverrideableArgument, SafeSuggestionsPrimitiveMatchesArgument safeSuggestionsPrimitiveMatchesArgument) { + this.safeSuggestionsAppliedToSafeOverrideableArgument = safeSuggestionsAppliedToSafeOverrideableArgument; + this.safeSuggestionsPrimitiveMatchesArgument = safeSuggestionsPrimitiveMatchesArgument; + } + + @Override + public List subAnalyzers() { + return List.of(); + } + + @Override + public List rules() { + return List.of( + safeSuggestionsAppliedToSafeOverrideableArgument, + safeSuggestionsPrimitiveMatchesArgument + ); + } + @Override + public void generate(IndentedWriter out, ArgumentSuggestionsGeneratorContext context) { + if (context.suggestionsType() == SuggestionsType.NONE) { + return; + } + out.printOnNewLine(".%s(%s.get())".formatted( + context.isSafe() ? "replaceSafeSuggestions" : "replaceSuggestions", + null //TODO: constructorRenderer.render(context.typeStack()) + )); + } + + @Override + public Optional parse(TypeElementParserContext context) { + throw new UnsupportedOperationException("%s: Parsing %s is not yet implemented".formatted(context.element(), getClass().getSimpleName())); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/suggestions/SafeSuggestionsAppliedToSafeOverrideableArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/suggestions/SafeSuggestionsAppliedToSafeOverrideableArgument.java new file mode 100644 index 0000000000..8d9c260cc9 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/suggestions/SafeSuggestionsAppliedToSafeOverrideableArgument.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.arguments.suggestions; + +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRule; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRuleContext; + +/** + * Check that whatever we're applying suggestions to implements SafeOverrideableArgument. + */ +public class SafeSuggestionsAppliedToSafeOverrideableArgument implements SemanticRule { + + @Override + public boolean passes(SemanticRuleContext context) { + context.logging().complain("Not yet implemented"); + return false; //TODO + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/suggestions/SafeSuggestionsPrimitiveMatchesArgument.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/suggestions/SafeSuggestionsPrimitiveMatchesArgument.java new file mode 100644 index 0000000000..781d33b830 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/suggestions/SafeSuggestionsPrimitiveMatchesArgument.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.arguments.suggestions; + +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRule; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRuleContext; + +/** + * Check that the type argument of the + * {@link dev.jorel.commandapi.arguments.SafeOverrideableArgument} matches the primitive + */ +public class SafeSuggestionsPrimitiveMatchesArgument implements SemanticRule { + + @Override + public boolean passes(SemanticRuleContext context) { + context.logging().complain("Not yet implemented"); + return false; //TODO + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/suggestions/package-info.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/suggestions/package-info.java new file mode 100644 index 0000000000..028c97d59f --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/arguments/suggestions/package-info.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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. + *******************************************************************************/ +/** + * Components for generating the suggestions option for CommandAPI arguments + */ +@ParametersAreNonnullByDefault +@ReturnTypesAreNonnullByDefault +package dev.jorel.commandapi.annotations.reloaded.modules.arguments.suggestions; + +import javax.annotation.ParametersAreNonnullByDefault; + +import dev.jorel.commandapi.annotations.reloaded.ReturnTypesAreNonnullByDefault; diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/base/CommandsClassGeneratorContext.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/base/CommandsClassGeneratorContext.java new file mode 100644 index 0000000000..9f44de18c5 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/base/CommandsClassGeneratorContext.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.base; + +import dev.jorel.commandapi.annotations.reloaded.generators.GeneratorContext; +import dev.jorel.commandapi.annotations.reloaded.modules.commands.CommandRegisterMethodGeneratorContext; +import dev.jorel.commandapi.annotations.reloaded.parser.ImportsBuilder; + +import javax.annotation.processing.ProcessingEnvironment; +import java.time.ZonedDateTime; +import java.util.List; + +/** + * Context for generating the class for registering all CommandAPI commands from their annotations + * + * @param processingEnv The annotations processing environment + * @param imports A builder for generating a set of imports for this class + * @param packageName The package name for this class + * @param commandsClassName The class name for this class + * @param generatorStarted The time that the annotations processor started + * @param registerMethods The context needed to generate each of the register method invocations of each command + */ +public record CommandsClassGeneratorContext( + ProcessingEnvironment processingEnv, + ImportsBuilder imports, + String packageName, + String commandsClassName, + ZonedDateTime generatorStarted, + List registerMethods +) implements GeneratorContext { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/base/CommandsClassImportsGenerator.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/base/CommandsClassImportsGenerator.java new file mode 100644 index 0000000000..99540b92fd --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/base/CommandsClassImportsGenerator.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.base; + +import dev.jorel.commandapi.annotations.reloaded.generators.CodeGenerator; +import dev.jorel.commandapi.annotations.reloaded.generators.IndentedWriter; + +/** + * Generate a set of imports for the commands class + */ +public class CommandsClassImportsGenerator implements CodeGenerator { + @Override + public void generate(IndentedWriter out, CommandsClassGeneratorContext context) { + for (String qualifiedName : context.imports().getAllFullyQualifiedNames()) { + out.printOnNewLine("import %s;".formatted(qualifiedName)); + } + out.printEmptyLine(); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/base/CommandsClassJavadocGenerator.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/base/CommandsClassJavadocGenerator.java new file mode 100644 index 0000000000..6b5ef74714 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/base/CommandsClassJavadocGenerator.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.base; + +import dev.jorel.commandapi.annotations.reloaded.generators.CodeGenerator; +import dev.jorel.commandapi.annotations.reloaded.generators.IndentedWriter; +import dev.jorel.commandapi.annotations.reloaded.modules.commands.CommandRegisterMethodGeneratorContext; + +/** + * Generates the Javadoc for the Commands class + */ +public class CommandsClassJavadocGenerator implements CodeGenerator { + @Override + public void generate(IndentedWriter out, CommandsClassGeneratorContext context) { + out.printOnNewLine("/**"); + out.printOnNewLine(" * This class was automatically generated by the CommandAPI"); + out.printOnNewLine(" * Generation time: %tc".formatted(context.generatorStarted())); + out.printOnNewLine(" * @Command classes used:"); + for (CommandRegisterMethodGeneratorContext methodContext : context.registerMethods()) { + out.printOnNewLine(" * - {@link %s}".formatted(methodContext.qualifiedCommandClassName())); + } + out.printOnNewLine(" */"); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/base/CommandsClassModule.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/base/CommandsClassModule.java new file mode 100644 index 0000000000..66953e32e5 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/base/CommandsClassModule.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.base; + +import dev.jorel.commandapi.annotations.reloaded.generators.CodeGenerator; +import dev.jorel.commandapi.annotations.reloaded.generators.IndentedWriter; +import dev.jorel.commandapi.annotations.reloaded.modules.commands.CommandRegisterMethodGeneratorContext; +import dev.jorel.commandapi.annotations.reloaded.modules.commands.CommandRegisterMethodModule; +import dev.jorel.commandapi.annotations.reloaded.parser.ParserUtils; +import dev.jorel.commandapi.annotations.reloaded.parser.TypeElementParserContext; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticAnalyzer; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRule; + +import javax.lang.model.element.TypeElement; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +/** + * Contains everything to do with generating the commands class for registering CommandAPI commands from annotations + */ +public class CommandsClassModule implements SemanticAnalyzer, CodeGenerator { + private final CommandsClassPackageGenerator commandsClassPackageGenerator; + private final CommandsClassImportsGenerator commandsClassImportsGenerator; + private final CommandsClassJavadocGenerator commandsClassJavadocGenerator; + private final CommandRegisterMethodModule commandRegisterMethodModule; + + public CommandsClassModule( + CommandsClassPackageGenerator commandsClassPackageGenerator, + CommandsClassImportsGenerator commandsClassImportsGenerator, + CommandsClassJavadocGenerator commandsClassJavadocGenerator, + CommandRegisterMethodModule commandRegisterMethodModule + ) { + this.commandsClassPackageGenerator = commandsClassPackageGenerator; + this.commandsClassImportsGenerator = commandsClassImportsGenerator; + this.commandsClassJavadocGenerator = commandsClassJavadocGenerator; + this.commandRegisterMethodModule = commandRegisterMethodModule; + } + + public Optional parseAllContexts( + ParserUtils parserUtils, + String commandsClassName, + ZonedDateTime generatorStarted, + Set commandClasses + ) { + List> maybeAllContexts = commandClasses.stream() + .map(element -> commandRegisterMethodModule.parse(new TypeElementParserContext( + parserUtils, + element + ))) + .toList(); + if (!maybeAllContexts.stream().allMatch(Optional::isPresent)) { + return Optional.empty(); + } + return Optional.of(new CommandsClassGeneratorContext( + parserUtils.processingEnv(), + parserUtils.imports(), + "packageName", //TODO How do we want to handle packages? + commandsClassName, + generatorStarted, + maybeAllContexts.stream().map(Optional::orElseThrow).toList() + )); + } + + @Override + public void generate(IndentedWriter out, CommandsClassGeneratorContext context) { + commandsClassPackageGenerator.generate(out, context); + commandsClassImportsGenerator.generate(out, context); + commandsClassJavadocGenerator.generate(out, context); + out.printOnNewLine("public class %s {".formatted(context.commandsClassName())); + out.indent(indented -> context.registerMethods().forEach(registerMethodContext -> + commandRegisterMethodModule.generate(indented, registerMethodContext) + )); + out.printOnNewLine("}"); + } + + @Override + public List subAnalyzers() { + return List.of( + commandRegisterMethodModule + ); + } + + @Override + public List rules() { + return List.of(); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/base/CommandsClassPackageGenerator.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/base/CommandsClassPackageGenerator.java new file mode 100644 index 0000000000..5cfd2b65af --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/base/CommandsClassPackageGenerator.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.base; + +import dev.jorel.commandapi.annotations.reloaded.generators.CodeGenerator; +import dev.jorel.commandapi.annotations.reloaded.generators.IndentedWriter; + +/** + * Generate the package for the commands class + */ +public class CommandsClassPackageGenerator implements CodeGenerator { + @Override + public void generate(IndentedWriter out, CommandsClassGeneratorContext context) { +// out.appendInLine("package %s;".formatted(context.packageName())); //TODO + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/base/package-info.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/base/package-info.java new file mode 100644 index 0000000000..7e9f4cd1ff --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/base/package-info.java @@ -0,0 +1,32 @@ +/** + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + *

+ * 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. + *

+ * Components for generating the commands class for registering CommandAPI commands with annotations + */ +/** + * Components for generating the commands class for registering CommandAPI commands with annotations + */ +@ParametersAreNonnullByDefault +@ReturnTypesAreNonnullByDefault +package dev.jorel.commandapi.annotations.reloaded.modules.base; + +import javax.annotation.ParametersAreNonnullByDefault; + +import dev.jorel.commandapi.annotations.reloaded.ReturnTypesAreNonnullByDefault; diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandExecutorMethodBaseCommandNameParser.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandExecutorMethodBaseCommandNameParser.java new file mode 100644 index 0000000000..5bf977d967 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandExecutorMethodBaseCommandNameParser.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.commands; + +import dev.jorel.commandapi.annotations.reloaded.AnnotationUtils; +import dev.jorel.commandapi.annotations.reloaded.parser.ExecutableElementParser; +import dev.jorel.commandapi.annotations.reloaded.parser.ExecutableElementParserContext; +import dev.jorel.commandapi.annotations.reloaded.parser.ParserUtils; +import dev.jorel.commandapi.annotations.reloaded.parser.TypeElementParserContext; + +import javax.lang.model.element.TypeElement; +import java.util.Optional; + +/** + * Parses the base command name for generating the parameter for a CommandAPI command constructor invocation + */ +public class CommandExecutorMethodBaseCommandNameParser implements ExecutableElementParser { + private final CommandNamesParser commandNamesParser; + + public CommandExecutorMethodBaseCommandNameParser(CommandNamesParser commandNamesParser) { + this.commandNamesParser = commandNamesParser; + } + + @Override + public Optional parse(ExecutableElementParserContext context) { + ParserUtils utils = context.utils(); + AnnotationUtils annotationUtils = utils.annotationUtils(); + TypeElement topLevelClass = annotationUtils.getTopLevelClass(context.element()); + return commandNamesParser + .parse(new TypeElementParserContext(utils, topLevelClass)) + .map(CommandNames::name); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandExecutorMethodExecutorGeneratorContext.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandExecutorMethodExecutorGeneratorContext.java new file mode 100644 index 0000000000..39ccc3bac6 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandExecutorMethodExecutorGeneratorContext.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.commands; + +import dev.jorel.commandapi.annotations.reloaded.generators.GeneratorContext; + +/** + * Context needed to generate the executor option for a CommandAPI command + */ +public record CommandExecutorMethodExecutorGeneratorContext( + //TODO +) implements GeneratorContext { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandExecutorMethodExecutorModule.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandExecutorMethodExecutorModule.java new file mode 100644 index 0000000000..d0a6e6fcef --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandExecutorMethodExecutorModule.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.commands; + +import dev.jorel.commandapi.annotations.reloaded.generators.IndentedWriter; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticAnalyzer; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRule; +import dev.jorel.commandapi.annotations.reloaded.modules.ExecutableElementAnalyzerParserGeneratorModule; +import dev.jorel.commandapi.annotations.reloaded.parser.ExecutableElementParserContext; + +import java.util.List; +import java.util.Optional; + +/** + * Contains everything to do with generating the executor option of a CommandAPI command + */ +public class CommandExecutorMethodExecutorModule implements ExecutableElementAnalyzerParserGeneratorModule { + @Override + public Optional parse(ExecutableElementParserContext context) { + return Optional.of(new CommandExecutorMethodExecutorGeneratorContext()); //TODO + } + + @Override + public void generate(IndentedWriter out, CommandExecutorMethodExecutorGeneratorContext context) { + //TODO + } + + @Override + public List subAnalyzers() { + return List.of(); + } + + @Override + public List rules() { + return List.of(); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandExecutorMethodGeneratorContext.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandExecutorMethodGeneratorContext.java new file mode 100644 index 0000000000..f4e0b5d5e9 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandExecutorMethodGeneratorContext.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.commands; + +import dev.jorel.commandapi.annotations.reloaded.generators.GeneratorContext; +import dev.jorel.commandapi.annotations.reloaded.modules.arguments.CommandExecutorMethodArgumentsGeneratorContext; +import dev.jorel.commandapi.annotations.reloaded.modules.permissions.CommandExecutorMethodPermissionsGeneratorContext; + +/** + * Context needed to generate the registration for a CommandAPI command + * + * @param commandClassName The name of the command class + * @param baseCommandName The name of the command node + * @param permissionContext Context needed to generate the command permissions option + * @param argumentsContext Context needed to generate the command arguments option + * @param executorContext Context needed to generate the command executor option + */ +public record CommandExecutorMethodGeneratorContext( + String commandClassName, + String baseCommandName, + CommandExecutorMethodPermissionsGeneratorContext permissionContext, + CommandExecutorMethodArgumentsGeneratorContext argumentsContext, + CommandExecutorMethodExecutorGeneratorContext executorContext +) implements GeneratorContext { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandExecutorMethodModule.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandExecutorMethodModule.java new file mode 100644 index 0000000000..fdcc3666b5 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandExecutorMethodModule.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.commands; + +import dev.jorel.commandapi.CommandAPICommand; +import dev.jorel.commandapi.annotations.reloaded.generators.IndentedWriter; +import dev.jorel.commandapi.annotations.reloaded.modules.arguments.CommandExecutorMethodArgumentsGeneratorContext; +import dev.jorel.commandapi.annotations.reloaded.modules.arguments.CommandExecutorMethodArgumentsModule; +import dev.jorel.commandapi.annotations.reloaded.modules.permissions.CommandExecutorMethodPermissionsGeneratorContext; +import dev.jorel.commandapi.annotations.reloaded.modules.permissions.CommandExecutorMethodPermissionsModule; +import dev.jorel.commandapi.annotations.reloaded.parser.ParserUtils; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticAnalyzer; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRule; +import dev.jorel.commandapi.annotations.reloaded.modules.ExecutableElementAnalyzerParserGeneratorModule; +import dev.jorel.commandapi.annotations.reloaded.parser.ExecutableElementParserContext; + +import java.util.List; +import java.util.Optional; + +/** + * Contains everything to do with generating the registration for a CommandAPI command + */ +public class CommandExecutorMethodModule implements ExecutableElementAnalyzerParserGeneratorModule { + + private final CommandExecutorMethodBaseCommandNameParser commandNameParser; + private final CommandExecutorMethodPermissionsModule permissionsModule; + private final CommandExecutorMethodArgumentsModule argumentsModule; + private final CommandExecutorMethodExecutorModule executorModule; + + public CommandExecutorMethodModule( + CommandExecutorMethodBaseCommandNameParser commandNameParser, + CommandExecutorMethodPermissionsModule permissionsModule, + CommandExecutorMethodArgumentsModule argumentsModule, + CommandExecutorMethodExecutorModule executorModule + ) { + this.commandNameParser = commandNameParser; + this.permissionsModule = permissionsModule; + this.argumentsModule = argumentsModule; + this.executorModule = executorModule; + } + + @Override + public void generate(IndentedWriter out, CommandExecutorMethodGeneratorContext context) { + out.printOnNewLine("new %s(\"%s\")".formatted( + context.commandClassName(), + context.baseCommandName() + )); + out.indent(indented -> { + permissionsModule.generate(indented, context.permissionContext()); + argumentsModule.generate(indented, context.argumentsContext()); + executorModule.generate(indented, context.executorContext()); + }); + out.appendInLine(";"); + out.printEmptyLine(); + } + + @Override + public Optional parse(ExecutableElementParserContext context) { + ParserUtils utils = context.utils(); + Optional maybeBaseCommandName = commandNameParser.parse(context); + Optional maybePermissions = permissionsModule.parse(context); + Optional maybeArguments = argumentsModule.parse(context); + Optional maybeExecutor = executorModule.parse(context); + if ( + maybeBaseCommandName.isEmpty() || + maybePermissions.isEmpty() || + maybeArguments.isEmpty() || + maybeExecutor.isEmpty()) { + return Optional.empty(); + } + return Optional.of( + new CommandExecutorMethodGeneratorContext( + utils.imports().withImport(CommandAPICommand.class), + maybeBaseCommandName.orElseThrow(), + maybePermissions.orElseThrow(), + maybeArguments.orElseThrow(), + maybeExecutor.orElseThrow() + ) + ); + } + + @Override + public List subAnalyzers() { + return List.of( + permissionsModule, + argumentsModule, + executorModule + ); + } + + @Override + public List rules() { + return List.of(); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandExecutorsGeneratorContext.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandExecutorsGeneratorContext.java new file mode 100644 index 0000000000..7804295e77 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandExecutorsGeneratorContext.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.commands; + +import dev.jorel.commandapi.annotations.reloaded.generators.GeneratorContext; + +import java.util.List; + +/** + * Context needed to generate the list of CommandAPI command registrations + * + * @param list The context needed to generate each CommandAPI command registration + */ +public record CommandExecutorsGeneratorContext( + List list +) implements GeneratorContext { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandExecutorsModule.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandExecutorsModule.java new file mode 100644 index 0000000000..daac22c2f5 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandExecutorsModule.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.commands; + +import dev.jorel.commandapi.annotations.reloaded.AnnotationUtils; +import dev.jorel.commandapi.annotations.reloaded.annotations.Executes; +import dev.jorel.commandapi.annotations.reloaded.generators.IndentedWriter; +import dev.jorel.commandapi.annotations.reloaded.parser.ParserUtils; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticAnalyzer; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRule; +import dev.jorel.commandapi.annotations.reloaded.modules.TypeElementAnalyzerParserGeneratorModule; +import dev.jorel.commandapi.annotations.reloaded.parser.ExecutableElementParserContext; +import dev.jorel.commandapi.annotations.reloaded.parser.TypeElementParserContext; + +import java.util.List; +import java.util.Optional; + +/** + * Contains everything to do with generating the list of CommandAPI command registrations + */ +public class CommandExecutorsModule implements TypeElementAnalyzerParserGeneratorModule { + private final CommandExecutorMethodModule commandExecutorMethodModule; + + public CommandExecutorsModule(CommandExecutorMethodModule commandExecutorMethodModule) { + this.commandExecutorMethodModule = commandExecutorMethodModule; + } + + @Override + public void generate(IndentedWriter out, CommandExecutorsGeneratorContext context) { + for (CommandExecutorMethodGeneratorContext executorContext : context.list()) { + commandExecutorMethodModule.generate(out, executorContext); + } + } + + @Override + public Optional parse(TypeElementParserContext context) { + ParserUtils utils = context.utils(); + AnnotationUtils annotationUtils = utils.annotationUtils(); + List> maybeExecutors = annotationUtils + .getEnclosedMethodsWithAnnotation(context.element(), Executes.class).stream() + .map(executorMethod -> new ExecutableElementParserContext(utils, executorMethod)) + .map(commandExecutorMethodModule::parse) + .toList(); + if (maybeExecutors.stream().anyMatch(Optional::isEmpty)) { + return Optional.empty(); + } + return Optional.of(new CommandExecutorsGeneratorContext( + maybeExecutors.stream().flatMap(Optional::stream).toList() + )); + } + + @Override + public List subAnalyzers() { + return List.of( + commandExecutorMethodModule + ); + } + + @Override + public List rules() { + return List.of(); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandHelp.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandHelp.java new file mode 100644 index 0000000000..bdcd97db08 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandHelp.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.commands; + +/** + * The help information for a CommandAPI command + * + * @param fullDescription Displayed in the description section of the help topic for the command + * @param shortDescription Displayed in help lists and at the top of the help topic for the command + */ +public record CommandHelp( + String fullDescription, + String shortDescription +) { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandHelpParser.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandHelpParser.java new file mode 100644 index 0000000000..05a27fe7c8 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandHelpParser.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.commands; + +import dev.jorel.commandapi.annotations.reloaded.Logging; +import dev.jorel.commandapi.annotations.reloaded.annotations.Command; +import dev.jorel.commandapi.annotations.reloaded.annotations.Help; +import dev.jorel.commandapi.annotations.reloaded.parser.ParserUtils; +import dev.jorel.commandapi.annotations.reloaded.parser.TypeElementParser; +import dev.jorel.commandapi.annotations.reloaded.parser.TypeElementParserContext; + +import javax.lang.model.element.TypeElement; +import java.util.Optional; + +/** + * Parses command help information for generating the help option for CommandAPI command registration invocations + */ +public class CommandHelpParser implements TypeElementParser { + + @Override + public Optional parse(TypeElementParserContext context) { + TypeElement commandClass = context.element(); + ParserUtils utils = context.utils(); + Logging logging = utils.logging(); + Help helpAnnotation = commandClass.getAnnotation(Help.class); + if (helpAnnotation == null) { + return Optional.of(new CommandHelp("", "")); + } + Command commandAnnotation = commandClass.getAnnotation(Command.class); + if (commandAnnotation == null) { + logging.complain(commandClass, "@%s can only go on @%s classes" + .formatted(Help.class.getSimpleName(), Command.class.getSimpleName())); + return Optional.empty(); + } + logging.info(commandClass, "Help found %s".formatted(helpAnnotation)); + return Optional.of( + new CommandHelp( + helpAnnotation.value(), + helpAnnotation.shortDescription() + ) + ); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandNames.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandNames.java new file mode 100644 index 0000000000..a268393e9a --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandNames.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.commands; + +/** + * The name information for a CommandAPI command. + * + * @param name The base command name + * @param aliases Aliases for the command + */ +public record CommandNames( + String name, + String[] aliases +) { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandNamesParser.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandNamesParser.java new file mode 100644 index 0000000000..668346b7eb --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandNamesParser.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.commands; + +import dev.jorel.commandapi.annotations.reloaded.Logging; +import dev.jorel.commandapi.annotations.reloaded.annotations.Command; +import dev.jorel.commandapi.annotations.reloaded.parser.ParserUtils; +import dev.jorel.commandapi.annotations.reloaded.parser.TypeElementParser; +import dev.jorel.commandapi.annotations.reloaded.parser.TypeElementParserContext; + +import javax.lang.model.element.TypeElement; +import java.util.Arrays; +import java.util.Optional; + +/** + * Parses command names and aliases for use in generating CommandAPI command registration invocations + */ +public class CommandNamesParser implements TypeElementParser { + @Override + public Optional parse(TypeElementParserContext context) { + TypeElement commandClass = context.element(); + ParserUtils utils = context.utils(); + Logging logging = utils.logging(); + logging.info(commandClass, "Parsing command names"); + Command command = commandClass.getAnnotation(Command.class); + if (command == null) { + logging.complain(commandClass, "@%s annotation missing on command class" + .formatted(Command.class.getSimpleName())); + return Optional.empty(); + } + String[] names = command.value(); + if (names.length == 0) { + logging.complain(commandClass, "@%s annotation must have at least one value" + .formatted(Command.class.getSimpleName())); + return Optional.empty(); + } + String[] aliases = names.length > 1 ? Arrays.copyOfRange(names, 1, names.length) : new String[0]; + logging.info(commandClass, "Parsed command names %s and aliases %s" + .formatted(names[0], String.join(", ", aliases))); + return Optional.of(new CommandNames(names[0], aliases)); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandRegisterMethodGeneratorContext.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandRegisterMethodGeneratorContext.java new file mode 100644 index 0000000000..1a17e9bf90 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandRegisterMethodGeneratorContext.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.commands; + +import dev.jorel.commandapi.annotations.reloaded.generators.GeneratorContext; +import dev.jorel.commandapi.annotations.reloaded.modules.subcommands.SubcommandsGeneratorContext; + +/** + * Context needed to generate the CommandAPI command registration invocation. + * + * @param commandClassName The command class name + * @param subcommands The context to generate all subcommands + */ +public record CommandRegisterMethodGeneratorContext( + String commandClassName, + String qualifiedCommandClassName, + SubcommandsGeneratorContext subcommands +) implements GeneratorContext { + +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandRegisterMethodJavadocGenerator.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandRegisterMethodJavadocGenerator.java new file mode 100644 index 0000000000..90c9bb6d73 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandRegisterMethodJavadocGenerator.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.commands; + +import dev.jorel.commandapi.annotations.reloaded.generators.CodeGenerator; +import dev.jorel.commandapi.annotations.reloaded.generators.IndentedWriter; + +/** + * Generates the Javadoc for the registration method for a set of CommandAPI commands from a particular command class + */ +public class CommandRegisterMethodJavadocGenerator implements CodeGenerator { + @Override + public void generate(IndentedWriter out, CommandRegisterMethodGeneratorContext context) { + out.printOnNewLine("/**"); +// out.println(indentation() + " * Registers the following commands:"); + // TODO: + // /blah + // And so on... + out.printOnNewLine(" * @param command an instance of {@link %s} for command execution" + .formatted(context.commandClassName()) + ); + out.printOnNewLine(" */"); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandRegisterMethodModule.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandRegisterMethodModule.java new file mode 100644 index 0000000000..af56b082af --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/CommandRegisterMethodModule.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.commands; + +import dev.jorel.commandapi.annotations.reloaded.Logging; +import dev.jorel.commandapi.annotations.reloaded.generators.IndentedWriter; +import dev.jorel.commandapi.annotations.reloaded.modules.TypeElementAnalyzerParserGeneratorModule; +import dev.jorel.commandapi.annotations.reloaded.modules.subcommands.SubcommandsGeneratorContext; +import dev.jorel.commandapi.annotations.reloaded.modules.subcommands.SubcommandsModule; +import dev.jorel.commandapi.annotations.reloaded.parser.ParserUtils; +import dev.jorel.commandapi.annotations.reloaded.parser.TypeElementParserContext; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticAnalyzer; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRule; + +import javax.lang.model.element.TypeElement; +import java.util.List; +import java.util.Optional; + +/** + * Contains everything to do with generating the registration of a CommandAPI command via annotations + */ +public class CommandRegisterMethodModule implements TypeElementAnalyzerParserGeneratorModule { + private final RuleCommandCanOnlyGoOnTopLevelClasses ruleCommandCanOnlyGoOnTopLevelClasses; + private final CommandRegisterMethodJavadocGenerator javadocGenerator; + private final SubcommandsModule subcommandsModule; + + public CommandRegisterMethodModule( + RuleCommandCanOnlyGoOnTopLevelClasses ruleCommandCanOnlyGoOnTopLevelClasses, + CommandRegisterMethodJavadocGenerator javadocGenerator, + SubcommandsModule subcommandsModule + ) { + this.ruleCommandCanOnlyGoOnTopLevelClasses = ruleCommandCanOnlyGoOnTopLevelClasses; + this.javadocGenerator = javadocGenerator; + this.subcommandsModule = subcommandsModule; + } + + @Override + public Optional parse(TypeElementParserContext context) { + TypeElement element = context.element(); + ParserUtils utils = context.utils(); + Logging logging = utils.logging(); + logging.info(element, "Parsing context"); + Optional maybeSubcommandsContext = subcommandsModule.parse(context); + if (maybeSubcommandsContext.isEmpty()) { + logging.info(element, "Failed to parse context"); + return Optional.empty(); + } + logging.info(element, "Successfully parsed context"); + return Optional.of( + new CommandRegisterMethodGeneratorContext( + utils.imports().withImport(element), + element.getQualifiedName().toString(), + maybeSubcommandsContext.orElseThrow() + ) + ); + } + + @Override + public void generate(IndentedWriter out, CommandRegisterMethodGeneratorContext context) { + javadocGenerator.generate(out, context); + out.printOnNewLine("public static void register(%s command) {" + .formatted(context.commandClassName())); + out.indent(indented -> subcommandsModule.generate(indented, context.subcommands())); + out.printOnNewLine("}"); + } + + @Override + public List subAnalyzers() { + return List.of( + subcommandsModule + ); + } + + @Override + public List rules() { + return List.of( + ruleCommandCanOnlyGoOnTopLevelClasses + ); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/RuleCommandCanOnlyGoOnTopLevelClasses.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/RuleCommandCanOnlyGoOnTopLevelClasses.java new file mode 100644 index 0000000000..674e19fb57 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/RuleCommandCanOnlyGoOnTopLevelClasses.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.commands; + +import dev.jorel.commandapi.annotations.reloaded.annotations.Command; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRule; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRuleContext; + +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.NestingKind; +import javax.lang.model.element.TypeElement; + +/** + * A semantic rule that checks to make sure that all command annotations are on top-level classes + */ +public class RuleCommandCanOnlyGoOnTopLevelClasses implements SemanticRule { + @Override + public boolean passes(SemanticRuleContext context) { + boolean passing = true; + for (Element element : context.roundEnv().getElementsAnnotatedWith(Command.class)) { + if (element instanceof TypeElement typeElement) { + if (typeElement.getKind() == ElementKind.CLASS && + typeElement.getNestingKind() == NestingKind.TOP_LEVEL) { + continue; + } + } + context.logging().complain(element, "@%s can only go on a top level class" + .formatted(Command.class.getSimpleName())); + passing = false; + } + return passing; + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/package-info.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/package-info.java new file mode 100644 index 0000000000..1efd3b952a --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/commands/package-info.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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. + *******************************************************************************/ +/** + * Components for generating CommandAPI command registration methods for annotation command classes + */ +@ParametersAreNonnullByDefault +@ReturnTypesAreNonnullByDefault +package dev.jorel.commandapi.annotations.reloaded.modules.commands; + +import javax.annotation.ParametersAreNonnullByDefault; + +import dev.jorel.commandapi.annotations.reloaded.ReturnTypesAreNonnullByDefault; diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/package-info.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/package-info.java new file mode 100644 index 0000000000..7dd1321e7f --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/package-info.java @@ -0,0 +1,32 @@ +/** + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + *

+ * 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. + *

+ * Components for working with CommandAPI sub-command annotations + */ +/** + * Components for generating CommandAPI commands from annotations + */ +@ParametersAreNonnullByDefault +@ReturnTypesAreNonnullByDefault +package dev.jorel.commandapi.annotations.reloaded.modules; + +import javax.annotation.ParametersAreNonnullByDefault; + +import dev.jorel.commandapi.annotations.reloaded.ReturnTypesAreNonnullByDefault; diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/permissions/CommandExecutorMethodPermissionsGeneratorContext.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/permissions/CommandExecutorMethodPermissionsGeneratorContext.java new file mode 100644 index 0000000000..9fb7ed5fc1 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/permissions/CommandExecutorMethodPermissionsGeneratorContext.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.permissions; + +import dev.jorel.commandapi.annotations.reloaded.generators.GeneratorContext; + +/** + * The context needed to generate the permissions option of a CommandAPI command + */ +public record CommandExecutorMethodPermissionsGeneratorContext( + //TODO +) implements GeneratorContext { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/permissions/CommandExecutorMethodPermissionsModule.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/permissions/CommandExecutorMethodPermissionsModule.java new file mode 100644 index 0000000000..217a58d055 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/permissions/CommandExecutorMethodPermissionsModule.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.permissions; + +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticAnalyzer; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRule; +import dev.jorel.commandapi.annotations.reloaded.generators.IndentedWriter; +import dev.jorel.commandapi.annotations.reloaded.modules.ExecutableElementAnalyzerParserGeneratorModule; +import dev.jorel.commandapi.annotations.reloaded.parser.ExecutableElementParserContext; + +import java.util.List; +import java.util.Optional; + +/** + * Contains everything to do with generating the permissions option for a CommandAPI command registration + */ +public class CommandExecutorMethodPermissionsModule implements ExecutableElementAnalyzerParserGeneratorModule< + CommandExecutorMethodPermissionsGeneratorContext> { + @Override + public Optional parse(ExecutableElementParserContext context) { + return Optional.of(new CommandExecutorMethodPermissionsGeneratorContext()); //TODO + } + + @Override + public void generate(IndentedWriter out, CommandExecutorMethodPermissionsGeneratorContext context) { + //TODO + } + + @Override + public List subAnalyzers() { + return List.of(); + } + + @Override + public List rules() { + return List.of(); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/permissions/package-info.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/permissions/package-info.java new file mode 100644 index 0000000000..0913afe510 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/permissions/package-info.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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. + *******************************************************************************/ +/** + * Components for generating the permissions option of CommandAPI commands from annotations + */ +@ParametersAreNonnullByDefault +@ReturnTypesAreNonnullByDefault +package dev.jorel.commandapi.annotations.reloaded.modules.permissions; + +import dev.jorel.commandapi.annotations.reloaded.ReturnTypesAreNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/RuleNonTopLevelTypeSubCommandsMustGoInsideCommandOrSubcommandClasses.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/RuleNonTopLevelTypeSubCommandsMustGoInsideCommandOrSubcommandClasses.java new file mode 100644 index 0000000000..cf69e8c5d0 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/RuleNonTopLevelTypeSubCommandsMustGoInsideCommandOrSubcommandClasses.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.subcommands; + +import dev.jorel.commandapi.annotations.reloaded.AnnotationUtils; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRule; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRuleContext; +import dev.jorel.commandapi.annotations.reloaded.annotations.Command; +import dev.jorel.commandapi.annotations.reloaded.annotations.ExternalSubcommand; +import dev.jorel.commandapi.annotations.reloaded.annotations.Subcommand; + +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.TypeElement; + +/** + * A semantic rule that checks that when a sub-command is enclosed within a class, that class is either a command or + * sub-command itself + */ +public class RuleNonTopLevelTypeSubCommandsMustGoInsideCommandOrSubcommandClasses implements SemanticRule { + + @Override + public boolean passes(SemanticRuleContext context) { + AnnotationUtils annotationUtils = context.annotationUtils(); + boolean passes = true; + for (Element element : context.roundEnv().getElementsAnnotatedWith(Subcommand.class)) { + if (element instanceof TypeElement classElement) { + Element enclosingElement = classElement.getEnclosingElement(); + if (enclosingElement.getKind() == ElementKind.CLASS) { + if (annotationUtils.doesNotHaveAnnotations(enclosingElement, Command.class, Subcommand.class)) { + context.logging().complain(classElement, + "@%s can only go inside @%s classes (or be top-level classes pointed to by an @%s)" + .formatted( + Subcommand.class.getSimpleName(), + Command.class.getSimpleName(), + ExternalSubcommand.class.getSimpleName() + ) + ); + passes = false; + } + } + } + } + return passes; + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/RuleNonTopLevelTypeSubcommandsCanOnlyGoInsideClasses.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/RuleNonTopLevelTypeSubcommandsCanOnlyGoInsideClasses.java new file mode 100644 index 0000000000..1adf90f510 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/RuleNonTopLevelTypeSubcommandsCanOnlyGoInsideClasses.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.subcommands; + +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRule; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRuleContext; +import dev.jorel.commandapi.annotations.reloaded.annotations.Command; +import dev.jorel.commandapi.annotations.reloaded.annotations.ExternalSubcommand; +import dev.jorel.commandapi.annotations.reloaded.annotations.Subcommand; + +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.TypeElement; + +/** + * A semantic rule for checking that sub-commands enclosed within other elements are only inside class elements + */ +public class RuleNonTopLevelTypeSubcommandsCanOnlyGoInsideClasses implements SemanticRule { + + @Override + public boolean passes(SemanticRuleContext context) { + boolean passes = true; + for (Element element : context.roundEnv().getElementsAnnotatedWith(Subcommand.class)) { + if (element instanceof TypeElement classElement) { + Element enclosingElement = classElement.getEnclosingElement(); + if (enclosingElement.getKind() != ElementKind.CLASS && + enclosingElement.getKind() != ElementKind.PACKAGE) { + context.logging().complain(classElement, + "@%s can only go inside @%s classes (or be top-level classes pointed to by an @%s)" + .formatted( + Subcommand.class.getSimpleName(), + Command.class.getSimpleName(), + ExternalSubcommand.class.getSimpleName() + ) + ); + passes = false; + } + } + } + return passes; + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/RuleTopLevelSubCommandClassesMustExtendCommandOrSubcommandClass.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/RuleTopLevelSubCommandClassesMustExtendCommandOrSubcommandClass.java new file mode 100644 index 0000000000..2eb16fb34f --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/RuleTopLevelSubCommandClassesMustExtendCommandOrSubcommandClass.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.subcommands; + +import dev.jorel.commandapi.annotations.reloaded.AnnotationUtils; +import dev.jorel.commandapi.annotations.reloaded.annotations.Command; +import dev.jorel.commandapi.annotations.reloaded.annotations.ExternalSubcommand; +import dev.jorel.commandapi.annotations.reloaded.annotations.Subcommand; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRule; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRuleContext; + +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.TypeMirror; + +/** + * A semantic rule that checks that top-level sub-commands extend a command or sub-command class + */ +public class RuleTopLevelSubCommandClassesMustExtendCommandOrSubcommandClass implements SemanticRule { + + @Override + public boolean passes(SemanticRuleContext context) { + AnnotationUtils utils = context.annotationUtils(); + boolean passes = true; + for (Element element : context.roundEnv().getElementsAnnotatedWith(Subcommand.class)) { + if (element instanceof TypeElement subcommandElement) { + Element enclosingElement = subcommandElement.getEnclosingElement(); + if (enclosingElement.getKind() == ElementKind.PACKAGE) { + TypeMirror parentClass = subcommandElement.getSuperclass(); + if (parentClass instanceof TypeElement parentElement) { + if (!utils.hasAnyAnnotation(parentElement, Command.class, Subcommand.class)) { + context.logging().complain(subcommandElement, + "Top-level " + Subcommand.class.getSimpleName() + + " classes must extend a class with " + Command.class.getSimpleName() + + " or " + Subcommand.class.getSimpleName() + + " that has a " + ExternalSubcommand.class.getSimpleName() + + " pointing to it, but " + parentElement.getQualifiedName() + + " is not a " + Command.class.getSimpleName() + "" + + " or " + Subcommand.class.getSimpleName() + ); + passes = false; + } + } + } + } + } + return passes; + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/RuleTopLevelSubCommandClassesMustExtendParentClassWithExternalSubcommand.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/RuleTopLevelSubCommandClassesMustExtendParentClassWithExternalSubcommand.java new file mode 100644 index 0000000000..8c30df1179 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/RuleTopLevelSubCommandClassesMustExtendParentClassWithExternalSubcommand.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.subcommands; + +import dev.jorel.commandapi.annotations.reloaded.AnnotationUtils; +import dev.jorel.commandapi.annotations.reloaded.annotations.Command; +import dev.jorel.commandapi.annotations.reloaded.annotations.ExternalSubcommand; +import dev.jorel.commandapi.annotations.reloaded.annotations.Subcommand; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRule; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRuleContext; + +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.TypeMirror; +import javax.lang.model.util.Elements; +import javax.lang.model.util.Types; + +/** + * A semantic rule that checks that top-level sub-commands extend a class that points to it as an external sub-command + */ +public class RuleTopLevelSubCommandClassesMustExtendParentClassWithExternalSubcommand implements SemanticRule { + + private boolean isLinkedExternalSubcommand(SemanticRuleContext context, TypeElement subcommandElement, TypeElement parentElement) { + AnnotationUtils utils = context.annotationUtils(); + Elements elementUtils = context.processingEnv().getElementUtils(); + Types typeUtils = context.processingEnv().getTypeUtils(); + String className = elementUtils.getBinaryName(subcommandElement).toString(); + return utils.getEnclosedElementsWithAnnotation(parentElement, ExternalSubcommand.class) + .stream() + .flatMap(it -> utils.getAnnotationClassValue(it, ExternalSubcommand.class).stream()) + .map(typeUtils::asElement) + .map(TypeElement.class::cast) + .map(TypeElement::getQualifiedName) + .map(Object::toString) + .anyMatch(className::equals); + } + + @Override + public boolean passes(SemanticRuleContext context) { + boolean passes = true; + for (Element element : context.roundEnv().getElementsAnnotatedWith(Subcommand.class)) { + if (element instanceof TypeElement subcommandElement) { + Element enclosingElement = subcommandElement.getEnclosingElement(); + if (enclosingElement.getKind() == ElementKind.PACKAGE) { + TypeMirror parentClass = subcommandElement.getSuperclass(); + if (parentClass instanceof TypeElement parentElement) { + if (!isLinkedExternalSubcommand(context, subcommandElement, parentElement)) { + context.logging().complain(subcommandElement, + "Top-level " + Subcommand.class.getSimpleName() + + " classes must extend a class with " + Command.class.getSimpleName() + + " or " + Subcommand.class.getSimpleName() + + " that has a " + ExternalSubcommand.class.getSimpleName() + + " pointing to it, but " + parentElement.getQualifiedName() + + " does not have a " + ExternalSubcommand.class.getSimpleName() + + " pointing back to this" + ); + passes = false; + } + } + } + } + } + return passes; + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/RuleTopLevelSubCommandClassesMustHaveASuperClass.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/RuleTopLevelSubCommandClassesMustHaveASuperClass.java new file mode 100644 index 0000000000..159fe951c1 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/RuleTopLevelSubCommandClassesMustHaveASuperClass.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.subcommands; + +import dev.jorel.commandapi.annotations.reloaded.annotations.Command; +import dev.jorel.commandapi.annotations.reloaded.annotations.ExternalSubcommand; +import dev.jorel.commandapi.annotations.reloaded.annotations.Subcommand; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRule; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRuleContext; + +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.TypeKind; +import javax.lang.model.type.TypeMirror; + +/** + * A semantic rule that checks that top-level sub-commands extend a class + */ +public class RuleTopLevelSubCommandClassesMustHaveASuperClass implements SemanticRule { + + @Override + public boolean passes(SemanticRuleContext context) { + boolean passes = true; + for (Element element : context.roundEnv().getElementsAnnotatedWith(Subcommand.class)) { + if (element instanceof TypeElement subcommandElement) { + Element enclosingElement = subcommandElement.getEnclosingElement(); + if (enclosingElement.getKind() == ElementKind.PACKAGE) { + TypeMirror parentClass = subcommandElement.getSuperclass(); + if (parentClass.getKind() == TypeKind.NONE) { + context.logging().complain(subcommandElement, + "Top-level " + Subcommand.class.getSimpleName() + + " classes must extend a class with " + Command.class.getSimpleName() + + " or " + Subcommand.class.getSimpleName() + + " that has a " + ExternalSubcommand.class.getSimpleName() + + " pointing to it, but this extends nothing" + ); + passes = false; + } + } + } + } + return passes; + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/RuleTypeSubCommandsCanOnlyGoOnNormalClasses.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/RuleTypeSubCommandsCanOnlyGoOnNormalClasses.java new file mode 100644 index 0000000000..6d49efad15 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/RuleTypeSubCommandsCanOnlyGoOnNormalClasses.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.subcommands; + +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRule; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRuleContext; +import dev.jorel.commandapi.annotations.reloaded.annotations.Subcommand; + +import javax.lang.model.element.Element; +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.TypeElement; + +/** + * Semantic check that sub-commands can only go on normal classes. I.e. not enums, records etc + */ +public class RuleTypeSubCommandsCanOnlyGoOnNormalClasses implements SemanticRule { + + @Override + public boolean passes(SemanticRuleContext context) { + boolean passes = true; + for (Element element : context.roundEnv().getElementsAnnotatedWith(Subcommand.class)) { + if (element instanceof TypeElement classElement) { + if (classElement.getKind() != ElementKind.CLASS) { + context.logging().complain(classElement, + "@%s cannot go on %s types" + .formatted( + Subcommand.class.getSimpleName(), + classElement.getKind() + ) + ); + passes = false; + } + } + } + return passes; + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandClassGeneratorContext.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandClassGeneratorContext.java new file mode 100644 index 0000000000..7c32ff0279 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandClassGeneratorContext.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.subcommands; + +import dev.jorel.commandapi.annotations.reloaded.generators.GeneratorContext; +import dev.jorel.commandapi.annotations.reloaded.modules.commands.CommandExecutorsGeneratorContext; + +/** + * Context needed to generate all the sub-command registration invocations for a CommandAPI command class + * + * @param subcommandMethods Context needed to generate all the method-based sub-command registration invocations + * @param subcommandClasses Context needed to generate all the class-based sub-command registration invocations + * @param commandExecutors Context needed to generate all the method-based command registration invocations + */ +public record SubcommandClassGeneratorContext( + SubcommandMethodsGeneratorContext subcommandMethods, + SubcommandClassesGeneratorContext subcommandClasses, + CommandExecutorsGeneratorContext commandExecutors +) implements GeneratorContext { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandClassModule.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandClassModule.java new file mode 100644 index 0000000000..81bf32fd52 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandClassModule.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.subcommands; + +import dev.jorel.commandapi.annotations.reloaded.Logging; +import dev.jorel.commandapi.annotations.reloaded.annotations.Command; +import dev.jorel.commandapi.annotations.reloaded.generators.IndentedWriter; +import dev.jorel.commandapi.annotations.reloaded.modules.commands.CommandExecutorsGeneratorContext; +import dev.jorel.commandapi.annotations.reloaded.parser.ParserUtils; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticAnalyzer; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRule; +import dev.jorel.commandapi.annotations.reloaded.modules.TypeElementAnalyzerParserGeneratorModule; +import dev.jorel.commandapi.annotations.reloaded.modules.commands.CommandExecutorsModule; +import dev.jorel.commandapi.annotations.reloaded.parser.TypeElementParserContext; + +import java.util.List; +import java.util.Optional; + +/** + * Contains everything to do with generating all the CommandAPI command registration invocations for a command class + */ +public class SubcommandClassModule implements TypeElementAnalyzerParserGeneratorModule { + + private final SubcommandClassesModule subcommandClassesModule; + private final SubcommandMethodsModule subcommandMethodsModule; + private final CommandExecutorsModule commandExecutorsModule; + + public SubcommandClassModule( + SubcommandClassesModule subcommandClassesModule, + SubcommandMethodsModule subcommandMethodsModule, + CommandExecutorsModule commandExecutorsModule) { + this.subcommandClassesModule = subcommandClassesModule; + this.subcommandMethodsModule = subcommandMethodsModule; + this.commandExecutorsModule = commandExecutorsModule; + } + + @Override + public Optional parse(TypeElementParserContext context) { + ParserUtils utils = context.utils(); + Logging logging = utils.logging(); + logging.info(context.element(), "Parsing subcommand class"); + Optional maybeSubcommandClasses = subcommandClassesModule.parse(context); + Optional maybeSubcommandMethods = subcommandMethodsModule.parse(context); + Optional maybeCommandExecutors = commandExecutorsModule.parse(context); + if (maybeSubcommandMethods.isEmpty() || + maybeSubcommandClasses.isEmpty() || + maybeCommandExecutors.isEmpty()) { + return Optional.empty(); + } + SubcommandClassesGeneratorContext subcommandClasses = maybeSubcommandClasses.orElseThrow(); + SubcommandMethodsGeneratorContext subcommandMethods = maybeSubcommandMethods.orElseThrow(); + CommandExecutorsGeneratorContext commandExecutors = maybeCommandExecutors.orElseThrow(); + if (subcommandClasses.list().isEmpty() && + subcommandMethods.list().isEmpty() && + commandExecutors.list().isEmpty()) { + logging.warn(context.element(), "@%s class has no executors" + .formatted(Command.class.getSimpleName())); + } + logging.info(context.element(), "Parsed %d subcommand classes, %d subcommand methods, and %d command executors".formatted( + subcommandClasses.list().size(), + subcommandMethods.list().size(), + commandExecutors.list().size() + )); + return Optional.of( + new SubcommandClassGeneratorContext( + subcommandMethods, + subcommandClasses, + commandExecutors + ) + ); + } + + @Override + public void generate(IndentedWriter out, SubcommandClassGeneratorContext context) { + subcommandMethodsModule.generate(out, context.subcommandMethods()); + subcommandClassesModule.generate(out, context.subcommandClasses()); + commandExecutorsModule.generate(out, context.commandExecutors()); + } + + @Override + public List subAnalyzers() { + return List.of( + subcommandClassesModule, + subcommandMethodsModule, + commandExecutorsModule + ); + } + + @Override + public List rules() { + return List.of(); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandClassNamesStackParser.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandClassNamesStackParser.java new file mode 100644 index 0000000000..f61c8b92ac --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandClassNamesStackParser.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.subcommands; + +import dev.jorel.commandapi.annotations.reloaded.modules.commands.CommandNames; +import dev.jorel.commandapi.annotations.reloaded.parser.TypeElementParser; +import dev.jorel.commandapi.annotations.reloaded.parser.TypeElementParserContext; + +import java.util.Deque; +import java.util.Optional; + +/** + * Parses the list of command and sub-command names in the context of a given sub-command class + */ +public class SubcommandClassNamesStackParser implements TypeElementParser> { + @Override + public Optional> parse(TypeElementParserContext context) { + throw new UnsupportedOperationException("Not yet implemented"); //TODO + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandClassesGeneratorContext.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandClassesGeneratorContext.java new file mode 100644 index 0000000000..3dd8eab7ad --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandClassesGeneratorContext.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.subcommands; + +import dev.jorel.commandapi.annotations.reloaded.generators.GeneratorContext; + +import java.util.List; + +/** + * Context needed to generate the list of sub-command registration invocations for a CommandAPI command class + * + * @param list The context needed to generate each sub-command registration invocation + */ +public record SubcommandClassesGeneratorContext( + List list +) implements GeneratorContext { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandClassesModule.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandClassesModule.java new file mode 100644 index 0000000000..98b9c0dc5a --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandClassesModule.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.subcommands; + +import dev.jorel.commandapi.annotations.reloaded.parser.ParserUtils; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticAnalyzer; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRule; +import dev.jorel.commandapi.annotations.reloaded.BackReference; +import dev.jorel.commandapi.annotations.reloaded.annotations.Subcommand; +import dev.jorel.commandapi.annotations.reloaded.generators.IndentedWriter; +import dev.jorel.commandapi.annotations.reloaded.modules.TypeElementAnalyzerParserGeneratorModule; +import dev.jorel.commandapi.annotations.reloaded.parser.TypeElementParserContext; + +import javax.lang.model.element.ElementKind; +import javax.lang.model.element.TypeElement; +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +/** + * Contains everything to do with generating the list of sub-command registration invocations for a CommandAPI command + * class + */ +public class SubcommandClassesModule implements TypeElementAnalyzerParserGeneratorModule { + + // Back-referencing so that we can get subcommand classes at any nesting depth + private final BackReference subcommandClassModuleRef; + + public SubcommandClassesModule( + BackReference subcommandClassModuleRef) { + this.subcommandClassModuleRef = subcommandClassModuleRef; + } + + @Override + public Optional parse(TypeElementParserContext context) { + ParserUtils utils = context.utils(); + List subcommandClasses = context.element() + .getEnclosedElements().stream() + .filter(element -> element.getAnnotation(Subcommand.class) != null) + .filter(element -> element.getKind() == ElementKind.CLASS) + .map(TypeElement.class::cast) + .toList(); + utils.logging().info(context.element(), "Found %d enclosed subcommand classes" + .formatted(subcommandClasses.size())); + if (subcommandClasses.isEmpty()) { + return Optional.of(new SubcommandClassesGeneratorContext(Collections.emptyList())); + } + SubcommandClassModule subcommandClassModule = subcommandClassModuleRef.get(); + List> maybeSubcommands = subcommandClasses.stream() + .map(element -> new TypeElementParserContext(utils, element)) + .map(subcommandClassModule::parse) + .toList(); + if (maybeSubcommands.stream().anyMatch(Optional::isEmpty)) { + return Optional.empty(); + } + return Optional.of( + new SubcommandClassesGeneratorContext( + maybeSubcommands.stream().flatMap(Optional::stream).toList() + ) + ); + } + + @Override + public void generate(IndentedWriter out, SubcommandClassesGeneratorContext context) { + if (context.list().isEmpty()) { + return; + } + SubcommandClassModule subcommandClassModule = subcommandClassModuleRef.get(); + context.list().forEach(subcontext -> subcommandClassModule.generate(out, subcontext)); + } + + @Override + public List subAnalyzers() { + return List.of(); + } + + @Override + public List rules() { + return List.of(); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandMethodNamesStackParser.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandMethodNamesStackParser.java new file mode 100644 index 0000000000..381264469f --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandMethodNamesStackParser.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.subcommands; + +import dev.jorel.commandapi.annotations.reloaded.Logging; +import dev.jorel.commandapi.annotations.reloaded.annotations.Subcommand; +import dev.jorel.commandapi.annotations.reloaded.modules.commands.CommandNames; +import dev.jorel.commandapi.annotations.reloaded.parser.ExecutableElementParser; +import dev.jorel.commandapi.annotations.reloaded.parser.ExecutableElementParserContext; +import dev.jorel.commandapi.annotations.reloaded.parser.ParserUtils; + +import java.util.ArrayDeque; +import java.util.Arrays; +import java.util.Deque; +import java.util.Optional; + +/** + * Parses the list of command and sub-command names in the context of a sub-command method + */ +public class SubcommandMethodNamesStackParser implements ExecutableElementParser> { + @Override + public Optional> parse(ExecutableElementParserContext context) { + ParserUtils utils = context.utils(); + Logging logging = utils.logging(); + Subcommand[] subcommands = context.element().getAnnotationsByType(Subcommand.class); + if (subcommands.length == 0) { + logging.complain(context.element(), "@%s annotation is missing from subcommand method" + .formatted(Subcommand.class.getSimpleName())); + return Optional.empty(); + } + boolean valid = true; + ArrayDeque stack = new ArrayDeque(); + for (Subcommand subcommand : subcommands) { + String[] values = subcommand.value(); + if (values.length == 0) { + logging.complain(context.element(), "@%s annotation on method is missing a value" + .formatted(Subcommand.class.getSimpleName())); + valid = false; + continue; + } + String[] aliases = values.length > 1 ? Arrays.copyOfRange(values, 1, values.length) : new String[0]; + stack.add(new CommandNames(values[0], aliases)); + } + if (!valid) { + return Optional.empty(); + } + return Optional.of(stack); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandMethodsGeneratorContext.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandMethodsGeneratorContext.java new file mode 100644 index 0000000000..1692c1591d --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandMethodsGeneratorContext.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.subcommands; + +import dev.jorel.commandapi.annotations.reloaded.generators.GeneratorContext; +import dev.jorel.commandapi.annotations.reloaded.modules.commands.CommandExecutorMethodGeneratorContext; + +import java.util.List; + +/** + * Context needed to generate all the CommandAPI command registrations for method annotations + * + * @param list The context needed to generate each command registration + */ +public record SubcommandMethodsGeneratorContext( + List list +) implements GeneratorContext { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandMethodsModule.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandMethodsModule.java new file mode 100644 index 0000000000..51e330b601 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandMethodsModule.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.subcommands; + +import dev.jorel.commandapi.annotations.reloaded.AnnotationUtils; +import dev.jorel.commandapi.annotations.reloaded.generators.IndentedWriter; +import dev.jorel.commandapi.annotations.reloaded.modules.commands.CommandExecutorMethodGeneratorContext; +import dev.jorel.commandapi.annotations.reloaded.parser.ParserUtils; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticAnalyzer; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRule; +import dev.jorel.commandapi.annotations.reloaded.annotations.Subcommand; +import dev.jorel.commandapi.annotations.reloaded.modules.TypeElementAnalyzerParserGeneratorModule; +import dev.jorel.commandapi.annotations.reloaded.modules.commands.CommandExecutorMethodModule; +import dev.jorel.commandapi.annotations.reloaded.parser.ExecutableElementParserContext; +import dev.jorel.commandapi.annotations.reloaded.parser.TypeElementParserContext; + +import java.util.List; +import java.util.Optional; + +/** + * Contains everything to do with generating the CommandAPI command registrations for sub-command method annotations + */ +public class SubcommandMethodsModule implements TypeElementAnalyzerParserGeneratorModule { + private final CommandExecutorMethodModule commandExecutorMethodModule; + + public SubcommandMethodsModule(CommandExecutorMethodModule commandExecutorMethodModule) { + this.commandExecutorMethodModule = commandExecutorMethodModule; + } + + @Override + public Optional parse(TypeElementParserContext context) { + ParserUtils utils = context.utils(); + AnnotationUtils annotationUtils = utils.annotationUtils(); + List> maybeSubcommands = annotationUtils + .getEnclosedMethodsWithAnnotation(context.element(), Subcommand.class).stream() + .map(element -> new ExecutableElementParserContext(utils, element)) + .map(commandExecutorMethodModule::parse) + .toList(); + if (maybeSubcommands.stream().anyMatch(Optional::isEmpty)) { + return Optional.empty(); + } + return Optional.of( + new SubcommandMethodsGeneratorContext( + maybeSubcommands.stream().flatMap(Optional::stream).toList() + ) + ); + } + + @Override + public void generate(IndentedWriter out, SubcommandMethodsGeneratorContext context) { + context.list().forEach(subcontext -> commandExecutorMethodModule.generate(out, subcontext)); + } + + @Override + public List subAnalyzers() { + return List.of( + commandExecutorMethodModule + ); + } + + @Override + public List rules() { + return List.of(); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandsGeneratorContext.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandsGeneratorContext.java new file mode 100644 index 0000000000..6551ff6e66 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandsGeneratorContext.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.subcommands; + +import dev.jorel.commandapi.annotations.reloaded.generators.GeneratorContext; + +/** + * Context needed to generate all the CommandAPI command registrations for sub-command annotations + * + * @param subcommandClass The context needed to generate all the CommandAPI command registrations for command class + */ +public record SubcommandsGeneratorContext( + SubcommandClassGeneratorContext subcommandClass +) implements GeneratorContext { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandsModule.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandsModule.java new file mode 100644 index 0000000000..8ed293f5fc --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/SubcommandsModule.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.subcommands; + +import dev.jorel.commandapi.annotations.reloaded.generators.IndentedWriter; +import dev.jorel.commandapi.annotations.reloaded.modules.TypeElementAnalyzerParserGeneratorModule; +import dev.jorel.commandapi.annotations.reloaded.parser.TypeElementParserContext; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticAnalyzer; +import dev.jorel.commandapi.annotations.reloaded.semantics.SemanticRule; + +import java.util.List; +import java.util.Optional; + +/** + * Contains everything to do with generating the CommandAPI command registrations for sub-commands + */ +public class SubcommandsModule implements TypeElementAnalyzerParserGeneratorModule { + + private final RuleNonTopLevelTypeSubCommandsMustGoInsideCommandOrSubcommandClasses ruleNonTopLevelTypeSubCommandsMustGoInsideCommandOrSubcommandClasses; + private final RuleNonTopLevelTypeSubcommandsCanOnlyGoInsideClasses ruleNonTopLevelTypeSubcommandsCanOnlyGoInsideClasses; + private final RuleTypeSubCommandsCanOnlyGoOnNormalClasses ruleTypeSubCommandsCanOnlyGoOnNormalClasses; + private final RuleTopLevelSubCommandClassesMustExtendParentClassWithExternalSubcommand ruleTopLevelSubCommandClassesMustExtendParentClassWithExternalSubcommand; + private final RuleTopLevelSubCommandClassesMustHaveASuperClass ruleTopLevelSubCommandClassesMustHaveASuperClass; + private final RuleTopLevelSubCommandClassesMustExtendCommandOrSubcommandClass ruleTopLevelSubCommandClassesMustExtendCommandOrSubcommandClass; + private final SubcommandClassModule subcommandClassModule; + + public SubcommandsModule( + RuleNonTopLevelTypeSubCommandsMustGoInsideCommandOrSubcommandClasses ruleNonTopLevelTypeSubCommandsMustGoInsideCommandOrSubcommandClasses, + RuleNonTopLevelTypeSubcommandsCanOnlyGoInsideClasses ruleNonTopLevelTypeSubcommandsCanOnlyGoInsideClasses, + RuleTypeSubCommandsCanOnlyGoOnNormalClasses ruleTypeSubCommandsCanOnlyGoOnNormalClasses, + RuleTopLevelSubCommandClassesMustExtendParentClassWithExternalSubcommand ruleTopLevelSubCommandClassesMustExtendParentClassWithExternalSubcommand, + RuleTopLevelSubCommandClassesMustHaveASuperClass ruleTopLevelSubCommandClassesMustHaveASuperClass, + RuleTopLevelSubCommandClassesMustExtendCommandOrSubcommandClass ruleTopLevelSubCommandClassesMustExtendCommandOrSubcommandClass, + SubcommandClassModule subcommandClassModule + ) { + this.ruleNonTopLevelTypeSubCommandsMustGoInsideCommandOrSubcommandClasses = ruleNonTopLevelTypeSubCommandsMustGoInsideCommandOrSubcommandClasses; + this.ruleNonTopLevelTypeSubcommandsCanOnlyGoInsideClasses = ruleNonTopLevelTypeSubcommandsCanOnlyGoInsideClasses; + this.ruleTypeSubCommandsCanOnlyGoOnNormalClasses = ruleTypeSubCommandsCanOnlyGoOnNormalClasses; + this.ruleTopLevelSubCommandClassesMustExtendParentClassWithExternalSubcommand = ruleTopLevelSubCommandClassesMustExtendParentClassWithExternalSubcommand; + this.ruleTopLevelSubCommandClassesMustHaveASuperClass = ruleTopLevelSubCommandClassesMustHaveASuperClass; + this.ruleTopLevelSubCommandClassesMustExtendCommandOrSubcommandClass = ruleTopLevelSubCommandClassesMustExtendCommandOrSubcommandClass; + this.subcommandClassModule = subcommandClassModule; + } + + @Override + public Optional parse(TypeElementParserContext context) { + Optional maybeSubcommandClass = subcommandClassModule.parse(context); + if (maybeSubcommandClass.isEmpty()) { + return Optional.empty(); + } + return Optional.of( + new SubcommandsGeneratorContext( + maybeSubcommandClass.orElseThrow() + ) + ); + } + + @Override + public void generate(IndentedWriter out, SubcommandsGeneratorContext context) { + subcommandClassModule.generate(out, context.subcommandClass()); + } + + @Override + public List subAnalyzers() { + return List.of( + subcommandClassModule + ); + } + + @Override + public List rules() { + return List.of( + ruleNonTopLevelTypeSubCommandsMustGoInsideCommandOrSubcommandClasses, + ruleNonTopLevelTypeSubcommandsCanOnlyGoInsideClasses, + ruleTypeSubCommandsCanOnlyGoOnNormalClasses, + ruleTopLevelSubCommandClassesMustHaveASuperClass, + ruleTopLevelSubCommandClassesMustExtendCommandOrSubcommandClass, + ruleTopLevelSubCommandClassesMustExtendParentClassWithExternalSubcommand + ); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/package-info.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/package-info.java new file mode 100644 index 0000000000..9d283a34b7 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/modules/subcommands/package-info.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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. + *******************************************************************************/ +/** + * Components for generating CommandAPI command registrations from annotations + */ +@ParametersAreNonnullByDefault +@ReturnTypesAreNonnullByDefault +package dev.jorel.commandapi.annotations.reloaded.modules.subcommands; + +import javax.annotation.ParametersAreNonnullByDefault; +import dev.jorel.commandapi.annotations.reloaded.ReturnTypesAreNonnullByDefault; \ No newline at end of file diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/package-info.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/package-info.java new file mode 100644 index 0000000000..de554bdb4a --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/package-info.java @@ -0,0 +1,30 @@ +/** + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + *

+ * 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. + *

+ * Annotations which can be used with the CommandAPI annotation system. + */ +/** + * Annotations which can be used with the CommandAPI annotation system. + */ +@ParametersAreNonnullByDefault +@ReturnTypesAreNonnullByDefault +package dev.jorel.commandapi.annotations.reloaded; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/AnnotationParser.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/AnnotationParser.java new file mode 100644 index 0000000000..5337a49b8b --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/AnnotationParser.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.parser; + +import javax.lang.model.element.Element; +import java.util.Optional; + +/** + * Interface for parsing a CommandAPI annotation and retrieving some data. + * + * @param The type of element that the annotation is applied to + * @param The type of contextual information needed to parse the data + * @param The type of data returned + */ +public interface AnnotationParser< + AnElement extends Element, + AParserContext extends AnnotationParserContext, + AReturnType + > { + + /** + * Parse the given contextual information and attempt to retrieve data. + * + * @param context The context needed to retrieve the data + * @return The data, if it could be retrieved, or empty if it couldn't + */ + Optional parse(AParserContext context); +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/AnnotationParserContext.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/AnnotationParserContext.java new file mode 100644 index 0000000000..d0b03557d7 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/AnnotationParserContext.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.parser; + +import javax.lang.model.element.Element; + +/** + * Interface that sets the basic minimum context needed for parsing data from an annotation. + * + * @param The type of element the annotation is applied to + */ +public interface AnnotationParserContext { + /** + * @return A set of utilities to help with parsing data related to annotations + */ + ParserUtils utils(); + + /** + * @return The element that the annotation is applied to + */ + AnElement element(); +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/ExecutableElementParser.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/ExecutableElementParser.java new file mode 100644 index 0000000000..4f1237c0a1 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/ExecutableElementParser.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.parser; + +import javax.lang.model.element.ExecutableElement; + +/** + * A convenience interface for {@link AnnotationParser} for annotations that are applied to executable + * elements such as methods. + */ +public interface ExecutableElementParser extends AnnotationParser { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/ExecutableElementParserContext.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/ExecutableElementParserContext.java new file mode 100644 index 0000000000..108fb9a5ed --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/ExecutableElementParserContext.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.parser; + +import javax.lang.model.element.ExecutableElement; + +/** + * A generic context for parsing data from an annotated method + */ +public record ExecutableElementParserContext( + ParserUtils utils, + ExecutableElement element +) implements AnnotationParserContext { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/GenericElementParserContext.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/GenericElementParserContext.java new file mode 100644 index 0000000000..fcf8b80ff2 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/GenericElementParserContext.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.parser; + +import javax.lang.model.element.Element; + +/** + * A generic context for parsing data from an annotated element of any type + */ +public record GenericElementParserContext( + ParserUtils utils, + Element element +) implements AnnotationParserContext { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/ImportsBuilder.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/ImportsBuilder.java new file mode 100644 index 0000000000..ed6e015f65 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/ImportsBuilder.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.parser; + +import javax.lang.model.element.TypeElement; +import java.util.Set; + +/** + * Allows the parser to generate a set of imports from TypeMirrors for everything, so it's all one (near-linear) + * operation. + */ +public interface ImportsBuilder { + /** + * Adds the fully-qualified name of the class to the list of imports, while providing the short-form where possible + * so that it can be used in the generated code. If classes of the same name from different packages are imported, + * this will be handled without causing errors. + * + * @param clazz The class to import into the generated class + * @return The in-line reference to the class + */ + String withImport(Class clazz); + + /** + * Adds the fully-qualified name of the class to the list of imports, while providing the short-form where possible + * so that it can be used in the generated code. If classes of the same name from different packages are imported, + * this will be handled without causing errors. + * + * @param typeElement The type mirror of the class to import into the generated class + * @return The in-line reference to the class + */ + String withImport(TypeElement typeElement); + + /** + * @return A complete list of all classes to add imports for + */ + Set getAllFullyQualifiedNames(); +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/ImportsBuilderImpl.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/ImportsBuilderImpl.java new file mode 100644 index 0000000000..246b2bc281 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/ImportsBuilderImpl.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.parser; + +import javax.lang.model.element.Name; +import javax.lang.model.element.TypeElement; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +/** + * Default implementation for building a set of imports for a generated class. + *

+ * In case of class name conflicts, the first package will get the import and use the simple name, whereas all + * additional packages will use a qualified name. + */ +public class ImportsBuilderImpl implements ImportsBuilder { + private final Map imports; + + public ImportsBuilderImpl() { + this(new HashMap<>()); + } + + ImportsBuilderImpl(Map imports) { + this.imports = imports; + } + + String withImport(String simpleName, String qualifiedName) { + if (imports.containsKey(simpleName)) { + if (imports.get(simpleName).equals(qualifiedName)) { + return simpleName; // We already imported this + } + return qualifiedName; // Conflicting name, can't import so use fully qualified name instead + } + imports.put(simpleName, qualifiedName); + return simpleName; + } + + @Override + public String withImport(Class clazz) { + return withImport(clazz.getSimpleName(), clazz.getCanonicalName()); + } + + @Override + public String withImport(TypeElement typeElement) { + String simpleName = typeElement.getSimpleName().toString(); + Name qualifiedName = typeElement.getQualifiedName(); + if (qualifiedName.isEmpty()) { + throw new IllegalArgumentException("You can't import an element with no qualified name: %s" + .formatted(typeElement)); + } + return withImport(simpleName, qualifiedName.toString()); + } + + @Override + public Set getAllFullyQualifiedNames() { + return new TreeSet<>(imports.values()); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/ParserUtils.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/ParserUtils.java new file mode 100644 index 0000000000..5de0832768 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/ParserUtils.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.parser; + +import dev.jorel.commandapi.annotations.reloaded.AnnotationUtils; +import dev.jorel.commandapi.annotations.reloaded.Logging; + +import javax.annotation.processing.ProcessingEnvironment; + +/** + * Utilities to help with parsing annotated elements + * + * @param logging The logger for the annotation processor + * @param processingEnv The annotation processing environment + * @param imports The imports builder for the generated class + * @param annotationUtils Utilities for working with java annotations + */ +public record ParserUtils( + Logging logging, + + ProcessingEnvironment processingEnv, + + ImportsBuilder imports, + + AnnotationUtils annotationUtils +) { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/TypeElementParser.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/TypeElementParser.java new file mode 100644 index 0000000000..47c00f1864 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/TypeElementParser.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.parser; + +import javax.lang.model.element.TypeElement; + +/** + * A convenience interface for {@link AnnotationParser} for annotations that are applied to type + * elements such as classes. + */ +public interface TypeElementParser extends AnnotationParser { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/TypeElementParserContext.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/TypeElementParserContext.java new file mode 100644 index 0000000000..62c8c6c53c --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/TypeElementParserContext.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.parser; + +import javax.lang.model.element.TypeElement; + +/** + * A generic context for parsing data from an annotated class + */ +public record TypeElementParserContext( + ParserUtils utils, + TypeElement element +) implements AnnotationParserContext { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/VariableElementParserContext.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/VariableElementParserContext.java new file mode 100644 index 0000000000..605aebd144 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/VariableElementParserContext.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.parser; + +import javax.lang.model.element.VariableElement; + +/** + * A generic context for parsing data from an annotated field + */ +public record VariableElementParserContext( + ParserUtils utils, + VariableElement element +) implements AnnotationParserContext { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/package-info.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/package-info.java new file mode 100644 index 0000000000..a528a69691 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/parser/package-info.java @@ -0,0 +1,32 @@ +/** + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + *

+ * 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. + *

+ * Components for parsing annotated elements + */ +/** + * Components for parsing annotated elements + */ +@ParametersAreNonnullByDefault +@ReturnTypesAreNonnullByDefault +package dev.jorel.commandapi.annotations.reloaded.parser; + +import javax.annotation.ParametersAreNonnullByDefault; + +import dev.jorel.commandapi.annotations.reloaded.ReturnTypesAreNonnullByDefault; diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/semantics/SemanticAnalyzer.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/semantics/SemanticAnalyzer.java new file mode 100644 index 0000000000..e43f9e3bee --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/semantics/SemanticAnalyzer.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.semantics; + +import java.util.List; + +/** + * Interface for analysing semantic rules for a feature of the CommandAPI annotation parser + */ +public interface SemanticAnalyzer { + /** + * @return A list of semantic analysers for sub-features + */ + List subAnalyzers(); + + /** + * @return A list of semantic rules to apply for this feature + */ + List rules(); + + /** + * @return A name to use for this analyser in logs + */ + default String getName() { + return getClass().getSimpleName(); + } + + /** + * @param context The context needed to analyse the set of semantic rules + * @return True, if all rules pass, or false, if any rule fails + */ + default boolean allPass(SemanticRuleContext context) { + context.logging().info("Performing %s semantic checks".formatted(getName())); + boolean passing = true; + for (SemanticRule rule : rules()) { + if (rule.fails(context)) { + passing = false; + // Do not fail fast, we want full logs + } + } + context.logging().info("%s semantic checks %s".formatted(getName(), passing ? "passed" : "failed")); + for (SemanticAnalyzer analyzer : subAnalyzers()) { + if (analyzer.anyFail(context)) { + passing = false; + // Do not fail fast, we want full logs + } + } + return passing; + } + + /** + * @param context The context needed to analyse the set of semantic rules + * @return True, if any rule fails, or false, if all rule pass. + */ + default boolean anyFail(SemanticRuleContext context) { + return !allPass(context); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/semantics/SemanticRule.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/semantics/SemanticRule.java new file mode 100644 index 0000000000..02afe504d1 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/semantics/SemanticRule.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.semantics; + +/** + * Interface for a basic semantic rule check for the CommandAPI annotation system + */ +public interface SemanticRule { + /** + * @param context The context needed to analyse this rule + * @return True, if the rule is satisfied, otherwise false + */ + boolean passes(SemanticRuleContext context); + + /** + * @param context The context needed to analyse this rule + * @return True, if the rule is not satisfied, otherwise false + */ + default boolean fails(SemanticRuleContext context) { + return !passes(context); + } +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/semantics/SemanticRuleContext.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/semantics/SemanticRuleContext.java new file mode 100644 index 0000000000..6ffa7e5ef3 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/semantics/SemanticRuleContext.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.semantics; + +import dev.jorel.commandapi.annotations.reloaded.AnnotationUtils; +import dev.jorel.commandapi.annotations.reloaded.Logging; + +import javax.annotation.processing.ProcessingEnvironment; +import javax.annotation.processing.RoundEnvironment; + +/** + * Context needed to analyse a semantic rule for the CommandAPI annotation system + */ +public interface SemanticRuleContext { + /** + * @return The logger for the annotations processor + */ + Logging logging(); + + /** + * @return The environment information for the annotations processor + */ + ProcessingEnvironment processingEnv(); + + /** + * @return The environment information for this round of the annotations processor + */ + RoundEnvironment roundEnv(); + + /** + * @return A set of utilities for working with java annotations + */ + AnnotationUtils annotationUtils(); +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/semantics/SemanticRuleContextData.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/semantics/SemanticRuleContextData.java new file mode 100644 index 0000000000..062955f118 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/semantics/SemanticRuleContextData.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.semantics; + +import dev.jorel.commandapi.annotations.reloaded.AnnotationUtils; +import dev.jorel.commandapi.annotations.reloaded.Logging; + +import javax.annotation.processing.ProcessingEnvironment; +import javax.annotation.processing.RoundEnvironment; + +/** + * A generic context for analysing a semantic rule for the CommandAPI annotation system + */ +public record SemanticRuleContextData( + Logging logging, + ProcessingEnvironment processingEnv, + RoundEnvironment roundEnv, + AnnotationUtils annotationUtils +) implements SemanticRuleContext { +} diff --git a/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/semantics/package-info.java b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/semantics/package-info.java new file mode 100644 index 0000000000..d7a1eb9472 --- /dev/null +++ b/commandapi-annotations-reloaded/src/main/java/dev/jorel/commandapi/annotations/reloaded/semantics/package-info.java @@ -0,0 +1,34 @@ +/** + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + *

+ * 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. + *

+ * Annotations which can be used with the CommandAPI annotation system. + *

+ * Components for applying semantic rule checks for the CommandAPI annotation system + */ +/** + * Components for applying semantic rule checks for the CommandAPI annotation system + */ +@ParametersAreNonnullByDefault +@ReturnTypesAreNonnullByDefault +package dev.jorel.commandapi.annotations.reloaded.semantics; + +import dev.jorel.commandapi.annotations.reloaded.ReturnTypesAreNonnullByDefault; + +import javax.annotation.ParametersAreNonnullByDefault; \ No newline at end of file diff --git a/commandapi-annotations-reloaded/src/test/java/dev/jorel/commandapi/annotations/reloaded/modules/base/CommandsClassJavadocGeneratorTest.java b/commandapi-annotations-reloaded/src/test/java/dev/jorel/commandapi/annotations/reloaded/modules/base/CommandsClassJavadocGeneratorTest.java new file mode 100644 index 0000000000..1ce7ddb8d0 --- /dev/null +++ b/commandapi-annotations-reloaded/src/test/java/dev/jorel/commandapi/annotations/reloaded/modules/base/CommandsClassJavadocGeneratorTest.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright 2018, 2020 Jorel Ali (Skepter) - MIT License + * + * 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 dev.jorel.commandapi.annotations.reloaded.modules.base; + +import dev.jorel.commandapi.annotations.reloaded.generators.IndentedWriter; +import dev.jorel.commandapi.annotations.reloaded.modules.commands.CommandRegisterMethodGeneratorContext; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.time.Month; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.util.Iterator; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +@ExtendWith(MockitoExtension.class) +class CommandsClassJavadocGeneratorTest { + + CommandsClassJavadocGenerator generator; + + @BeforeEach + void setUp() { + generator = new CommandsClassJavadocGenerator(); + } + + @Test + void generate( + @Mock IndentedWriter out, + @Captor ArgumentCaptor outputLines, + @Mock CommandsClassGeneratorContext context, + @Mock CommandRegisterMethodGeneratorContext method1, + @Mock CommandRegisterMethodGeneratorContext method2, + @Mock CommandRegisterMethodGeneratorContext method3 + ) { + ZonedDateTime generatorStarted = ZonedDateTime.of(2024, Month.APRIL.getValue(), 20, + 17, 57, 23, 123456789, ZoneOffset.UTC); + doReturn(generatorStarted).when(context).generatorStarted(); + doReturn(List.of(method1, method2, method3)).when(context).registerMethods(); + doReturn("my.package.name.MyCommand").when(method1).qualifiedCommandClassName(); + doReturn("my.package.name.MyOtherCommand").when(method2).qualifiedCommandClassName(); + doReturn("my.package.name.other.SomeCommand").when(method3).qualifiedCommandClassName(); + generator.generate(out, context); + verify(out, times(8)).printOnNewLine(outputLines.capture()); + Iterator outputsIterator = outputLines.getAllValues().iterator(); + assertEquals("/**", outputsIterator.next()); + assertEquals(" * This class was automatically generated by the CommandAPI", outputsIterator.next()); + assertEquals(" * Generation time: Sat Apr 20 17:57:23 Z 2024", outputsIterator.next()); + assertEquals(" * @Command classes used:", outputsIterator.next()); + assertEquals(" * - {@link my.package.name.MyCommand}", outputsIterator.next()); + assertEquals(" * - {@link my.package.name.MyOtherCommand}", outputsIterator.next()); + assertEquals(" * - {@link my.package.name.other.SomeCommand}", outputsIterator.next()); + assertEquals(" */", outputsIterator.next()); + } +} \ No newline at end of file diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandPermission.java b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandPermission.java index adcdcb884c..6e62f2b258 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/CommandPermission.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/CommandPermission.java @@ -23,6 +23,8 @@ import java.util.Objects; import java.util.Optional; +import javax.annotation.Nullable; + /** * A representation of permission nodes for commands. Represents permission * nodes, being op and having all permissions @@ -143,11 +145,12 @@ public boolean isNegated() { return this.negated; } + @Nullable PermissionNode getPermissionNode() { return this.permissionNode; } - CommandPermission negate() { + public CommandPermission negate() { this.negated = true; return this; } diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/ArgumentSuggestions.java b/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/ArgumentSuggestions.java index 3133325794..f0437cb437 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/ArgumentSuggestions.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/ArgumentSuggestions.java @@ -19,7 +19,7 @@ // change the spaces into tabs! /* ANCHOR: Declaration */ @FunctionalInterface -public interface ArgumentSuggestions { +public interface ArgumentSuggestions extends ISuggestions { /** * Create a {@link CompletableFuture} resolving onto a brigadier {@link Suggestions} object. diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/ISuggestions.java b/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/ISuggestions.java new file mode 100644 index 0000000000..fc7b999f62 --- /dev/null +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/ISuggestions.java @@ -0,0 +1,11 @@ +package dev.jorel.commandapi.arguments; + +/** + * Parent interface of Suggestions for annotations + * + * Apparently rawtype warnings are unavoidable here. See + * https://stackoverflow.com/questions/69491202/how-to-use-sealed-classes-with-generics + */ +public interface ISuggestions { + +} \ No newline at end of file diff --git a/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/SafeSuggestions.java b/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/SafeSuggestions.java index 4680fd08d3..d0060c36f7 100644 --- a/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/SafeSuggestions.java +++ b/commandapi-core/src/main/java/dev/jorel/commandapi/arguments/SafeSuggestions.java @@ -17,7 +17,7 @@ * @param the type of the suggestions */ @FunctionalInterface -public interface SafeSuggestions { +public interface SafeSuggestions extends ISuggestions { /** * Convert this {@link SafeSuggestions} object into an {@link ArgumentSuggestions} by mapping the values with a string diff --git a/pom.xml b/pom.xml index bb76fa5e3d..3bab327703 100644 --- a/pom.xml +++ b/pom.xml @@ -67,6 +67,8 @@ commandapi-annotations + commandapi-annotations-reloaded + commandapi-annotations-reloaded-tests commandapi-codecov