CMDAPIVarArgsSorting #43
@ -124,6 +124,8 @@ class CommandPart<T> {
|
||||
}
|
||||
if (next != null) {
|
||||
next.generateArgumentArray(errors, current, sender, args, startIndex + 1);
|
||||
} else if (startIndex + 1 < args.length) {
|
||||
throw new CommandParseException();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,8 +76,11 @@ public class SubCommand<T> implements Comparable<SubCommand<T>> {
|
||||
int tLength = parameters.length + subCommand.length;
|
||||
int oLength = o.parameters.length + o.subCommand.length;
|
||||
|
||||
if (parameters[parameters.length - 1].isVarArgs()) tLength *= -1;
|
||||
if (o.parameters[o.parameters.length - 1].isVarArgs()) oLength *= -1;
|
||||
boolean tVarArgs = parameters[parameters.length - 1].isVarArgs();
|
||||
boolean oVarArgs = o.parameters[o.parameters.length - 1].isVarArgs();
|
||||
|
||||
if (tVarArgs) tLength *= -1;
|
||||
if (oVarArgs) oLength *= -1;
|
||||
|
||||
return -Integer.compare(tLength, oLength);
|
||||
}
|
||||
|
@ -30,25 +30,16 @@ public class SubCMDSortingCommand extends TestSWCommand {
|
||||
|
||||
@Register
|
||||
public void test(String s) {
|
||||
System.out.println("HERE 1");
|
||||
throw new ExecutionIdentifier("Command with 0 parameters");
|
||||
}
|
||||
|
||||
@Register
|
||||
public void test(String s, String args) {
|
||||
throw new ExecutionIdentifier("Command with 1 parameter");
|
||||
}
|
||||
|
||||
@Register
|
||||
public void test(String s, String... args) {
|
||||
System.out.println("HERE 2");
|
||||
throw new ExecutionIdentifier("Command with 1 parameters");
|
||||
}
|
||||
|
||||
@Register
|
||||
public void test(String s, String p, String... args) {
|
||||
System.out.println("HERE 3");
|
||||
throw new ExecutionIdentifier("Command with 2 parameters");
|
||||
}
|
||||
|
||||
@Register
|
||||
public void test(String s, String p, String p2, String... args) {
|
||||
System.out.println("HERE 4");
|
||||
throw new ExecutionIdentifier("Command with 3 parameters");
|
||||
throw new ExecutionIdentifier("Command with n parameters");
|
||||
}
|
||||
}
|
||||
|
@ -44,29 +44,18 @@ public class SubCMDSortingCommandTest {
|
||||
cmd.execute("", "", new String[]{"Hello"});
|
||||
assert false;
|
||||
} catch (Exception e) {
|
||||
assertCMDFramework(e, ExecutionIdentifier.class, "Command with 1 parameters");
|
||||
assertCMDFramework(e, ExecutionIdentifier.class, "Command with 1 parameter");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTwoArgs() {
|
||||
public void testOneArgsVarArg() {
|
||||
SubCMDSortingCommand cmd = new SubCMDSortingCommand();
|
||||
try {
|
||||
cmd.execute("", "", new String[]{"Hello", "World"});
|
||||
assert false;
|
||||
} catch (Exception e) {
|
||||
assertCMDFramework(e, ExecutionIdentifier.class, "Command with 2 parameters");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThreeArgs() {
|
||||
SubCMDSortingCommand cmd = new SubCMDSortingCommand();
|
||||
try {
|
||||
cmd.execute("", "", new String[]{"Hello", "World", "!"});
|
||||
assert false;
|
||||
} catch (Exception e) {
|
||||
assertCMDFramework(e, ExecutionIdentifier.class, "Command with 3 parameters");
|
||||
assertCMDFramework(e, ExecutionIdentifier.class, "Command with n parameters");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren