Bladeren bron

ValidatingCommand and WrappableCommand now use CommandArguments

/me now takes its two \001s into account (fixes issue 2291)
Removed deprecated implodeArgs methods
tags/0.6.3m1rc1
Chris Smith 15 jaren geleden
bovenliggende
commit
e8e4a0a43a

+ 0
- 31
src/com/dmdirc/commandparser/commands/Command.java Bestand weergeven

@@ -38,37 +38,6 @@ public abstract class Command {
38 38
     
39 39
     /** The format name used for command errors. */
40 40
     protected static final String FORMAT_ERROR = "commandError";
41
-               
42
-    /**
43
-     * Implodes the given list of arguments.
44
-     * @param offset The index to start at
45
-     * @param args The arguments to implode
46
-     * @return A string containing each argument seperated by a space
47
-     * @deprecated Should be no need for this now
48
-     */
49
-    @Deprecated
50
-    protected static final String implodeArgs(final int offset, final String... args) {
51
-        String res = "";
52
-        for (int i = offset; i < args.length; i++) {
53
-            if (res.isEmpty()) {
54
-                res = args[i];
55
-            } else {
56
-                res = res.concat(" " + args[i]);
57
-            }
58
-        }
59
-        return res;
60
-    }
61
-    
62
-    /**
63
-     * Implodes the given list of arguments.
64
-     * @param args The arguments to implode
65
-     * @return A string containing each argument seperated by a space
66
-     * @deprecated Should be no need for this now
67
-     */
68
-    @Deprecated
69
-    protected static final String implodeArgs(final String... args) {
70
-        return implodeArgs(0, args);
71
-    } 
72 41
     
73 42
     /**
74 43
      * Sends a line, if appropriate, to the specified target.

+ 3
- 3
src/com/dmdirc/commandparser/commands/ValidatingCommand.java Bestand weergeven

@@ -21,11 +21,10 @@
21 21
  */
22 22
 package com.dmdirc.commandparser.commands;
23 23
 
24
+import com.dmdirc.commandparser.CommandArguments;
24 25
 import com.dmdirc.config.prefs.validator.ValidationResponse;
25 26
 import com.dmdirc.ui.interfaces.InputWindow;
26 27
 
27
-import java.util.List;
28
-
29 28
 /**
30 29
  * Validating commands are capable of validating their arguments to determine
31 30
  * whether the input would be valid or not.
@@ -40,7 +39,8 @@ public interface ValidatingCommand {
40 39
      * @param origin The window the command is being executed in
41 40
      * @param arguments The arguments that the user has entered (so far)
42 41
      * @return A validation response indicating the validity of the arguments
42
+     * @since 0.6.3
43 43
      */
44
-    ValidationResponse validateArguments(InputWindow origin, List<String> arguments);
44
+    ValidationResponse validateArguments(InputWindow origin, CommandArguments arguments);
45 45
 
46 46
 }

+ 3
- 3
src/com/dmdirc/commandparser/commands/WrappableCommand.java Bestand weergeven

@@ -22,10 +22,9 @@
22 22
 
23 23
 package com.dmdirc.commandparser.commands;
24 24
 
25
+import com.dmdirc.commandparser.CommandArguments;
25 26
 import com.dmdirc.ui.interfaces.InputWindow;
26 27
 
27
-import java.util.List;
28
-
29 28
 /**
30 29
  * Wrapping commands are commands whose arguments may be wrapped into multiple
31 30
  * lines when sending.
@@ -41,7 +40,8 @@ public interface WrappableCommand {
41 40
      * @param origin The window the command is being executed in
42 41
      * @param arguments The arguments that the user has entered (so far)
43 42
      * @return The number of lines that the arguments will result in
43
+     * @since 0.6.3
44 44
      */
45
-    int getLineCount(InputWindow origin, List<String> arguments);
45
+    int getLineCount(InputWindow origin, CommandArguments arguments);
46 46
 
47 47
 }

+ 2
- 2
src/com/dmdirc/commandparser/commands/chat/Me.java Bestand weergeven

