Renamed CommandException -> CommandSyntaxException

This commit is contained in:
Nathan Adams 2017-08-21 14:44:22 +02:00
parent f287b89ee4
commit 08b183588f
24 changed files with 94 additions and 97 deletions

View file

@ -1,11 +1,11 @@
package com.mojang.brigadier;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandException;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
@FunctionalInterface
public interface Command<S> {
int SINGLE_SUCCESS = 1;
int run(CommandContext<S> context) throws CommandException;
int run(CommandContext<S> context) throws CommandSyntaxException;
}

View file

@ -7,7 +7,7 @@ import com.google.common.collect.Sets;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.context.CommandContextBuilder;
import com.mojang.brigadier.exceptions.CommandException;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import com.mojang.brigadier.tree.CommandNode;
import com.mojang.brigadier.tree.LiteralCommandNode;
@ -27,6 +27,7 @@ public class CommandDispatcher<S> {
public static final SimpleCommandExceptionType ERROR_UNKNOWN_COMMAND = new SimpleCommandExceptionType("command.unknown.command", "Unknown command");
public static final SimpleCommandExceptionType ERROR_UNKNOWN_ARGUMENT = new SimpleCommandExceptionType("command.unknown.argument", "Incorrect argument for command");
public static final SimpleCommandExceptionType ERROR_EXPECTED_ARGUMENT_SEPARATOR = new SimpleCommandExceptionType("command.expected.separator", "Expected whitespace to end one argument, but found trailing data");
public static final SimpleCommandExceptionType ERROR_COMMAND_FAILED = new SimpleCommandExceptionType("command.failed", "Expected whitespace to end one argument, but found trailing data");
public static final String ARGUMENT_SEPARATOR = " ";
public static final char ARGUMENT_SEPARATOR_CHAR = ' ';
@ -58,12 +59,12 @@ public class CommandDispatcher<S> {
return build;
}
public int execute(final String input, final S source) throws CommandException {
public int execute(final String input, final S source) throws CommandSyntaxException {
final ParseResults<S> parse = parse(input, source);
return execute(parse);
}
public int execute(final ParseResults<S> parse) throws CommandException {
public int execute(final ParseResults<S> parse) throws CommandSyntaxException {
if (parse.getReader().canRead()) {
if (parse.getExceptions().size() == 1) {
throw parse.getExceptions().values().iterator().next();
@ -102,15 +103,15 @@ public class CommandDispatcher<S> {
return result;
}
public ParseResults<S> parse(final String command, final S source) throws CommandException {
public ParseResults<S> parse(final String command, final S source) throws CommandSyntaxException {
final StringReader reader = new StringReader(command);
final CommandContextBuilder<S> context = new CommandContextBuilder<>(this, source);
return parseNodes(root, reader, context, context, null);
}
private ParseResults<S> parseNodes(final CommandNode<S> node, final StringReader reader, final CommandContextBuilder<S> contextBuilder, CommandContextBuilder<S> rootContext, final CommandContextBuilder<S> parentContext) throws CommandException {
private ParseResults<S> parseNodes(final CommandNode<S> node, final StringReader reader, final CommandContextBuilder<S> contextBuilder, CommandContextBuilder<S> rootContext, final CommandContextBuilder<S> parentContext) throws CommandSyntaxException {
final S source = contextBuilder.getSource();
final Map<CommandNode<S>, CommandException> errors = Maps.newHashMap();
final Map<CommandNode<S>, CommandSyntaxException> errors = Maps.newHashMap();
for (final CommandNode<S> child : node.getChildren()) {
if (!child.canUse(source)) {
@ -125,7 +126,7 @@ public class CommandDispatcher<S> {
throw ERROR_EXPECTED_ARGUMENT_SEPARATOR.createWithContext(reader);
}
}
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
errors.put(child, ex);
reader.setCursor(cursor);
continue;
@ -275,7 +276,7 @@ public class CommandDispatcher<S> {
reader.setCursor(cursor);
child.listSuggestions(reader.getRemaining(), result, context);
}
} catch (final CommandException e) {
} catch (final CommandSyntaxException e) {
reader.setCursor(cursor);
child.listSuggestions(reader.getRemaining(), result, context);
}

View file

@ -1,7 +1,7 @@
package com.mojang.brigadier;
import com.mojang.brigadier.context.CommandContextBuilder;
import com.mojang.brigadier.exceptions.CommandException;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.tree.CommandNode;
import java.util.Collections;
@ -9,10 +9,10 @@ import java.util.Map;
public class ParseResults<S> {
private final CommandContextBuilder<S> context;
private final Map<CommandNode<S>, CommandException> exceptions;
private final Map<CommandNode<S>, CommandSyntaxException> exceptions;
private final ImmutableStringReader reader;
public ParseResults(final CommandContextBuilder<S> context, final ImmutableStringReader reader, final Map<CommandNode<S>, CommandException> exceptions) {
public ParseResults(final CommandContextBuilder<S> context, final ImmutableStringReader reader, final Map<CommandNode<S>, CommandSyntaxException> exceptions) {
this.context = context;
this.reader = reader;
this.exceptions = exceptions;
@ -30,7 +30,7 @@ public class ParseResults<S> {
return reader;
}
public Map<CommandNode<S>, CommandException> getExceptions() {
public Map<CommandNode<S>, CommandSyntaxException> getExceptions() {
return exceptions;
}
}

View file

@ -1,6 +1,6 @@
package com.mojang.brigadier;
import com.mojang.brigadier.exceptions.CommandException;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.ParameterizedCommandExceptionType;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
@ -98,7 +98,7 @@ public class StringReader implements ImmutableStringReader {
}
}
public int readInt() throws CommandException {
public int readInt() throws CommandSyntaxException {
final int start = cursor;
while (canRead() && isAllowedNumber(peek())) {
skip();
@ -115,7 +115,7 @@ public class StringReader implements ImmutableStringReader {
}
}
public double readDouble() throws CommandException {
public double readDouble() throws CommandSyntaxException {
final int start = cursor;
while (canRead() && isAllowedNumber(peek())) {
skip();
@ -148,7 +148,7 @@ public class StringReader implements ImmutableStringReader {
return string.substring(start, cursor);
}
public String readQuotedString() throws CommandException {
public String readQuotedString() throws CommandSyntaxException {
if (!canRead()) {
return "";
} else if (peek() != SYNTAX_QUOTE) {
@ -179,7 +179,7 @@ public class StringReader implements ImmutableStringReader {
throw ERROR_EXPECTED_END_OF_QUOTE.createWithContext(this);
}
public String readString() throws CommandException {
public String readString() throws CommandSyntaxException {
if (canRead() && peek() == SYNTAX_QUOTE) {
return readQuotedString();
} else {
@ -187,7 +187,7 @@ public class StringReader implements ImmutableStringReader {
}
}
public boolean readBoolean() throws CommandException {
public boolean readBoolean() throws CommandSyntaxException {
final int start = cursor;
final String value = readString();
if (value.isEmpty()) {
@ -204,7 +204,7 @@ public class StringReader implements ImmutableStringReader {
}
}
public void expect(final char c) throws CommandException {
public void expect(final char c) throws CommandSyntaxException {
if (!canRead() || peek() != c) {
throw ERROR_EXPECTED_SYMBOL.createWithContext(this, String.valueOf(c));
}

View file

@ -2,12 +2,12 @@ package com.mojang.brigadier.arguments;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.context.CommandContextBuilder;
import com.mojang.brigadier.exceptions.CommandException;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import java.util.Set;
public interface ArgumentType<T> {
<S> T parse(StringReader reader, CommandContextBuilder<S> contextBuilder) throws CommandException;
<S> T parse(StringReader reader, CommandContextBuilder<S> contextBuilder) throws CommandSyntaxException;
default <S> void listSuggestions(final String command, final Set<String> output, final CommandContextBuilder<S> contextBuilder) {
}

View file

@ -3,8 +3,7 @@ package com.mojang.brigadier.arguments;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.context.CommandContextBuilder;
import com.mojang.brigadier.exceptions.CommandException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
public class BoolArgumentType implements ArgumentType<Boolean> {
private BoolArgumentType() {
@ -19,7 +18,7 @@ public class BoolArgumentType implements ArgumentType<Boolean> {
}
@Override
public <S> Boolean parse(final StringReader reader, final CommandContextBuilder<S> contextBuilder) throws CommandException {
public <S> Boolean parse(final StringReader reader, final CommandContextBuilder<S> contextBuilder) throws CommandSyntaxException {
return reader.readBoolean();
}

View file

@ -3,7 +3,7 @@ package com.mojang.brigadier.arguments;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.context.CommandContextBuilder;
import com.mojang.brigadier.exceptions.CommandException;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.ParameterizedCommandExceptionType;
import java.util.Objects;
@ -44,7 +44,7 @@ public class FloatArgumentType implements ArgumentType<Float> {
}
@Override
public <S> Float parse(final StringReader reader, final CommandContextBuilder<S> contextBuilder) throws CommandException {
public <S> Float parse(final StringReader reader, final CommandContextBuilder<S> contextBuilder) throws CommandSyntaxException {
final int start = reader.getCursor();
final float result = (float) reader.readDouble();
for (int i = 0; i < suffix.length(); i++) {

View file

@ -3,7 +3,7 @@ package com.mojang.brigadier.arguments;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.context.CommandContextBuilder;
import com.mojang.brigadier.exceptions.CommandException;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.ParameterizedCommandExceptionType;
import java.util.Objects;
@ -44,7 +44,7 @@ public class IntegerArgumentType implements ArgumentType<Integer> {
}
@Override
public <S> Integer parse(final StringReader reader, final CommandContextBuilder<S> contextBuilder) throws CommandException {
public <S> Integer parse(final StringReader reader, final CommandContextBuilder<S> contextBuilder) throws CommandSyntaxException {
final int start = reader.getCursor();
final int result = reader.readInt();
for (int i = 0; i < suffix.length(); i++) {

View file

@ -4,7 +4,7 @@ import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.context.CommandContextBuilder;
import com.mojang.brigadier.exceptions.CommandException;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
public class StringArgumentType implements ArgumentType<String> {
private final StringType type;
@ -30,7 +30,7 @@ public class StringArgumentType implements ArgumentType<String> {
}
@Override
public <S> String parse(final StringReader reader, final CommandContextBuilder<S> contextBuilder) throws CommandException {
public <S> String parse(final StringReader reader, final CommandContextBuilder<S> contextBuilder) throws CommandSyntaxException {
if (type == StringType.GREEDY_PHRASE) {
final String text = reader.getRemaining();
reader.setCursor(reader.getTotalLength());

View file

@ -2,7 +2,7 @@ package com.mojang.brigadier.exceptions;
import java.util.Map;
public class CommandException extends Exception {
public class CommandSyntaxException extends Exception {
public static final int CONTEXT_AMOUNT = 10;
public static boolean ENABLE_COMMAND_STACK_TRACES = true;
@ -11,7 +11,7 @@ public class CommandException extends Exception {
private final String input;
private final int cursor;
public CommandException(final CommandExceptionType type, final Map<String, String> data) {
public CommandSyntaxException(final CommandExceptionType type, final Map<String, String> data) {
super(type.getTypeName(), null, ENABLE_COMMAND_STACK_TRACES, ENABLE_COMMAND_STACK_TRACES);
this.type = type;
this.data = data;
@ -19,7 +19,7 @@ public class CommandException extends Exception {
this.cursor = -1;
}
public CommandException(final CommandExceptionType type, final Map<String, String> data, final String input, final int cursor) {
public CommandSyntaxException(final CommandExceptionType type, final Map<String, String> data, final String input, final int cursor) {
super(type.getTypeName(), null, ENABLE_COMMAND_STACK_TRACES, ENABLE_COMMAND_STACK_TRACES);
this.type = type;
this.data = data;

View file

@ -3,7 +3,6 @@ package com.mojang.brigadier.exceptions;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.mojang.brigadier.ImmutableStringReader;
import com.mojang.brigadier.StringReader;
import java.util.Map;
import java.util.regex.Matcher;
@ -39,12 +38,12 @@ public class ParameterizedCommandExceptionType implements CommandExceptionType {
return result.toString();
}
public CommandException create(final Object... values) {
return new CommandException(this, createMap(values));
public CommandSyntaxException create(final Object... values) {
return new CommandSyntaxException(this, createMap(values));
}
public CommandException createWithContext(final ImmutableStringReader reader, final Object... values) {
return new CommandException(this, createMap(values), reader.getString(), reader.getCursor());
public CommandSyntaxException createWithContext(final ImmutableStringReader reader, final Object... values) {
return new CommandSyntaxException(this, createMap(values), reader.getString(), reader.getCursor());
}
public Map<String, String> createMap(final Object... values) {

View file

@ -2,7 +2,6 @@ package com.mojang.brigadier.exceptions;
import com.google.common.collect.ImmutableMap;
import com.mojang.brigadier.ImmutableStringReader;
import com.mojang.brigadier.StringReader;
import java.util.Map;
@ -25,12 +24,12 @@ public class SimpleCommandExceptionType implements CommandExceptionType {
return message;
}
public CommandException create() {
return new CommandException(this, ImmutableMap.of());
public CommandSyntaxException create() {
return new CommandSyntaxException(this, ImmutableMap.of());
}
public CommandException createWithContext(final ImmutableStringReader reader) {
return new CommandException(this, ImmutableMap.of(), reader.getString(), reader.getCursor());
public CommandSyntaxException createWithContext(final ImmutableStringReader reader) {
return new CommandSyntaxException(this, ImmutableMap.of(), reader.getString(), reader.getCursor());
}
@Override

View file

@ -7,7 +7,7 @@ import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.context.CommandContextBuilder;
import com.mojang.brigadier.context.ParsedArgument;
import com.mojang.brigadier.exceptions.CommandException;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import java.util.Collection;
import java.util.Set;
@ -54,7 +54,7 @@ public class ArgumentCommandNode<S, T> extends CommandNode<S> {
}
@Override
public void parse(final StringReader reader, final CommandContextBuilder<S> contextBuilder) throws CommandException {
public void parse(final StringReader reader, final CommandContextBuilder<S> contextBuilder) throws CommandSyntaxException {
final int start = reader.getCursor();
final T result = type.parse(reader, contextBuilder);
final ParsedArgument<S, T> parsed = new ParsedArgument<>(start, reader.getCursor(), result);

View file

@ -7,7 +7,7 @@ import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.context.CommandContextBuilder;
import com.mojang.brigadier.exceptions.CommandException;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import java.util.Collection;
import java.util.LinkedHashMap;
@ -94,7 +94,7 @@ public abstract class CommandNode<S> implements Comparable<CommandNode<S>> {
public abstract String getUsageText();
public abstract void parse(StringReader reader, CommandContextBuilder<S> contextBuilder) throws CommandException;
public abstract void parse(StringReader reader, CommandContextBuilder<S> contextBuilder) throws CommandSyntaxException;
public abstract void listSuggestions(String command, Set<String> output, CommandContextBuilder<S> contextBuilder);

View file

@ -5,7 +5,7 @@ import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.context.CommandContextBuilder;
import com.mojang.brigadier.exceptions.CommandException;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.ParameterizedCommandExceptionType;
import java.util.Collection;
@ -33,7 +33,7 @@ public class LiteralCommandNode<S> extends CommandNode<S> {
}
@Override
public void parse(final StringReader reader, final CommandContextBuilder<S> contextBuilder) throws CommandException {
public void parse(final StringReader reader, final CommandContextBuilder<S> contextBuilder) throws CommandSyntaxException {
final int start = reader.getCursor();
for (int i = 0; i < literal.length(); i++) {
if (reader.canRead() && reader.peek() == literal.charAt(i)) {

View file

@ -3,9 +3,8 @@ package com.mojang.brigadier.tree;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.context.CommandContextBuilder;
import com.mojang.brigadier.exceptions.CommandException;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
@ -25,7 +24,7 @@ public class RootCommandNode<S> extends CommandNode<S> {
}
@Override
public void parse(final StringReader reader, final CommandContextBuilder<S> contextBuilder) throws CommandException {
public void parse(final StringReader reader, final CommandContextBuilder<S> contextBuilder) throws CommandSyntaxException {
}
@Override

View file

@ -3,7 +3,7 @@ package com.mojang.brigadier;
import com.google.common.collect.Lists;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.context.CommandContextBuilder;
import com.mojang.brigadier.exceptions.CommandException;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.tree.LiteralCommandNode;
import org.junit.Before;
import org.junit.Test;
@ -74,7 +74,7 @@ public class CommandDispatcherTest {
try {
subject.execute("foo", source);
fail();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandDispatcher.ERROR_UNKNOWN_COMMAND));
assertThat(ex.getData(), is(Collections.<String, Object>emptyMap()));
assertThat(ex.getCursor(), is(0));
@ -88,7 +88,7 @@ public class CommandDispatcherTest {
try {
subject.execute("foo", source);
fail();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandDispatcher.ERROR_UNKNOWN_COMMAND));
assertThat(ex.getData(), is(Collections.<String, Object>emptyMap()));
assertThat(ex.getCursor(), is(0));
@ -102,7 +102,7 @@ public class CommandDispatcherTest {
try {
subject.execute("", source);
fail();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandDispatcher.ERROR_UNKNOWN_COMMAND));
assertThat(ex.getData(), is(Collections.<String, Object>emptyMap()));
assertThat(ex.getCursor(), is(0));
@ -116,7 +116,7 @@ public class CommandDispatcherTest {
try {
subject.execute("foo bar", source);
fail();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandDispatcher.ERROR_UNKNOWN_ARGUMENT));
assertThat(ex.getData(), is(Collections.emptyMap()));
assertThat(ex.getCursor(), is(4));
@ -130,7 +130,7 @@ public class CommandDispatcherTest {
try {
subject.execute("foo baz", source);
fail();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(LiteralCommandNode.ERROR_INCORRECT_LITERAL));
assertThat(ex.getData(), is(Collections.singletonMap("expected", "bar")));
assertThat(ex.getCursor(), is(4));
@ -148,7 +148,7 @@ public class CommandDispatcherTest {
try {
subject.execute("foo unknown", source);
fail();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandDispatcher.ERROR_UNKNOWN_ARGUMENT));
assertThat(ex.getData(), is(Collections.emptyMap()));
assertThat(ex.getCursor(), is(4));
@ -234,7 +234,7 @@ public class CommandDispatcherTest {
try {
subject.execute("foo 5", source);
fail();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandDispatcher.ERROR_UNKNOWN_COMMAND));
assertThat(ex.getData(), is(Collections.emptyMap()));
assertThat(ex.getCursor(), is(0));
@ -259,7 +259,7 @@ public class CommandDispatcherTest {
try {
subject.execute("foo5", source);
fail();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(CommandDispatcher.ERROR_EXPECTED_ARGUMENT_SEPARATOR));
assertThat(ex.getData(), is(Collections.emptyMap()));
assertThat(ex.getCursor(), is(3));
@ -275,7 +275,7 @@ public class CommandDispatcherTest {
try {
subject.execute("foo bar", source);
fail();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(StringReader.ERROR_EXPECTED_INT));
assertThat(ex.getData(), is(Collections.emptyMap()));
assertThat(ex.getCursor(), is(4));

View file

@ -2,7 +2,7 @@ package com.mojang.brigadier;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterators;
import com.mojang.brigadier.exceptions.CommandException;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.tree.CommandNode;
import org.junit.Before;
import org.junit.Test;
@ -101,7 +101,7 @@ public class CommandDispatcherUsagesTest {
private CommandNode<Object> get(final String command) {
try {
return Iterators.getLast(subject.parse(command, source).getContext().getNodes().keySet().iterator());
} catch (final CommandException e) {
} catch (final CommandSyntaxException e) {
throw new AssertionError("get() failed unexpectedly", e);
}
}

View file

@ -1,7 +1,7 @@
package com.mojang.brigadier;
import com.google.common.collect.ImmutableMap;
import com.mojang.brigadier.exceptions.CommandException;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import org.junit.Test;
import java.util.Collections;
@ -216,7 +216,7 @@ public class StringReaderTest {
public void readQuotedString_noOpen() throws Exception {
try {
new StringReader("hello world\"").readQuotedString();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(StringReader.ERROR_EXPECTED_START_OF_QUOTE));
assertThat(ex.getData(), equalTo(Collections.emptyMap()));
assertThat(ex.getCursor(), is(0));
@ -227,7 +227,7 @@ public class StringReaderTest {
public void readQuotedString_noClose() throws Exception {
try {
new StringReader("\"hello world").readQuotedString();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(StringReader.ERROR_EXPECTED_END_OF_QUOTE));
assertThat(ex.getData(), equalTo(Collections.emptyMap()));
assertThat(ex.getCursor(), is(12));
@ -238,7 +238,7 @@ public class StringReaderTest {
public void readQuotedString_invalidEscape() throws Exception {
try {
new StringReader("\"hello\\nworld\"").readQuotedString();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(StringReader.ERROR_INVALID_ESCAPE));
assertThat(ex.getData(), equalTo(ImmutableMap.of("character", "n")));
assertThat(ex.getCursor(), is(7));
@ -265,7 +265,7 @@ public class StringReaderTest {
public void readInt_invalid() throws Exception {
try {
new StringReader("12.34").readInt();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(StringReader.ERROR_INVALID_INT));
assertThat(ex.getData(), equalTo(ImmutableMap.of("value", "12.34")));
assertThat(ex.getCursor(), is(0));
@ -276,7 +276,7 @@ public class StringReaderTest {
public void readInt_none() throws Exception {
try {
new StringReader("").readInt();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(StringReader.ERROR_EXPECTED_INT));
assertThat(ex.getData(), equalTo(Collections.emptyMap()));
assertThat(ex.getCursor(), is(0));
@ -327,7 +327,7 @@ public class StringReaderTest {
public void readDouble_invalid() throws Exception {
try {
new StringReader("12.34.56").readDouble();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(StringReader.ERROR_INVALID_DOUBLE));
assertThat(ex.getData(), equalTo(ImmutableMap.of("value", "12.34.56")));
assertThat(ex.getCursor(), is(0));
@ -338,7 +338,7 @@ public class StringReaderTest {
public void readDouble_none() throws Exception {
try {
new StringReader("").readDouble();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(StringReader.ERROR_EXPECTED_DOUBLE));
assertThat(ex.getData(), equalTo(Collections.emptyMap()));
assertThat(ex.getCursor(), is(0));
@ -374,7 +374,7 @@ public class StringReaderTest {
try {
reader.expect('a');
fail();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(StringReader.ERROR_EXPECTED_SYMBOL));
assertThat(ex.getData(), equalTo(ImmutableMap.of("symbol", "a")));
assertThat(ex.getCursor(), is(0));
@ -387,7 +387,7 @@ public class StringReaderTest {
try {
reader.expect('a');
fail();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(StringReader.ERROR_EXPECTED_SYMBOL));
assertThat(ex.getData(), equalTo(ImmutableMap.of("symbol", "a")));
assertThat(ex.getCursor(), is(0));
@ -407,7 +407,7 @@ public class StringReaderTest {
try {
reader.readBoolean();
fail();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(StringReader.ERROR_INVALID_BOOL));
assertThat(ex.getData(), equalTo(ImmutableMap.of("value", "tuesday")));
assertThat(ex.getCursor(), is(0));
@ -420,7 +420,7 @@ public class StringReaderTest {
try {
reader.readBoolean();
fail();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(StringReader.ERROR_EXPECTED_BOOL));
assertThat(ex.getData(), equalTo(Collections.emptyMap()));
assertThat(ex.getCursor(), is(0));

View file

@ -5,7 +5,7 @@ import com.google.common.collect.Sets;
import com.google.common.testing.EqualsTester;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.context.CommandContextBuilder;
import com.mojang.brigadier.exceptions.CommandException;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -54,7 +54,7 @@ public class FloatArgumentTypeTest {
try {
floatArg(0, 100, "L").parse(reader, context);
fail();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(FloatArgumentType.ERROR_WRONG_SUFFIX));
assertThat(ex.getData(), equalTo(ImmutableMap.<String, Object>of("suffix", "L")));
assertThat(ex.getCursor(), is(0));
@ -67,7 +67,7 @@ public class FloatArgumentTypeTest {
try {
floatArg(0, 100, "L").parse(reader, context);
fail();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(FloatArgumentType.ERROR_WRONG_SUFFIX));
assertThat(ex.getData(), equalTo(ImmutableMap.<String, Object>of("suffix", "L")));
assertThat(ex.getCursor(), is(0));
@ -80,7 +80,7 @@ public class FloatArgumentTypeTest {
try {
floatArg(0, 100).parse(reader, context);
fail();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(FloatArgumentType.ERROR_TOO_SMALL));
assertThat(ex.getData(), equalTo(ImmutableMap.<String, Object>of("found", "-5.0", "minimum", "0.0")));
assertThat(ex.getCursor(), is(0));
@ -93,7 +93,7 @@ public class FloatArgumentTypeTest {
try {
floatArg(-100, 0).parse(reader, context);
fail();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(FloatArgumentType.ERROR_TOO_BIG));
assertThat(ex.getData(), equalTo(ImmutableMap.<String, Object>of("found", "5.0", "maximum", "0.0")));
assertThat(ex.getCursor(), is(0));

View file

@ -5,7 +5,7 @@ import com.google.common.collect.Sets;
import com.google.common.testing.EqualsTester;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.context.CommandContextBuilder;
import com.mojang.brigadier.exceptions.CommandException;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -54,7 +54,7 @@ public class IntegerArgumentTypeTest {
try {
integer(0, 100, "L").parse(reader, context);
fail();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(IntegerArgumentType.ERROR_WRONG_SUFFIX));
assertThat(ex.getData(), equalTo(ImmutableMap.<String, Object>of("suffix", "L")));
assertThat(ex.getCursor(), is(0));
@ -67,7 +67,7 @@ public class IntegerArgumentTypeTest {
try {
integer(0, 100, "L").parse(reader, context);
fail();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(IntegerArgumentType.ERROR_WRONG_SUFFIX));
assertThat(ex.getData(), equalTo(ImmutableMap.<String, Object>of("suffix", "L")));
assertThat(ex.getCursor(), is(0));
@ -80,7 +80,7 @@ public class IntegerArgumentTypeTest {
try {
integer(0, 100).parse(reader, context);
fail();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(IntegerArgumentType.ERROR_TOO_SMALL));
assertThat(ex.getData(), equalTo(ImmutableMap.<String, Object>of("found", "-5", "minimum", "0")));
assertThat(ex.getCursor(), is(0));
@ -93,7 +93,7 @@ public class IntegerArgumentTypeTest {
try {
integer(-100, 0).parse(reader, context);
fail();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(IntegerArgumentType.ERROR_TOO_BIG));
assertThat(ex.getData(), equalTo(ImmutableMap.<String, Object>of("found", "5", "maximum", "0")));
assertThat(ex.getCursor(), is(0));

View file

@ -11,7 +11,7 @@ import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public class ParameterizedCommandExceptionTypeTest {
public class ParameterizedCommandSyntaxExceptionTypeTest {
private ParameterizedCommandExceptionType type;
@Before
@ -28,7 +28,7 @@ public class ParameterizedCommandExceptionTypeTest {
public void createWithContext() throws Exception {
final StringReader reader = new StringReader("Foo bar");
reader.setCursor(5);
final CommandException exception = type.createWithContext(reader, "World");
final CommandSyntaxException exception = type.createWithContext(reader, "World");
assertThat(exception.getType(), is(type));
assertThat(exception.getData(), is(ImmutableMap.<String, Object>of("name", "World")));
assertThat(exception.getInput(), is("Foo bar"));

View file

@ -13,13 +13,13 @@ import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public class SimpleCommandExceptionTypeTest {
public class SimpleCommandSyntaxExceptionTypeTest {
@Test
public void createWithContext() throws Exception {
final SimpleCommandExceptionType type = new SimpleCommandExceptionType("foo", "bar");
final StringReader reader = new StringReader("Foo bar");
reader.setCursor(5);
final CommandException exception = type.createWithContext(reader);
final CommandSyntaxException exception = type.createWithContext(reader);
assertThat(exception.getType(), is(type));
assertThat(exception.getData(), is(Collections.emptyMap()));
assertThat(exception.getInput(), is("Foo bar"));
@ -36,19 +36,19 @@ public class SimpleCommandExceptionTypeTest {
@Test
public void getContext_none() throws Exception {
final CommandException exception = new CommandException(mock(CommandExceptionType.class), Collections.emptyMap());
final CommandSyntaxException exception = new CommandSyntaxException(mock(CommandExceptionType.class), Collections.emptyMap());
assertThat(exception.getContext(), is(nullValue()));
}
@Test
public void getContext_short() throws Exception {
final CommandException exception = new CommandException(mock(CommandExceptionType.class), Collections.emptyMap(), "Hello world!", 5);
final CommandSyntaxException exception = new CommandSyntaxException(mock(CommandExceptionType.class), Collections.emptyMap(), "Hello world!", 5);
assertThat(exception.getContext(), equalTo("Hello<--[HERE]"));
}
@Test
public void getContext_long() throws Exception {
final CommandException exception = new CommandException(mock(CommandExceptionType.class), Collections.emptyMap(), "Hello world! This has an error in it. Oh dear!", 20);
final CommandSyntaxException exception = new CommandSyntaxException(mock(CommandExceptionType.class), Collections.emptyMap(), "Hello world! This has an error in it. Oh dear!", 20);
assertThat(exception.getContext(), equalTo("...d! This ha<--[HERE]"));
}
}

View file

@ -8,7 +8,7 @@ import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContextBuilder;
import com.mojang.brigadier.exceptions.CommandException;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@ -66,7 +66,7 @@ public class LiteralCommandNodeTest extends AbstractCommandNodeTest {
try {
node.parse(reader, contextBuilder);
fail();
} catch (final CommandException ex) {
} catch (final CommandSyntaxException ex) {
assertThat(ex.getType(), is(LiteralCommandNode.ERROR_INCORRECT_LITERAL));
assertThat(ex.getData(), is(ImmutableMap.<String, Object>of("expected", "foo")));
assertThat(ex.getCursor(), is(0));