Explorar el Código

Make CommandManager a singleton

CLIENT-84

Change-Id: I48182a9cd7c8f49612025ba208ae90d3bb19ee2b
Depends-On: Ib62d32dbfdadaf38930ceacf667ff533de047599
Reviewed-on: http://gerrit.dmdirc.com/1996
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.6.6b1
Chris Smith hace 13 años
padre
commit
949770857a
Se han modificado 26 ficheros con 95 adiciones y 89 borrados
  1. 2
    2
      src/com/dmdirc/Channel.java
  2. 1
    1
      src/com/dmdirc/GlobalWindow.java
  3. 1
    1
      src/com/dmdirc/Main.java
  4. 2
    3
      src/com/dmdirc/Query.java
  5. 2
    2
      src/com/dmdirc/Server.java
  6. 2
    1
      src/com/dmdirc/actions/wrappers/AliasWrapper.java
  7. 2
    2
      src/com/dmdirc/commandparser/CommandArguments.java
  8. 41
    36
      src/com/dmdirc/commandparser/CommandManager.java
  9. 2
    2
      src/com/dmdirc/commandparser/PopupMenuItem.java
  10. 2
    1
      src/com/dmdirc/commandparser/commands/Command.java
  11. 4
    2
      src/com/dmdirc/commandparser/commands/global/AliasCommand.java
  12. 4
    3
      src/com/dmdirc/commandparser/commands/global/Help.java
  13. 1
    1
      src/com/dmdirc/commandparser/commands/global/Set.java
  14. 2
    1
      src/com/dmdirc/commandparser/commands/server/OpenQuery.java
  15. 1
    2
      src/com/dmdirc/commandparser/parsers/ChannelCommandParser.java
  16. 6
    3
      src/com/dmdirc/commandparser/parsers/CommandParser.java
  17. 1
    2
      src/com/dmdirc/commandparser/parsers/GlobalCommandParser.java
  18. 1
    3
      src/com/dmdirc/commandparser/parsers/QueryCommandParser.java
  19. 1
    4
      src/com/dmdirc/commandparser/parsers/ServerCommandParser.java
  20. 2
    2
      src/com/dmdirc/commandparser/validators/CommandNameValidator.java
  21. 2
    2
      src/com/dmdirc/ui/input/InputHandler.java
  22. 4
    4
      src/com/dmdirc/ui/input/TabCompleter.java
  23. 5
    5
      test/com/dmdirc/commandparser/CommandArgumentsTest.java
  24. 2
    2
      test/com/dmdirc/commandparser/commands/HelpTest.java
  25. 1
    1
      test/com/dmdirc/commandparser/parsers/CommandParserTest.java
  26. 1
    1
      test/com/dmdirc/harness/TestCommandParser.java

+ 2
- 2
src/com/dmdirc/Channel.java Ver fichero

@@ -120,9 +120,9 @@ public class Channel extends MessageTarget implements ConfigChangeListener {
120 120
 
121 121
         tabCompleter = new TabCompleter(server.getTabCompleter());
122 122
         tabCompleter.addEntries(TabCompletionType.COMMAND,
123
-                CommandManager.getCommandNames(CommandType.TYPE_CHANNEL));
123
+                CommandManager.getCommandManager().getCommandNames(CommandType.TYPE_CHANNEL));
124 124
         tabCompleter.addEntries(TabCompletionType.COMMAND,
125
-                CommandManager.getCommandNames(CommandType.TYPE_CHAT));
125
+                CommandManager.getCommandManager().getCommandNames(CommandType.TYPE_CHAT));
126 126
 
127 127
         WindowManager.getWindowManager().addWindow(server, this, focus);
128 128
 

+ 1
- 1
src/com/dmdirc/GlobalWindow.java Ver fichero

@@ -57,7 +57,7 @@ public class GlobalWindow extends WritableFrameContainer {
57 57
 
58 58
         tabCompleter = new TabCompleter();
59 59
         tabCompleter.addEntries(TabCompletionType.COMMAND,
60
-                CommandManager.getCommandNames(CommandType.TYPE_GLOBAL));
60
+                CommandManager.getCommandManager().getCommandNames(CommandType.TYPE_GLOBAL));
61 61
         tabCompleter.addEntries(TabCompletionType.COMMAND,
62 62
                 AliasWrapper.getAliasWrapper().getAliases());
63 63
 

+ 1
- 1
src/com/dmdirc/Main.java Ver fichero

