Browse Source

Issue 1453: Initial separation of Command and CommandInfo

tags/0.6.3m1rc1
Chris Smith 15 years ago
parent
commit
1ef0277d3a

+ 9
- 5
src/com/dmdirc/commandparser/CommandInfo.java View File

@@ -27,30 +27,34 @@ package com.dmdirc.commandparser;
27 27
  * 
28 28
  * @author chris
29 29
  */
30
-public abstract class CommandInfo {
30
+public interface CommandInfo {
31 31
           
32 32
     /**
33 33
      * Returns this command's name.
34
+     *
34 35
      * @return The name of this command
35 36
      */
36
-    public abstract String getName();
37
+    String getName();
37 38
     
38 39
     /**
39 40
      * Returns whether or not this command should be shown in help messages.
41
+     *
40 42
      * @return True iff the command should be shown, false otherwise
41 43
      */
42
-    public abstract boolean showInHelp();
44
+    boolean showInHelp();
43 45
     
44 46
     /**
45 47
      * Returns a string representing the help message for this command.
48
+     *
46 49
      * @return the help message for this command
47 50
      */
48
-    public abstract String getHelp();
51
+    String getHelp();
49 52
     
50 53
     /**
51 54
      * Retrieves the type of this command.
55
+     *
52 56
      * @return This command's type
53 57
      */
54
-    public abstract CommandType getType();
58
+    CommandType getType();
55 59
 
56 60
 }

+ 24
- 8
src/com/dmdirc/commandparser/CommandManager.java View File

@@ -103,10 +103,26 @@ public final class CommandManager {
103 103
      * Registers a command with the command manager.
104 104
      * 
105 105
      * @param command The command to be registered
106
+     * @param info The information about the command
107
+     * @since 0.6.3
106 108
      */
107
-    public static void registerCommand(final Command command) {
109
+    public static void registerCommand(final Command command, final CommandInfo info) {
108 110
         registerCommand(command, true);
109 111
     }
112
+
113
+    /**
114
+     * Registers a command with the command manager.
115
+     *
116
+     * @deprecated Introduced for compatibility reasons. Use
117
+     * {@link #registerCommand(Command, CommandInfo)} instead.
118
+     * @param <T> The type that's being registered
119
+     * @param command An object that extends {@link Command} and implements
120
+     * {@link CommandInfo} to be registered.
121
+     * @since 0.6.3
122
+     */
123
+    public static <T extends Command & CommandInfo> void registerCommand(final T command) {
124
+        registerCommand(command, command);
125
+    }
110 126
     
111 127
     /**
112 128
      * Unregisters a command with the command manager.
@@ -170,7 +186,7 @@ public final class CommandManager {
170 186
         
171 187
         for (CommandParser parser : parsers) {
172 188
             if (register) {
173
-                parser.registerCommand(command);
189
+                parser.registerCommand(command, command);
174 190
             } else {
175 191
                 parser.unregisterCommand(command);
176 192
             }
@@ -317,11 +333,11 @@ public final class CommandManager {
317 333
      */
318 334
     public static void loadChannelCommands(final CommandParser parser) {
319 335
         for (Command com : getCommands(CommandType.TYPE_CHANNEL, null)) {
320
-            parser.registerCommand(com);
336
+            parser.registerCommand(com, com);
321 337
         }
322 338
         
323 339
         for (Command com : getCommands(CommandType.TYPE_CHAT, null)) {
324
-            parser.registerCommand(com);
340
+            parser.registerCommand(com, com);
325 341
         }
326 342
         
327 343
         parsers.add(CommandType.TYPE_CHANNEL, parser);
@@ -334,7 +350,7 @@ public final class CommandManager {
334 350
      */
335 351
     public static void loadServerCommands(final CommandParser parser) {
336 352
         for (Command command : getCommands(CommandType.TYPE_SERVER, null)) {
337
-            parser.registerCommand(command);
353
+            parser.registerCommand(command, command);
338 354
         }
339 355
         
340 356
         parsers.add(CommandType.TYPE_SERVER, parser);
@@ -347,7 +363,7 @@ public final class CommandManager {
347 363
      */
348 364
     public static void loadGlobalCommands(final CommandParser parser) {
349 365
         for (Command com : getCommands(CommandType.TYPE_GLOBAL, null)) {
350
-            parser.registerCommand(com);
366
+            parser.registerCommand(com, com);
351 367
         }
352 368
         
353 369
         parsers.add(CommandType.TYPE_GLOBAL, parser);
@@ -360,11 +376,11 @@ public final class CommandManager {
360 376
      */
361 377
     public static void loadQueryCommands(final CommandParser parser) {
362 378
         for (Command com : getCommands(CommandType.TYPE_QUERY, null)) {
363
-            parser.registerCommand(com);
379
+            parser.registerCommand(com, com);
364 380
         }
365 381
         
366 382
         for (Command com : getCommands(CommandType.TYPE_CHAT, null)) {
367
-            parser.registerCommand(com);
383
+            parser.registerCommand(com, com);
368 384
         }
369 385
         
370 386
         parsers.add(CommandType.TYPE_QUERY, parser);

+ 2
- 1
src/com/dmdirc/commandparser/commands/Command.java View File

@@ -30,9 +30,10 @@ import com.dmdirc.ui.messages.Styliser;
30 30
 
31 31
 /**
32 32
  * Represents a generic command.
33
+ *
33 34
  * @author chris
34 35
  */
35
-public abstract class Command extends CommandInfo implements Comparable<Command> {
36
+public abstract class Command implements CommandInfo, Comparable<Command> {
36 37
     
37 38
     /** The format name used for command output. */
38 39
     protected static final String FORMAT_OUTPUT = "commandOutput";

+ 5
- 1
src/com/dmdirc/commandparser/parsers/ChannelCommandParser.java View File

@@ -67,7 +67,8 @@ public final class ChannelCommandParser extends CommandParser {
67 67
         this.channel = newChannel;
68 68
     }
69 69
     
70
-    /** Loads the relevant commands into the parser. */
70
+    /** {@inheritDoc} */
71
+    @Override
71 72
     protected void loadCommands() {
72 73
         CommandManager.loadGlobalCommands(this);
73 74
         CommandManager.loadServerCommands(this);
@@ -75,6 +76,7 @@ public final class ChannelCommandParser extends CommandParser {
75 76
     }
76 77
     
77 78
     /** {@inheritDoc} */
79
+    @Override
78 80
     protected void executeCommand(final InputWindow origin,
79 81
             final boolean isSilent, final Command command, final String... args) {
80 82
         if (command instanceof ChannelCommand) {
@@ -91,9 +93,11 @@ public final class ChannelCommandParser extends CommandParser {
91 93
     /**
92 94
      * Called when the input was a line of text that was not a command. This normally
93 95
      * means it is sent to the server/channel/user as-is, with no further processing.
96
+     *
94 97
      * @param origin The window in which the command was typed
95 98
      * @param line The line input by the user
96 99
      */
100
+    @Override
97 101
     protected void handleNonCommand(final InputWindow origin, final String line) {
98 102
         channel.sendLine(line);
99 103
     }

+ 9
- 5
src/com/dmdirc/commandparser/parsers/CommandParser.java View File

@@ -25,6 +25,7 @@ package com.dmdirc.commandparser.parsers;
25 25
 import com.dmdirc.Server;
26 26
 import com.dmdirc.actions.ActionManager;
27 27
 import com.dmdirc.actions.CoreActionType;
28
+import com.dmdirc.commandparser.CommandInfo;
28 29
 import com.dmdirc.commandparser.CommandManager;
29 30
 import com.dmdirc.commandparser.CommandType;
30 31
 import com.dmdirc.commandparser.commands.Command;
@@ -79,19 +80,22 @@ public abstract class CommandParser implements Serializable {
79 80
     /**
80 81
      * Registers the specified command with this parser.
81 82
      *
83
+     * @since 0.6.3
82 84
      * @param command Command to be registered
85
+     * @param info The information the command should be registered with
83 86
      */
84
-    public final void registerCommand(final Command command) {
85
-        commands.put(command.getName().toLowerCase(), command);
87
+    public final void registerCommand(final Command command, final CommandInfo info) {
88
+        commands.put(info.getName().toLowerCase(), command);
86 89
     }
87 90
 
88 91
     /**
89 92
      * Unregisters the specified command with this parser.
90 93
      *
91
-     * @param command Command to be unregistered
94
+     * @param info Command information to be unregistered
95
+     * @since 0.6.3
92 96
      */
93
-    public final void unregisterCommand(final Command command) {
94
-        commands.remove(command.getName().toLowerCase());
97
+    public final void unregisterCommand(final CommandInfo info) {
98
+        commands.remove(info.getName().toLowerCase());
95 99
     }
96 100
 
97 101
     /**

+ 3
- 0
src/com/dmdirc/commandparser/parsers/GlobalCommandParser.java View File

@@ -67,11 +67,13 @@ public final class GlobalCommandParser extends CommandParser {
67 67
     }
68 68
     
69 69
     /** Loads the relevant commands into the parser. */
70
+    @Override
70 71
     protected void loadCommands() {
71 72
         CommandManager.loadGlobalCommands(this);
72 73
     }
73 74
     
74 75
     /** {@inheritDoc} */
76
+    @Override
75 77
     protected void executeCommand(final InputWindow origin,
76 78
             final boolean isSilent, final Command command, final String... args) {
77 79
         ((GlobalCommand) command).execute(origin, isSilent, args);
@@ -83,6 +85,7 @@ public final class GlobalCommandParser extends CommandParser {
83 85
      * @param origin The window in which the command was typed
84 86
      * @param line The line input by the user
85 87
      */
88
+    @Override
86 89
     protected void handleNonCommand(final InputWindow origin, final String line) {
87 90
         if (origin == null) {
88 91
             Logger.userError(ErrorLevel.MEDIUM, "Invalid global command: " + line);

+ 3
- 0
src/com/dmdirc/commandparser/parsers/QueryCommandParser.java View File

@@ -68,6 +68,7 @@ public final class QueryCommandParser extends CommandParser {
68 68
     }
69 69
     
70 70
     /** Loads the relevant commands into the parser. */
71
+    @Override
71 72
     protected void loadCommands() {
72 73
         CommandManager.loadGlobalCommands(this);
73 74
         CommandManager.loadServerCommands(this);
@@ -75,6 +76,7 @@ public final class QueryCommandParser extends CommandParser {
75 76
     }
76 77
     
77 78
     /** {@inheritDoc} */
79
+    @Override
78 80
     protected void executeCommand(final InputWindow origin,
79 81
             final boolean isSilent, final Command command, final String... args) {
80 82
         if (command instanceof QueryCommand) {
@@ -94,6 +96,7 @@ public final class QueryCommandParser extends CommandParser {
94 96
      * @param origin The window in which the command was typed
95 97
      * @param line The line input by the user
96 98
      */
99
+    @Override
97 100
     protected void handleNonCommand(final InputWindow origin, final String line) {
98 101
         query.sendLine(line);
99 102
     }

+ 3
- 0
src/com/dmdirc/commandparser/parsers/ServerCommandParser.java View File

@@ -58,12 +58,14 @@ public final class ServerCommandParser extends CommandParser {
58 58
     }
59 59
     
60 60
     /** Loads the relevant commands into the parser. */
61
+    @Override
61 62
     protected void loadCommands() {
62 63
         CommandManager.loadGlobalCommands(this);
63 64
         CommandManager.loadServerCommands(this);
64 65
     }
65 66
     
66 67
     /** {@inheritDoc} */
68
+    @Override
67 69
     protected void executeCommand(final InputWindow origin,
68 70
             final boolean isSilent, final Command command, final String... args) {
69 71
         if (command instanceof ServerCommand) {
@@ -79,6 +81,7 @@ public final class ServerCommandParser extends CommandParser {
79 81
      * @param origin The window in which the command was typed
80 82
      * @param line The line input by the user
81 83
      */
84
+    @Override
82 85
     protected void handleNonCommand(final InputWindow origin, final String line) {
83 86
         server.sendLine(line);
84 87
     }

Loading…
Cancel
Save