Clean up ParametricCallable.

This commit is contained in:
sk89q 2014-07-01 13:50:49 -07:00
parent 1b0a6bfcd8
commit 7ba002ac8d

View File

@ -19,7 +19,6 @@
package com.sk89q.worldedit.util.command.parametric; package com.sk89q.worldedit.util.command.parametric;
import com.google.common.base.Joiner;
import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.CommandException;
@ -109,8 +108,7 @@ class ParametricCallable implements CommandCallable {
} }
// Special annotation bindings // Special annotation bindings
} else if (parameter.getBinding() == null) { } else if (parameter.getBinding() == null) {
parameter.setBinding(builder.getBindings().get( parameter.setBinding(builder.getBindings().get(annotation.annotationType()));
annotation.annotationType()));
parameter.setClassifier(annotation); parameter.setClassifier(annotation);
} }
} }
@ -188,7 +186,6 @@ class ParametricCallable implements CommandCallable {
// Provide help if -? is specified // Provide help if -? is specified
if (context.hasFlag('?')) { if (context.hasFlag('?')) {
String title = Joiner.on(" ").join(parentCommands);
throw new InvalidUsageException(null, this, true); throw new InvalidUsageException(null, this, true);
} }
@ -314,8 +311,7 @@ class ParametricCallable implements CommandCallable {
CommandContext context = existing.getContext(); CommandContext context = existing.getContext();
if (parameter.isValueFlag()) { if (parameter.isValueFlag()) {
return new StringArgumentStack( return new StringArgumentStack(context, context.getFlag(parameter.getFlag()), false);
context, context.getFlag(parameter.getFlag()), false);
} else { } else {
String v = context.hasFlag(parameter.getFlag()) ? "true" : "false"; String v = context.hasFlag(parameter.getFlag()) ? "true" : "false";
return new StringArgumentStack(context, v, true); return new StringArgumentStack(context, v, true);
@ -370,17 +366,14 @@ class ParametricCallable implements CommandCallable {
* @throws ParameterException on an error * @throws ParameterException on an error
* @throws CommandException on an error * @throws CommandException on an error
*/ */
private Object getDefaultValue(int i, ContextArgumentStack scoped) private Object getDefaultValue(int i, ContextArgumentStack scoped) throws ParameterException, CommandException, InvocationTargetException {
throws ParameterException, CommandException, InvocationTargetException {
CommandContext context = scoped.getContext(); CommandContext context = scoped.getContext();
ParameterData parameter = parameters[i]; ParameterData parameter = parameters[i];
String[] defaultValue = parameter.getDefaultValue(); String[] defaultValue = parameter.getDefaultValue();
if (defaultValue != null) { if (defaultValue != null) {
try { try {
return parameter.getBinding().bind( return parameter.getBinding().bind(parameter, new StringArgumentStack(context, defaultValue, false), false);
parameter, new StringArgumentStack(
context, defaultValue, false), false);
} catch (MissingParameterException e) { } catch (MissingParameterException e) {
throw new ParametricException( throw new ParametricException(
"The default value of the parameter using the binding " + "The default value of the parameter using the binding " +
@ -399,8 +392,7 @@ class ParametricCallable implements CommandCallable {
* @param scoped the argument scope * @param scoped the argument scope
* @throws UnconsumedParameterException thrown if parameters were not consumed * @throws UnconsumedParameterException thrown if parameters were not consumed
*/ */
private void checkUnconsumed(ContextArgumentStack scoped) private void checkUnconsumed(ContextArgumentStack scoped) throws UnconsumedParameterException {
throws UnconsumedParameterException {
CommandContext context = scoped.getContext(); CommandContext context = scoped.getContext();
String unconsumed; String unconsumed;
String unconsumedFlags = getUnusedFlags(context); String unconsumedFlags = getUnusedFlags(context);