@@ -124,7 +124,7 @@ public final class Main {
124 124
 
125 125
         clp.applySettings();
126 126
 
127
-        CommandManager.initCommands();
127
+        CommandManager.getCommandManager().initCommands();
128 128
 
129 129
         for (String service : new String[]{"ui", "tabcompletion", "parser"}) {
130 130
             ensureExists(pm, service);

+ 2
- 3
src/com/dmdirc/Query.java Ver fichero

@@ -65,7 +65,6 @@ public class Query extends MessageTarget implements PrivateActionListener,
65 65
     /** The tab completer for the query window. */
66 66
     private final TabCompleter tabCompleter;
67 67
 
68
-
69 68
     /**
70 69
      * Creates a new instance of Query.
71 70
      *
@@ -103,9 +102,9 @@ public class Query extends MessageTarget implements PrivateActionListener,
103 102
 
104 103
         tabCompleter = new TabCompleter(server.getTabCompleter());
105 104
         tabCompleter.addEntries(TabCompletionType.COMMAND,
106
-                CommandManager.getCommandNames(CommandType.TYPE_QUERY));
105
+                CommandManager.getCommandManager().getCommandNames(CommandType.TYPE_QUERY));
107 106
         tabCompleter.addEntries(TabCompletionType.COMMAND,
108
-                CommandManager.getCommandNames(CommandType.TYPE_CHAT));
107
+                CommandManager.getCommandManager().getCommandNames(CommandType.TYPE_CHAT));
109 108
 
110 109
         if (!server.getState().isDisconnected()) {
111 110
             reregister();

+ 2
- 2
src/com/dmdirc/Server.java Ver fichero

@@ -203,9 +203,9 @@ public class Server extends WritableFrameContainer
203 203
         tabCompleter.addEntries(TabCompletionType.COMMAND,
204 204
                 AliasWrapper.getAliasWrapper().getAliases());
205 205
         tabCompleter.addEntries(TabCompletionType.COMMAND,
206
-                CommandManager.getCommandNames(CommandType.TYPE_SERVER));
206
+                CommandManager.getCommandManager().getCommandNames(CommandType.TYPE_SERVER));
207 207
         tabCompleter.addEntries(TabCompletionType.COMMAND,
208
-                CommandManager.getCommandNames(CommandType.TYPE_GLOBAL));
208
+                CommandManager.getCommandManager().getCommandNames(CommandType.TYPE_GLOBAL));
209 209
 
210 210
         updateIcon();
211 211
 

+ 2
- 1
src/com/dmdirc/actions/wrappers/AliasWrapper.java Ver fichero

@@ -132,7 +132,8 @@ public final class AliasWrapper extends ActionGroup {
132 132
     public static String getCommandName(final Action action) {
133 133
         for (ActionCondition condition : action.getConditions()) {
134 134
             if (condition.getArg() == 1) {
135
-                return CommandManager.getCommandChar() + condition.getTarget();
135
+                return CommandManager.getCommandManager().getCommandChar()
136
+                        + condition.getTarget();
136 137
             }
137 138
         }
138 139
 

+ 2
- 2
src/com/dmdirc/commandparser/CommandArguments.java Ver fichero

@@ -208,7 +208,7 @@ public class CommandArguments {
208 208
      * @return True if the input was a command, false otherwise
209 209
      */
210 210
     public boolean isCommand() {
211
-        return !line.isEmpty() && line.charAt(0) == CommandManager.getCommandChar();
211
+        return !line.isEmpty() && line.charAt(0) == CommandManager.getCommandManager().getCommandChar();
212 212
     }
213 213
 
214 214
     /**
@@ -218,7 +218,7 @@ public class CommandArguments {
218 218
      */
219 219
     public boolean isSilent() {
220 220
         return isCommand() && line.length() >= 2
221
-                && line.charAt(1) == CommandManager.getSilenceChar();
221
+                && line.charAt(1) == CommandManager.getCommandManager().getSilenceChar();
222 222
     }
223 223
 
224 224
     /**

+ 41
- 36
src/com/dmdirc/commandparser/CommandManager.java Ver fichero

@@ -46,37 +46,33 @@ import java.util.Map;
46 46
  * The command manager creates and manages a single instance of all commands,
47 47
  * and provides methods to load each group of commands into a parser instance.
48 48
  */
49
-public final class CommandManager {
49
+public class CommandManager {
50
+
51
+    /** A singleton instance of the command manager. */
52
+    private static final CommandManager INSTANCE = new CommandManager();
50 53
 
51 54
     /** A list of commands that have been instantiated. */
52
-    private static final Map<CommandInfo, Command> COMMANDS
55
+    private final Map<CommandInfo, Command> commands
53 56
             = new HashMap<CommandInfo, Command>();
54 57
 
55 58
     /** A list of command parsers that have been instantiated. */
56
-    private static final MapList<CommandType, CommandParser> PARSERS
59
+    private final MapList<CommandType, CommandParser> parsers
57 60
             = new MapList<CommandType, CommandParser>();
58 61
 
59 62
     /** The command char we're using. */
60
-    private static char commandChar = IdentityManager.getGlobalConfig()
63
+    private char commandChar = IdentityManager.getGlobalConfig()
61 64
             .getOptionChar("general", "commandchar");
62 65
 
63 66
     /** The silence char we're using. */
64
-    private static char silenceChar = IdentityManager.getGlobalConfig()
67
+    private char silenceChar = IdentityManager.getGlobalConfig()
65 68
             .getOptionChar("general", "silencechar");
66 69
 
67
-    /**
68
-     * Prevents creation of a new command manager.
69
-     */
70
-    private CommandManager() {
71
-        // Do nothing
72
-    }
73
-
74 70
     /**
75 71
      * Returns the current command character.
76 72
      *
77 73
      * @return the current command char
78 74
      */
79
-    public static char getCommandChar() {
75
+    public char getCommandChar() {
80 76
         return commandChar;
81 77
     }
82 78
 
@@ -85,7 +81,7 @@ public final class CommandManager {
85 81
      *
86 82
      * @return the current silence char
87 83
      */
88
-    public static char getSilenceChar() {
84
+    public char getSilenceChar() {
89 85
         return silenceChar;
90 86
     }
91 87
 
@@ -96,7 +92,7 @@ public final class CommandManager {
96 92
      * @param info The information about the command
97 93
      * @since 0.6.3m1
98 94
      */
99
-    public static void registerCommand(final Command command, final CommandInfo info) {
95
+    public void registerCommand(final Command command, final CommandInfo info) {
100 96
         registerCommand(info, command, true);
101 97
     }
102 98
 
@@ -109,7 +105,7 @@ public final class CommandManager {
109 105
      * {@link CommandInfo} to be registered.
110 106
      * @since 0.6.3m1
111 107
      */
112
-    public static <T extends Command & CommandInfo> void registerCommand(final T command) {
108
+    public <T extends Command & CommandInfo> void registerCommand(final T command) {
113 109
         registerCommand(command, command);
114 110
     }
115 111
 
@@ -119,8 +115,8 @@ public final class CommandManager {
119 115
      * @param info The information object for the command that should be unregistered
120 116
      * @since 0.6.3m1
121 117
      */
122
-    public static void unregisterCommand(final CommandInfo info) {
123
-        registerCommand(info, COMMANDS.get(info), false);
118
+    public void unregisterCommand(final CommandInfo info) {
119
+        registerCommand(info, commands.get(info), false);
124 120
     }
125 121
 
126 122
     /**
@@ -132,16 +128,16 @@ public final class CommandManager {
132 128
      * should be unregistered.
133 129
      * @since 0.6.3m1
134 130
      */
135
-    private static void registerCommand(final CommandInfo info, final Command command,
131
+    private void registerCommand(final CommandInfo info, final Command command,
136 132
             final boolean register) {
137
-        if (PARSERS.containsKey(info.getType())) {
138
-            registerCommand(info, command, PARSERS.get(info.getType()), register);
133
+        if (parsers.containsKey(info.getType())) {
134
+            registerCommand(info, command, parsers.get(info.getType()), register);
139 135
         }
140 136
 
141 137
         if (register) {
142
-            COMMANDS.put(info, command);
138
+            commands.put(info, command);
143 139
         } else {
144
-            COMMANDS.remove(info);
140
+            commands.remove(info);
145 141
         }
146 142
 
147 143
         registerCommandName(info, register);
@@ -156,7 +152,7 @@ public final class CommandManager {
156 152
      * @param register Whether to register or unregister the commands
157 153
      * @since 0.6.3m1
158 154
      */
159
-    private static void registerCommand(final CommandInfo info, final Command command,
155
+    private void registerCommand(final CommandInfo info, final Command command,
160 156
             final List<? extends CommandParser> myParsers, final boolean register) {
161 157
         for (CommandParser parser : myParsers) {
162 158
             if (register) {
@@ -176,7 +172,7 @@ public final class CommandManager {
176 172
      * should be unregistered.
177 173
      * @since 0.6.3m1
178 174
      */
179
-    private static void registerCommandName(final CommandInfo command,
175
+    private void registerCommandName(final CommandInfo command,
180 176
             final boolean register) {
181 177
         // Do tab completion
182 178
         final String commandName = getCommandChar() + command.getName();
@@ -215,7 +211,7 @@ public final class CommandManager {
215 211
      * @param register True if the command should be registered, false if it
216 212
      * should be unregistered.
217 213
      */
218
-    private static void registerCommandName(final TabCompleter completer,
214
+    private void registerCommandName(final TabCompleter completer,
219 215
             final String name, final boolean register) {
220 216
         if (register) {
221 217
             completer.addEntry(TabCompletionType.COMMAND, name);
@@ -227,7 +223,7 @@ public final class CommandManager {
227 223
     /**
228 224
      * Instansiates the default commands.
229 225
      */
230
-    public static void initCommands() {
226
+    public void initCommands() {
231 227
         // Chat commands
232 228
         registerCommand(new Me());
233 229
 
@@ -313,7 +309,7 @@ public final class CommandManager {
313 309
      * @param parser The {@link CommandParser} to load commands in to
314 310
      * @param supertypes The types of commands that should be loaded
315 311
      */
316
-    public static void loadCommands(final CommandParser parser,
312
+    public void loadCommands(final CommandParser parser,
317 313
             final CommandType ... supertypes) {
318 314
         for (CommandType supertype : supertypes) {
319 315
             for (CommandType type : supertype.getComponentTypes()) {
@@ -321,7 +317,7 @@ public final class CommandManager {
321 317
                     parser.registerCommand(pair.getValue(), pair.getKey());
322 318
                 }
323 319
 
324
-                PARSERS.add(type, parser);
320
+                parsers.add(type, parser);
325 321
             }
326 322
         }
327 323
     }
@@ -333,7 +329,7 @@ public final class CommandManager {
333 329
      * @param name The name to look for
334 330
      * @return A command with a matching signature, or null if none were found
335 331
      */
336
-    public static Map.Entry<CommandInfo, Command> getCommand(final String name) {
332
+    public Map.Entry<CommandInfo, Command> getCommand(final String name) {
337 333
         return getCommand(null, name);
338 334
     }
339 335
 
@@ -344,7 +340,7 @@ public final class CommandManager {
344 340
      * @param name The name to look for
345 341
      * @return A command with a matching signature, or null if none were found
346 342
      */
347
-    public static Map.Entry<CommandInfo, Command> getCommand(final CommandType type,
343
+    public Map.Entry<CommandInfo, Command> getCommand(final CommandType type,
348 344
             final String name) {
349 345
         final Map<CommandInfo, Command> res = getCommands(type, name);
350 346
 
@@ -357,7 +353,7 @@ public final class CommandManager {
357 353
      * @param command The name of the command to test
358 354
      * @return True iff the command is a channel command, false otherwise
359 355
      */
360
-    public static boolean isChannelCommand(final String command) {
356
+    public boolean isChannelCommand(final String command) {
361 357
         return getCommand(CommandType.TYPE_CHANNEL, command) != null
362 358
                 || getCommand(CommandType.TYPE_CHAT, command) != null;
363 359
     }
@@ -368,7 +364,7 @@ public final class CommandManager {
368 364
      * @param type The type of command to list
369 365
      * @return A list of command names
370 366
      */
371
-    public static List<String> getCommandNames(final CommandType type) {
367
+    public List<String> getCommandNames(final CommandType type) {
372 368
         final List<String> res = new ArrayList<String>();
373 369
 
374 370
         for (CommandInfo command : getCommands(type).keySet()) {
@@ -386,7 +382,7 @@ public final class CommandManager {
386 382
      * @return A map of commands
387 383
      * @since 0.6.3m1
388 384
      */
389
-    public static Map<CommandInfo, Command> getCommands(final CommandType type) {
385
+    public Map<CommandInfo, Command> getCommands(final CommandType type) {
390 386
         return getCommands(type, null);
391 387
     }
392 388
 
@@ -399,11 +395,11 @@ public final class CommandManager {
399 395
      * @return A map of {@link CommandInfo}s and their associated {@link Command}.
400 396
      * @since 0.6.3m1
401 397
      */
402
-    private static Map<CommandInfo, Command> getCommands(final CommandType type,
398
+    private Map<CommandInfo, Command> getCommands(final CommandType type,
403 399
             final String name) {
404 400
         final Map<CommandInfo, Command> res = new HashMap<CommandInfo, Command>();
405 401
 
406
-        for (Map.Entry<CommandInfo, Command> entry : COMMANDS.entrySet()) {
402
+        for (Map.Entry<CommandInfo, Command> entry : commands.entrySet()) {
407 403
             if ((type == null || type.equals(entry.getKey().getType()))
408 404
                     && (name == null || name.equals(entry.getKey().getName()))) {
409 405
                 res.put(entry.getKey(), entry.getValue());
@@ -413,4 +409,13 @@ public final class CommandManager {
413 409
         return res;
414 410
     }
415 411
 
412
+    /**
413
+     * Retrieves a singleton instance of the CommandManager.
414
+     *
415
+     * @return A singleton instance of the CommandManager.
416
+     */
417
+    public static CommandManager getCommandManager() {
418
+        return INSTANCE;
419
+    }
420
+
416 421
 }

+ 2
- 2
src/com/dmdirc/commandparser/PopupMenuItem.java Ver fichero

@@ -141,7 +141,7 @@ public class PopupMenuItem {
141 141
                     builder.append("\n");
142 142
                 }
143 143
 
144
-                builder.append(CommandManager.getCommandChar());
144
+                builder.append(CommandManager.getCommandManager().getCommandChar());
145 145
                 builder.append(String.format(actualCommand, args));
146 146
                 offset = 0;
147 147
             }
@@ -156,7 +156,7 @@ public class PopupMenuItem {
156 156
                 builder.append("\n");
157 157
             }
158 158
 
159
-            builder.append(CommandManager.getCommandChar());
159
+            builder.append(CommandManager.getCommandManager().getCommandChar());
160 160
             builder.append(String.format(actualCommand, args));
161 161
         }
162 162
 

+ 2
- 1
src/com/dmdirc/commandparser/commands/Command.java Ver fichero

@@ -63,7 +63,8 @@ public abstract class Command {
63 63
      */
64 64
     protected final void showUsage(final FrameContainer target,
65 65
             final boolean isSilent, final String name, final String args) {
66
-        sendLine(target, isSilent, "commandUsage", CommandManager.getCommandChar(),
66
+        sendLine(target, isSilent, "commandUsage",
67
+                CommandManager.getCommandManager().getCommandChar(),
67 68
                 name, args);
68 69
     }
69 70
 

+ 4
- 2
src/com/dmdirc/commandparser/commands/global/AliasCommand.java Ver fichero

@@ -54,7 +54,8 @@ public class AliasCommand extends Command implements
54 54
 
55 55
         if (args.getArguments()[0].equalsIgnoreCase("--remove")) {
56 56
             final String name
57
-                    = args.getArguments()[1].charAt(0) == CommandManager.getCommandChar()
57
+                    = args.getArguments()[1].charAt(0)
58
+                    == CommandManager.getCommandManager().getCommandChar()
58 59
                     ? args.getArguments()[1].substring(1) : args.getArguments()[1];
59 60
 
60 61
             if (doRemove(name)) {
@@ -68,7 +69,8 @@ public class AliasCommand extends Command implements
68 69
             return;
69 70
         }
70 71
 
71
-        final String name = args.getArguments()[0].charAt(0) == CommandManager.getCommandChar()
72
+        final String name = args.getArguments()[0].charAt(0)
73
+                == CommandManager.getCommandManager().getCommandChar()
72 74
                 ? args.getArguments()[0].substring(1) : args.getArguments()[0];
73 75
 
74 76
         for (Action alias : AliasWrapper.getAliasWrapper()) {

+ 4
- 3
src/com/dmdirc/commandparser/commands/global/Help.java Ver fichero

@@ -105,10 +105,11 @@ public class Help extends Command implements IntelligentCommand, CommandInfo {
105 105
             final String name) {
106 106
         Map.Entry<CommandInfo, Command> command = null;
107 107
 
108
-        if (name.length() > 0 && name.charAt(0) == CommandManager.getCommandChar()) {
109
-            command = CommandManager.getCommand(name.substring(1));
108
+        if (name.length() > 0 && name.charAt(0)
109
+                == CommandManager.getCommandManager().getCommandChar()) {
110
+            command = CommandManager.getCommandManager().getCommand(name.substring(1));
110 111
         } else {
111
-            command = CommandManager.getCommand(name);
112
+            command = CommandManager.getCommandManager().getCommand(name);
112 113
         }
113 114
 
114 115
         if (command == null) {

+ 1
- 1
src/com/dmdirc/commandparser/commands/global/Set.java Ver fichero

@@ -155,7 +155,7 @@ public class Set extends Command implements IntelligentCommand, CommandInfo {
155 155
         final StringBuffer output = new StringBuffer(67);
156 156
 
157 157
         output.append("Valid domains (use ");
158
-        output.append(CommandManager.getCommandChar());
158
+        output.append(CommandManager.getCommandManager().getCommandChar());
159 159
         output.append("set <domain> to see options within a domain): ");
160 160
 
161 161
         for (String domain : manager.getDomains()) {

+ 2
- 1
src/com/dmdirc/commandparser/commands/server/OpenQuery.java Ver fichero

@@ -58,7 +58,8 @@ public class OpenQuery extends Command implements IntelligentCommand,
58 58
         if (server.getParser().isValidChannelName(args.getArguments()[0])) {
59 59
             sendLine(origin, args.isSilent(), FORMAT_ERROR, "You can't open a query "
60 60
                     + "with a channel; maybe you meant " + Styliser.CODE_FIXED
61
-                    + Styliser.CODE_BOLD + CommandManager.getCommandChar()
61
+                    + Styliser.CODE_BOLD
62
+                    + CommandManager.getCommandManager().getCommandChar()
62 63
                     + (args.getArguments().length > 1 ? "msg" : "join") + " "
63 64
                     + args.getArgumentsAsString()
64 65
                     + Styliser.CODE_BOLD + Styliser.CODE_FIXED + "?");

+ 1
- 2
src/com/dmdirc/commandparser/parsers/ChannelCommandParser.java Ver fichero

@@ -27,7 +27,6 @@ import com.dmdirc.FrameContainer;
27 27
 import com.dmdirc.Server;
28 28
 import com.dmdirc.commandparser.CommandArguments;
29 29
 import com.dmdirc.commandparser.CommandInfo;
30
-import com.dmdirc.commandparser.CommandManager;
31 30
 import com.dmdirc.commandparser.CommandType;
32 31
 import com.dmdirc.commandparser.commands.Command;
33 32
 import com.dmdirc.commandparser.commands.context.ChannelCommandContext;
@@ -72,7 +71,7 @@ public class ChannelCommandParser extends ChatCommandParser {
72 71
     /** {@inheritDoc} */
73 72
     @Override
74 73
     protected void loadCommands() {
75
-        CommandManager.loadCommands(this, CommandType.TYPE_GLOBAL,
74
+        commandManager.loadCommands(this, CommandType.TYPE_GLOBAL,
76 75
                 CommandType.TYPE_SERVER, CommandType.TYPE_CHANNEL);
77 76
     }
78 77
 

+ 6
- 3
src/com/dmdirc/commandparser/parsers/CommandParser.java Ver fichero

@@ -67,6 +67,9 @@ public abstract class CommandParser implements Serializable {
67 67
      */
68 68
     private final RollingList<PreviousCommand> history;
69 69
 
70
+    /** Command manager to use. */
71
+    protected final CommandManager commandManager = CommandManager.getCommandManager();
72
+
70 73
     /** Creates a new instance of CommandParser. */
71 74
     protected CommandParser() {
72 75
         commands = new HashMap<String, CommandInfoPair>();
@@ -171,7 +174,7 @@ public abstract class CommandParser implements Serializable {
171 174
 
172 175
         if (cargs.length == 0 || !parseChannel || origin == null
173 176
                 || origin.getServer() == null
174
-                || !CommandManager.isChannelCommand(command)) {
177
+                || !commandManager.isChannelCommand(command)) {
175 178
             return false;
176 179
         }
177 180
 
@@ -191,11 +194,11 @@ public abstract class CommandParser implements Serializable {
191 194
 
192 195
                 if (server.hasChannel(channel)) {
193 196
                     server.getChannel(channel).getCommandParser()
194
-                            .parseCommand(origin, window, CommandManager.getCommandChar()
197
+                            .parseCommand(origin, window, commandManager.getCommandChar()
195 198
                             + args.getCommandName() + " " + args.getWordsAsString(2), false);
196 199
                 } else {
197 200
                     final Map.Entry<CommandInfo, Command> actCommand
198
-                            = CommandManager.getCommand(CommandType.TYPE_CHANNEL, command);
201
+                            = commandManager.getCommand(CommandType.TYPE_CHANNEL, command);
199 202
 
200 203
                     if (actCommand != null && actCommand.getValue() instanceof ExternalCommand) {
201 204
                         ((ExternalCommand) actCommand.getValue()).execute(

+ 1
- 2
src/com/dmdirc/commandparser/parsers/GlobalCommandParser.java Ver fichero

@@ -25,7 +25,6 @@ package com.dmdirc.commandparser.parsers;
25 25
 import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.commandparser.CommandArguments;
27 27
 import com.dmdirc.commandparser.CommandInfo;
28
-import com.dmdirc.commandparser.CommandManager;
29 28
 import com.dmdirc.commandparser.CommandType;
30 29
 import com.dmdirc.commandparser.commands.Command;
31 30
 import com.dmdirc.commandparser.commands.context.CommandContext;
@@ -71,7 +70,7 @@ public class GlobalCommandParser extends CommandParser {
71 70
     /** Loads the relevant commands into the parser. */
72 71
     @Override
73 72
     protected void loadCommands() {
74
-        CommandManager.loadCommands(this, CommandType.TYPE_GLOBAL);
73
+        commandManager.loadCommands(this, CommandType.TYPE_GLOBAL);
75 74
     }
76 75
 
77 76
     /** {@inheritDoc} */

+ 1
- 3
src/com/dmdirc/commandparser/parsers/QueryCommandParser.java Ver fichero

@@ -27,7 +27,6 @@ import com.dmdirc.Query;
27 27
 import com.dmdirc.Server;
28 28
 import com.dmdirc.commandparser.CommandArguments;
29 29
 import com.dmdirc.commandparser.CommandInfo;
30
-import com.dmdirc.commandparser.CommandManager;
31 30
 import com.dmdirc.commandparser.CommandType;
32 31
 import com.dmdirc.commandparser.commands.Command;
33 32
 import com.dmdirc.commandparser.commands.context.QueryCommandContext;
@@ -36,7 +35,6 @@ import com.dmdirc.ui.interfaces.Window;
36 35
 /**
37 36
  * A command parser that is tailored for use in a query environment. Handles
38 37
  * both query and server commands.
39
- * @author chris
40 38
  */
41 39
 public class QueryCommandParser extends ChatCommandParser {
42 40
 
@@ -74,7 +72,7 @@ public class QueryCommandParser extends ChatCommandParser {
74 72
     /** Loads the relevant commands into the parser. */
75 73
     @Override
76 74
     protected void loadCommands() {
77
-        CommandManager.loadCommands(this, CommandType.TYPE_GLOBAL,
75
+        commandManager.loadCommands(this, CommandType.TYPE_GLOBAL,
78 76
                 CommandType.TYPE_SERVER, CommandType.TYPE_QUERY);
79 77
     }
80 78
 

+ 1
- 4
src/com/dmdirc/commandparser/parsers/ServerCommandParser.java Ver fichero

@@ -27,7 +27,6 @@ import com.dmdirc.Server;
27 27
 import com.dmdirc.ServerState;
28 28
 import com.dmdirc.commandparser.CommandArguments;
29 29
 import com.dmdirc.commandparser.CommandInfo;
30
-import com.dmdirc.commandparser.CommandManager;
31 30
 import com.dmdirc.commandparser.CommandType;
32 31
 import com.dmdirc.commandparser.commands.Command;
33 32
 import com.dmdirc.commandparser.commands.context.ServerCommandContext;
@@ -35,8 +34,6 @@ import com.dmdirc.ui.interfaces.Window;
35 34
 
36 35
 /**
37 36
  * A command parser used in the context of a server.
38
- *
39
- * @author chris
40 37
  */
41 38
 public class ServerCommandParser extends GlobalCommandParser {
42 39
 
@@ -65,7 +62,7 @@ public class ServerCommandParser extends GlobalCommandParser {
65 62
     /** Loads the relevant commands into the parser. */
66 63
     @Override
67 64
     protected void loadCommands() {
68
-        CommandManager.loadCommands(this, CommandType.TYPE_GLOBAL, CommandType.TYPE_SERVER);
65
+        commandManager.loadCommands(this, CommandType.TYPE_GLOBAL, CommandType.TYPE_SERVER);
69 66
     }
70 67
 
71 68
     /** {@inheritDoc} */

+ 2
- 2
src/com/dmdirc/commandparser/validators/CommandNameValidator.java Ver fichero

@@ -42,8 +42,8 @@ public class CommandNameValidator extends ValidatorChain<String> {
42 42
     public CommandNameValidator() {
43 43
         super(new RegexStringValidator("^[^\\s]*$", "Cannot contain spaces"),
44 44
                 new RegexStringValidator("^[^"
45
-                + Pattern.quote(String.valueOf(CommandManager.getCommandChar()))
46
-                + "].*$", "Cannot start with a " + CommandManager.getCommandChar()));
45
+                + Pattern.quote(String.valueOf(CommandManager.getCommandManager().getCommandChar()))
46
+                + "].*$", "Cannot start with a " + CommandManager.getCommandManager().getCommandChar()));
47 47
     }
48 48
 
49 49
 }

+ 2
- 2
src/com/dmdirc/ui/input/InputHandler.java Ver fichero

@@ -221,7 +221,7 @@ public abstract class InputHandler implements ConfigChangeListener {
221 221
 
222 222
         if (args.isCommand()) {
223 223
             final Map.Entry<CommandInfo, Command> command
224
-                    = CommandManager.getCommand(args.getCommandName());
224
+                    = CommandManager.getCommandManager().getCommand(args.getCommandName());
225 225
 
226 226
             if (command != null && command.getValue() instanceof ValidatingCommand) {
227 227
                 final ValidationResponse vr = ((ValidatingCommand) command.getValue())
@@ -432,7 +432,7 @@ public abstract class InputHandler implements ConfigChangeListener {
432 432
         LOGGER.log(Level.FINER, "Offsets: start: {0}, end: {1}",
433 433
                 new Object[]{start, end});
434 434
 
435
-        if (start > 0 && text.charAt(0) == CommandManager.getCommandChar()) {
435
+        if (start > 0 && text.charAt(0) == CommandManager.getCommandManager().getCommandChar()) {
436 436
             doCommandTabCompletion(text, start, end, shiftPressed);
437 437
         } else {
438 438
             doNormalTabCompletion(text, start, end, shiftPressed,  null);

+ 4
- 4
src/com/dmdirc/ui/input/TabCompleter.java Ver fichero

@@ -140,11 +140,11 @@ public class TabCompleter {
140 140
         entries.add(type, entry);
141 141
 
142 142
         if (type == TabCompletionType.COMMAND && entry.length() > 1
143
-                && entry.charAt(0) == CommandManager.getCommandChar()
144
-                && entry.charAt(1) != CommandManager.getSilenceChar()) {
143
+                && entry.charAt(0) == CommandManager.getCommandManager().getCommandChar()
144
+                && entry.charAt(1) != CommandManager.getCommandManager().getSilenceChar()) {
145 145
             // If we're adding a command name that doesn't include the silence
146 146
             // character, also add a version with the silence char
147
-            addEntry(type, entry.substring(0, 1) + CommandManager.getSilenceChar()
147
+            addEntry(type, entry.substring(0, 1) + CommandManager.getCommandManager().getSilenceChar()
148 148
                     + entry.substring(1));
149 149
         }
150 150
     }
@@ -241,7 +241,7 @@ public class TabCompleter {
241 241
         }
242 242
 
243 243
         final Map.Entry<CommandInfo, Command> command
244
-                = CommandManager.getCommand(args.getCommandName());
244
+                = CommandManager.getCommandManager().getCommand(args.getCommandName());
245 245
 
246 246
         AdditionalTabTargets targets = null;
247 247
 

+ 5
- 5
test/com/dmdirc/commandparser/CommandArgumentsTest.java Ver fichero

@@ -83,17 +83,17 @@ public class CommandArgumentsTest {
83 83
 
84 84
     @Test
85 85
     public void testIsCommand() {
86
-        assertTrue(new CommandArguments(CommandManager.getCommandChar() + "").isCommand());
87
-        assertTrue(new CommandArguments(CommandManager.getCommandChar() + "foo bar").isCommand());
88
-        assertFalse(new CommandArguments(" " + CommandManager.getCommandChar()).isCommand());
86
+        assertTrue(new CommandArguments(CommandManager.getCommandManager().getCommandChar() + "").isCommand());
87
+        assertTrue(new CommandArguments(CommandManager.getCommandManager().getCommandChar() + "foo bar").isCommand());
88
+        assertFalse(new CommandArguments(" " + CommandManager.getCommandManager().getCommandChar()).isCommand());
89 89
         assertFalse(new CommandArguments("").isCommand());
90 90
         assertFalse(new CommandArguments("foo").isCommand());
91 91
     }
92 92
 
93 93
     @Test
94 94
     public void testIsSilent() {
95
-        final char c = CommandManager.getCommandChar();
96
-        final char s = CommandManager.getSilenceChar();
95
+        final char c = CommandManager.getCommandManager().getCommandChar();
96
+        final char s = CommandManager.getCommandManager().getSilenceChar();
97 97
 
98 98
         assertTrue(new CommandArguments(c + "" + s).isSilent());
99 99
         assertFalse(new CommandArguments("f" + s).isSilent());

+ 2
- 2
test/com/dmdirc/commandparser/commands/HelpTest.java Ver fichero

@@ -60,10 +60,10 @@ public class HelpTest {
60 60
         final List<Object[]> res = new LinkedList<Object[]>();
61 61
 
62 62
         IdentityManager.load();
63
-        CommandManager.initCommands();
63
+        CommandManager.getCommandManager().initCommands();
64 64
 
65 65
         for (CommandType type : CommandType.values()) {
66
-            for (CommandInfo command : CommandManager.getCommands(type).keySet()) {
66
+            for (CommandInfo command : CommandManager.getCommandManager().getCommands(type).keySet()) {
67 67
                 if (command.showInHelp()) {
68 68
                     res.add(new Object[]{command});
69 69
                 }

+ 1
- 1
test/com/dmdirc/commandparser/parsers/CommandParserTest.java Ver fichero

@@ -35,7 +35,7 @@ public class CommandParserTest {
35 35
     @BeforeClass
36 36
     public static void setUpClass() throws Exception {
37 37
         IdentityManager.load();
38
-        CommandManager.initCommands();
38
+        CommandManager.getCommandManager().initCommands();
39 39
     }
40 40
 
41 41
     @Test

+ 1
- 1
test/com/dmdirc/harness/TestCommandParser.java Ver fichero

@@ -46,7 +46,7 @@ public class TestCommandParser extends CommandParser {
46 46
 
47 47
     @Override
48 48
     protected void loadCommands() {
49
-        CommandManager.loadCommands(this, CommandType.TYPE_GLOBAL);
49
+        CommandManager.getCommandManager().loadCommands(this, CommandType.TYPE_GLOBAL);
50 50
     }
51 51
 
52 52
     @Override

Loading…
Cancelar
Guardar