@@ -78,13 +78,13 @@ public final class Me extends ChatCommand implements ValidatingCommand {
78 78
     /** {@inheritDoc} */
79 79
     @Override
80 80
     public ValidationResponse validateArguments(final InputWindow origin, 
81
-            final List<String> arguments) {
81
+            final CommandArguments arguments) {
82 82
         if (origin.getContainer().getServer() == null
83 83
                 || origin.getContainer().getServer().getParser() == null) {
84 84
             return new ValidationResponse();
85 85
         }
86 86
         
87
-        final int length = implodeArgs(arguments.toArray(new String[arguments.size()])).length();
87
+        final int length = 2 + arguments.getArgumentsAsString().length();
88 88
         
89 89
         if (origin.getContainer().getServer().getParser().getMaxLength("PRIVMSG",
90 90
                 origin.getContainer().toString()) <= length) {

+ 4
- 5
src/com/dmdirc/commandparser/commands/server/Message.java Bestand weergeven

@@ -106,12 +106,11 @@ public final class Message extends ServerCommand implements IntelligentCommand,
106 106
 
107 107
     /** {@inheritDoc} */
108 108
     @Override
109
-    public int getLineCount(final InputWindow origin, final List<String> arguments) {
110
-        if (arguments.size() >= 2) {
111
-            final String target = arguments.get(0);
109
+    public int getLineCount(final InputWindow origin, final CommandArguments arguments) {
110
+        if (arguments.getArguments().length >= 2) {
111
+            final String target = arguments.getArguments()[0];
112 112
             return origin.getContainer().getServer().getNumLines("PRIVMSG "
113
-                    + target + " :" + implodeArgs(1,
114
-                    arguments.toArray(new String[arguments.size()])));
113
+                    + target + " :" + arguments.getArgumentsAsString(1));
115 114
         } else {
116 115
             return 1;
117 116
         }

+ 4
- 5
src/com/dmdirc/commandparser/commands/server/OpenQuery.java Bestand weergeven

@@ -116,12 +116,11 @@ public final class OpenQuery extends ServerCommand implements
116 116
     
117 117
     /** {@inheritDoc} */
118 118
     @Override
119
-    public int getLineCount(final InputWindow origin, final List<String> arguments) {
120
-        if (arguments.size() >= 2) {
121
-            final String target = arguments.get(0);
119
+    public int getLineCount(final InputWindow origin, final CommandArguments arguments) {
120
+        if (arguments.getArguments().length >= 2) {
121
+            final String target = arguments.getArguments()[0];
122 122
             return origin.getContainer().getServer().getNumLines("PRIVMSG "
123
-                    + target + " :" + implodeArgs(1,
124
-                    arguments.toArray(new String[arguments.size()])));
123
+                    + target + " :" + arguments.getArgumentsAsString(1));
125 124
         } else {
126 125
             return 1;
127 126
         }

+ 1
- 1
src/com/dmdirc/parser/irc/ChannelClientInfo.java Bestand weergeven

@@ -32,7 +32,7 @@ import java.util.Map;
32 32
  * @author Chris Smith
33 33
  * @see IRCParser
34 34
  */
35
-public final class ChannelClientInfo {
35
+public class ChannelClientInfo {
36 36
 	/** Reference to ClientInfo object this represents. */
37 37
 	private final ClientInfo cClient;
38 38
 	/** Integer representation of the channel modes assocated with this user. */

+ 6
- 6
src/com/dmdirc/ui/input/InputHandler.java Bestand weergeven

@@ -24,6 +24,7 @@ package com.dmdirc.ui.input;
24 24
 
25 25
 import com.dmdirc.actions.ActionManager;
26 26
 import com.dmdirc.actions.CoreActionType;
27
+import com.dmdirc.commandparser.CommandArguments;
27 28
 import com.dmdirc.commandparser.CommandManager;
28 29
 import com.dmdirc.commandparser.commands.Command;
29 30
 import com.dmdirc.commandparser.commands.ValidatingCommand;
@@ -45,7 +46,6 @@ import com.dmdirc.util.RollingList;
45 46
 import java.awt.Toolkit;
46 47
 import java.awt.event.KeyEvent;
47 48
 import java.util.ArrayList;
48
-import java.util.Arrays;
49 49
 import java.util.List;
50 50
 
51 51
 /**
@@ -215,11 +215,11 @@ public abstract class InputHandler implements ConfigChangeListener {
215 215
      */
216 216
     protected void validateText() {
217 217
         final String text = target.getText();
218
-        
219
-        if (!text.isEmpty() && text.charAt(0) == CommandManager.getCommandChar()) {
220
-            final List<String> args = Arrays.asList(text.split(" "));
221
-            final String signature = args.get(0).substring(1);
222
-            final Command command = CommandManager.getCommand(signature);
218
+
219
+        final CommandArguments args = new CommandArguments(text);
220
+
221
+        if (args.isCommand()) {
222
+            final Command command = CommandManager.getCommand(args.getCommandName());
223 223
             
224 224
             if (command instanceof ValidatingCommand) {
225 225
                 final ValidationResponse vr

Laden…
Annuleren
Opslaan