From 9585aaf0b333b6a4e1e639cf0807da4f36ee447f Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Wed, 24 Sep 2014 11:30:13 +0200 Subject: [PATCH] Added ArgumentValidationException as separate from illegal syntax --- .../commands/arguments/CommandArgumentType.java | 5 +++-- .../commands/arguments/IntegerArgumentType.java | 11 ++++++----- .../exceptions/ArgumentValidationException.java | 4 ++++ .../exceptions/IllegalArgumentSyntaxException.java | 4 ++++ .../exceptions/IllegalCommandArgumentException.java | 4 ---- .../minecraft/commands/tree/ArgumentCommandNode.java | 9 +++++---- .../java/net/minecraft/commands/tree/CommandNode.java | 5 +++-- .../minecraft/commands/tree/LiteralCommandNode.java | 11 ++++++----- .../commands/arguments/IntegerArgumentTypeTest.java | 9 +++++---- .../commands/tree/ArgumentCommandNodeTest.java | 8 ++++---- .../commands/tree/LiteralCommandNodeTest.java | 8 ++++---- 11 files changed, 44 insertions(+), 34 deletions(-) create mode 100644 src/main/java/net/minecraft/commands/exceptions/ArgumentValidationException.java create mode 100644 src/main/java/net/minecraft/commands/exceptions/IllegalArgumentSyntaxException.java delete mode 100644 src/main/java/net/minecraft/commands/exceptions/IllegalCommandArgumentException.java diff --git a/src/main/java/net/minecraft/commands/arguments/CommandArgumentType.java b/src/main/java/net/minecraft/commands/arguments/CommandArgumentType.java index 7ba56c3..875f51f 100644 --- a/src/main/java/net/minecraft/commands/arguments/CommandArgumentType.java +++ b/src/main/java/net/minecraft/commands/arguments/CommandArgumentType.java @@ -1,9 +1,10 @@ package net.minecraft.commands.arguments; -import net.minecraft.commands.exceptions.IllegalCommandArgumentException; +import net.minecraft.commands.exceptions.ArgumentValidationException; +import net.minecraft.commands.exceptions.IllegalArgumentSyntaxException; public interface CommandArgumentType { - CommandArgumentParseResult parse(String command) throws IllegalCommandArgumentException; + CommandArgumentParseResult parse(String command) throws IllegalArgumentSyntaxException, ArgumentValidationException; class CommandArgumentParseResult { private final String raw; diff --git a/src/main/java/net/minecraft/commands/arguments/IntegerArgumentType.java b/src/main/java/net/minecraft/commands/arguments/IntegerArgumentType.java index 8f4164e..a11f353 100644 --- a/src/main/java/net/minecraft/commands/arguments/IntegerArgumentType.java +++ b/src/main/java/net/minecraft/commands/arguments/IntegerArgumentType.java @@ -1,7 +1,8 @@ package net.minecraft.commands.arguments; import com.google.common.base.Splitter; -import net.minecraft.commands.exceptions.IllegalCommandArgumentException; +import net.minecraft.commands.exceptions.ArgumentValidationException; +import net.minecraft.commands.exceptions.IllegalArgumentSyntaxException; public class IntegerArgumentType implements CommandArgumentType { private static final Splitter SPLITTER = Splitter.on(' ').limit(2); @@ -27,22 +28,22 @@ public class IntegerArgumentType implements CommandArgumentType { } @Override - public CommandArgumentParseResult parse(String command) throws IllegalCommandArgumentException { + public CommandArgumentParseResult parse(String command) throws IllegalArgumentSyntaxException, ArgumentValidationException { String raw = SPLITTER.split(command).iterator().next(); try { int value = Integer.parseInt(raw); if (value < minimum) { - throw new IllegalCommandArgumentException(); + throw new ArgumentValidationException(); } if (value > maximum) { - throw new IllegalCommandArgumentException(); + throw new ArgumentValidationException(); } return new CommandArgumentParseResult(raw, value); } catch (NumberFormatException ignored) { - throw new IllegalCommandArgumentException(); + throw new IllegalArgumentSyntaxException(); } } } diff --git a/src/main/java/net/minecraft/commands/exceptions/ArgumentValidationException.java b/src/main/java/net/minecraft/commands/exceptions/ArgumentValidationException.java new file mode 100644 index 0000000..8fd83a9 --- /dev/null +++ b/src/main/java/net/minecraft/commands/exceptions/ArgumentValidationException.java @@ -0,0 +1,4 @@ +package net.minecraft.commands.exceptions; + +public class ArgumentValidationException extends CommandException { +} diff --git a/src/main/java/net/minecraft/commands/exceptions/IllegalArgumentSyntaxException.java b/src/main/java/net/minecraft/commands/exceptions/IllegalArgumentSyntaxException.java new file mode 100644 index 0000000..e65efb5 --- /dev/null +++ b/src/main/java/net/minecraft/commands/exceptions/IllegalArgumentSyntaxException.java @@ -0,0 +1,4 @@ +package net.minecraft.commands.exceptions; + +public class IllegalArgumentSyntaxException extends CommandException { +} diff --git a/src/main/java/net/minecraft/commands/exceptions/IllegalCommandArgumentException.java b/src/main/java/net/minecraft/commands/exceptions/IllegalCommandArgumentException.java deleted file mode 100644 index 5562a10..0000000 --- a/src/main/java/net/minecraft/commands/exceptions/IllegalCommandArgumentException.java +++ /dev/null @@ -1,4 +0,0 @@ -package net.minecraft.commands.exceptions; - -public class IllegalCommandArgumentException extends CommandException { -} diff --git a/src/main/java/net/minecraft/commands/tree/ArgumentCommandNode.java b/src/main/java/net/minecraft/commands/tree/ArgumentCommandNode.java index a67f722..55a5f18 100644 --- a/src/main/java/net/minecraft/commands/tree/ArgumentCommandNode.java +++ b/src/main/java/net/minecraft/commands/tree/ArgumentCommandNode.java @@ -1,7 +1,8 @@ package net.minecraft.commands.tree; import net.minecraft.commands.arguments.CommandArgumentType; -import net.minecraft.commands.exceptions.IllegalCommandArgumentException; +import net.minecraft.commands.exceptions.ArgumentValidationException; +import net.minecraft.commands.exceptions.IllegalArgumentSyntaxException; public class ArgumentCommandNode extends CommandNode { private final String name; @@ -21,7 +22,7 @@ public class ArgumentCommandNode extends CommandNode { } @Override - public CommandNode parse(String command) throws IllegalCommandArgumentException { + public CommandNode parse(String command) throws IllegalArgumentSyntaxException, ArgumentValidationException { CommandArgumentType.CommandArgumentParseResult parsed = type.parse(command); int start = parsed.getRaw().length() + 1; @@ -31,11 +32,11 @@ public class ArgumentCommandNode extends CommandNode { for (CommandNode node : getChildren()) { try { return node.parse(result); - } catch (IllegalCommandArgumentException ignored) { + } catch (IllegalArgumentSyntaxException ignored) { } } - throw new IllegalCommandArgumentException(); + throw new IllegalArgumentSyntaxException(); } else { return this; } diff --git a/src/main/java/net/minecraft/commands/tree/CommandNode.java b/src/main/java/net/minecraft/commands/tree/CommandNode.java index 47eb258..fa0f360 100644 --- a/src/main/java/net/minecraft/commands/tree/CommandNode.java +++ b/src/main/java/net/minecraft/commands/tree/CommandNode.java @@ -1,7 +1,8 @@ package net.minecraft.commands.tree; import com.google.common.collect.Lists; -import net.minecraft.commands.exceptions.IllegalCommandArgumentException; +import net.minecraft.commands.exceptions.ArgumentValidationException; +import net.minecraft.commands.exceptions.IllegalArgumentSyntaxException; import java.util.List; @@ -16,5 +17,5 @@ public abstract class CommandNode { children.add(node); } - public abstract CommandNode parse(String command) throws IllegalCommandArgumentException; + public abstract CommandNode parse(String command) throws IllegalArgumentSyntaxException, ArgumentValidationException; } diff --git a/src/main/java/net/minecraft/commands/tree/LiteralCommandNode.java b/src/main/java/net/minecraft/commands/tree/LiteralCommandNode.java index bc7b23e..f1f9ed3 100644 --- a/src/main/java/net/minecraft/commands/tree/LiteralCommandNode.java +++ b/src/main/java/net/minecraft/commands/tree/LiteralCommandNode.java @@ -1,6 +1,7 @@ package net.minecraft.commands.tree; -import net.minecraft.commands.exceptions.IllegalCommandArgumentException; +import net.minecraft.commands.exceptions.ArgumentValidationException; +import net.minecraft.commands.exceptions.IllegalArgumentSyntaxException; public class LiteralCommandNode extends CommandNode { private final String literal; @@ -20,7 +21,7 @@ public class LiteralCommandNode extends CommandNode { } @Override - public CommandNode parse(String command) throws IllegalCommandArgumentException { + public CommandNode parse(String command) throws IllegalArgumentSyntaxException, ArgumentValidationException { if (command.startsWith(literal)) { int start = literal.length() + 1; @@ -30,16 +31,16 @@ public class LiteralCommandNode extends CommandNode { for (CommandNode node : getChildren()) { try { return node.parse(result); - } catch (IllegalCommandArgumentException ignored) { + } catch (IllegalArgumentSyntaxException ignored) { } } - throw new IllegalCommandArgumentException(); + throw new IllegalArgumentSyntaxException(); } else { return this; } } else { - throw new IllegalCommandArgumentException(); + throw new IllegalArgumentSyntaxException(); } } } diff --git a/src/main/test/net/minecraft/commands/arguments/IntegerArgumentTypeTest.java b/src/main/test/net/minecraft/commands/arguments/IntegerArgumentTypeTest.java index befc371..77914fe 100644 --- a/src/main/test/net/minecraft/commands/arguments/IntegerArgumentTypeTest.java +++ b/src/main/test/net/minecraft/commands/arguments/IntegerArgumentTypeTest.java @@ -1,6 +1,7 @@ package net.minecraft.commands.arguments; -import net.minecraft.commands.exceptions.IllegalCommandArgumentException; +import net.minecraft.commands.exceptions.ArgumentValidationException; +import net.minecraft.commands.exceptions.IllegalArgumentSyntaxException; import org.junit.Before; import org.junit.Test; @@ -24,12 +25,12 @@ public class IntegerArgumentTypeTest { assertThat(result.getResult(), is(50)); } - @Test(expected = IllegalCommandArgumentException.class) + @Test(expected = IllegalArgumentSyntaxException.class) public void testParseInvalid() throws Exception { type.parse("fifty"); } - @Test(expected = IllegalCommandArgumentException.class) + @Test(expected = ArgumentValidationException.class) public void testParseTooLow() throws Exception { type.parse("-101"); } @@ -42,7 +43,7 @@ public class IntegerArgumentTypeTest { assertThat(result.getResult(), is(-100)); } - @Test(expected = IllegalCommandArgumentException.class) + @Test(expected = ArgumentValidationException.class) public void testParseTooHigh() throws Exception { type.parse("101"); } diff --git a/src/main/test/net/minecraft/commands/tree/ArgumentCommandNodeTest.java b/src/main/test/net/minecraft/commands/tree/ArgumentCommandNodeTest.java index e7f448d..2f79cf6 100644 --- a/src/main/test/net/minecraft/commands/tree/ArgumentCommandNodeTest.java +++ b/src/main/test/net/minecraft/commands/tree/ArgumentCommandNodeTest.java @@ -1,6 +1,6 @@ package net.minecraft.commands.tree; -import net.minecraft.commands.exceptions.IllegalCommandArgumentException; +import net.minecraft.commands.exceptions.IllegalArgumentSyntaxException; import org.junit.Before; import org.junit.Test; @@ -22,7 +22,7 @@ public class ArgumentCommandNodeTest { assertThat((ArgumentCommandNode) node.parse("123"), is(node)); } - @Test(expected = IllegalCommandArgumentException.class) + @Test(expected = IllegalArgumentSyntaxException.class) public void testParseInvalid() throws Exception { node.parse("bar"); } @@ -36,14 +36,14 @@ public class ArgumentCommandNodeTest { assertThat(node.parse("123 123"), is(child)); } - @Test(expected = IllegalCommandArgumentException.class) + @Test(expected = IllegalArgumentSyntaxException.class) public void testParseInvalidChild() throws Exception { node.addChild(argument("bar", integer()).build()); node.parse("123 bar"); } - @Test(expected = IllegalCommandArgumentException.class) + @Test(expected = IllegalArgumentSyntaxException.class) public void testParseNoChildren() throws Exception { node.parse("123 123"); } diff --git a/src/main/test/net/minecraft/commands/tree/LiteralCommandNodeTest.java b/src/main/test/net/minecraft/commands/tree/LiteralCommandNodeTest.java index 72cf6ce..0fa1ef5 100644 --- a/src/main/test/net/minecraft/commands/tree/LiteralCommandNodeTest.java +++ b/src/main/test/net/minecraft/commands/tree/LiteralCommandNodeTest.java @@ -1,6 +1,6 @@ package net.minecraft.commands.tree; -import net.minecraft.commands.exceptions.IllegalCommandArgumentException; +import net.minecraft.commands.exceptions.IllegalArgumentSyntaxException; import org.junit.Before; import org.junit.Test; @@ -23,7 +23,7 @@ public class LiteralCommandNodeTest { assertThat((LiteralCommandNode) node.parse("foo"), is(node)); } - @Test(expected = IllegalCommandArgumentException.class) + @Test(expected = IllegalArgumentSyntaxException.class) public void testParseInvalid() throws Exception { node.parse("bar"); } @@ -37,14 +37,14 @@ public class LiteralCommandNodeTest { assertThat(node.parse("foo 123"), is(child)); } - @Test(expected = IllegalCommandArgumentException.class) + @Test(expected = IllegalArgumentSyntaxException.class) public void testParseInvalidChild() throws Exception { node.addChild(argument("bar", integer()).build()); node.parse("foo bar"); } - @Test(expected = IllegalCommandArgumentException.class) + @Test(expected = IllegalArgumentSyntaxException.class) public void testParseNoChildren() throws Exception { node.parse("foo 123"); }