浏览代码

Fully javadoc'd the command parser package

git-svn-id: http://svn.dmdirc.com/trunk@145 00569f92-eb28-0410-84fd-f71c24880f
tags/0.1
Chris Smith 17 年前
父节点
当前提交
afc4211eb0

+ 7
- 1
src/uk/org/ownage/dmdirc/commandparser/ChannelCommand.java 查看文件

@@ -26,7 +26,7 @@ import uk.org.ownage.dmdirc.Channel;
26 26
 import uk.org.ownage.dmdirc.Server;
27 27
 
28 28
 /**
29
- *
29
+ * Represents a command which can be performed only in the context of a channel
30 30
  * @author chris
31 31
  */
32 32
 public abstract class ChannelCommand extends Command {
@@ -36,5 +36,11 @@ public abstract class ChannelCommand extends Command {
36 36
         super();
37 37
     }
38 38
     
39
+    /**
40
+     * Executes this command
41
+     * @param server The server instance that this command is being executed on
42
+     * @param channel The channel instance that this command is being executed on
43
+     * @param args Arguments passed to this command
44
+     */    
39 45
     public abstract void execute(Server server, Channel channel, String... args);    
40 46
 }

+ 35
- 6
src/uk/org/ownage/dmdirc/commandparser/ChannelCommandParser.java 查看文件

@@ -26,34 +26,63 @@ import uk.org.ownage.dmdirc.Channel;
26 26
 import uk.org.ownage.dmdirc.Server;
27 27
 
28 28
 /**
29
- *
29
+ * A command parser that is tailored for use in a channel environment. Handles
30
+ * both channel and server commands.
30 31
  * @author chris
31 32
  */
32 33
 public class ChannelCommandParser extends CommandParser {
33 34
     
35
+    /**
36
+     * The server instance that this parser is attached to
37
+     */
34 38
     private Server server;
39
+    /**
40
+     * The channel instance that this parser is attached to
41
+     */
35 42
     private Channel channel;
36 43
     
37
-    /** Creates a new instance of ChannelCommandParser */
44
+    /**
45
+     * Creates a new instance of ChannelCommandParser
46
+     * @param server The server instance that this parser is attached to
47
+     * @param channel The channel instance that this parser is attached to
48
+     */
38 49
     public ChannelCommandParser(Server server, Channel channel) {
39 50
         super();
40 51
         
41 52
         this.server = server;
42 53
         this.channel = channel;
43 54
     }
44
-
55
+    
56
+    /** Loads the relevant commands into the parser */
45 57
     protected void loadCommands() {
46 58
         throw new UnsupportedOperationException("Not implemented yet");
47 59
     }
48
-
60
+    
61
+    /**
62
+     * Executes the specified command with the given arguments.
63
+     * @param command The command to be executed
64
+     * @param args The arguments to the command
65
+     */    
49 66
     protected void executeCommand(Command command, String... args) {
50 67
         throw new UnsupportedOperationException("Not implemented yet");
51 68
     }
52
-
69
+    
70
+    /**
71
+     * Called when the user attempted to issue a command (i.e., used the command
72
+     * character) that wasn't found. It could be that the command has a different
73
+     * arity, or that it plain doesn't exist.
74
+     * @param command The command the user tried to execute
75
+     * @param args The arguments passed to the command
76
+     */    
53 77
     protected void handleInvalidCommand(String command, String... args) {
54 78
         throw new UnsupportedOperationException("Not implemented yet");
55 79
     }
56
-
80
+    
81
+    /**
82
+     * Called when the input was a line of text that was not a command. This normally
83
+     * means it is sent to the server/channel/user as-is, with no further processing.
84
+     * @param line The line input by the user
85
+     */    
57 86
     protected void handleNonCommand(String line) {
58 87
         throw new UnsupportedOperationException("Not implemented yet");
59 88
     }

+ 36
- 1
src/uk/org/ownage/dmdirc/commandparser/Command.java 查看文件

@@ -25,21 +25,48 @@ package uk.org.ownage.dmdirc.commandparser;
25 25
 import uk.org.ownage.dmdirc.Server;
26 26
 
27 27
 /**
28
- *
28
+ * Represents a generic command
29 29
  * @author chris
30 30
  */
31 31
 public abstract class Command {
32 32
     
33
+    /**
34
+     * The name of this command (i.e., the string used by the user to execute it)
35
+     */
33 36
     protected String name;
37
+    /**
38
+     * The arity of this command
39
+     */
34 40
     protected int arity = 0;
41
+    /**
42
+     * Whether this command is polyadic or not
43
+     */
35 44
     protected boolean polyadic;
45
+    /**
46
+     * Whether this command should be shown in help output
47
+     */
36 48
     protected boolean show = true;
49
+    /**
50
+     * A textual description of this command's arguments
51
+     */
37 52
     protected String arguments = "<unknown>";
53
+    /**
54
+     * A description of this command
55
+     */
38 56
     protected String description = "unknown";
39 57
     
58
+    /**
59
+     * Creates a new instance of Command
60
+     */
40 61
     public Command() {
41 62
     }
42 63
     
64
+    /**
65
+     * Returns the signature of this command. For polyadic commands, the signature
66
+     * is simply the name. For other commands, the signature is a concatenation of
67
+     * the name, a literal "/", and the arity.
68
+     * @return The signature of this command
69
+     */
43 70
     public String getSignature() {
44 71
         if (polyadic) {
45 72
             return name;
@@ -48,10 +75,18 @@ public abstract class Command {
48 75
         }
49 76
     }
50 77
     
78
+    /**
79
+     * Returns whether or not this command should be shown in help messages
80
+     * @return True iff the command should be shown, false otherwise
81
+     */
51 82
     public boolean showInHelp() {
52 83
         return show;
53 84
     }
54 85
     
86
+    /**
87
+     * Returns a string representing the help message for this command
88
+     * @return the help message for this command
89
+     */
55 90
     public String getHelp() {
56 91
         return name+" "+arguments+" - "+description;
57 92
     }

+ 13
- 1
src/uk/org/ownage/dmdirc/commandparser/CommandManager.java 查看文件

@@ -26,17 +26,29 @@ import java.util.Vector;
26 26
 import uk.org.ownage.dmdirc.commandparser.commands.*;
27 27
 
28 28
 /**
29
- *
29
+ * The command manager creates and manages a single instance of all commands,
30
+ * and provides methods to load each group of commands into a parser instance
30 31
  * @author chris
31 32
  */
32 33
 public class CommandManager {
33 34
     
35
+    /**
36
+     * The commands that have been instansiated
37
+     */
34 38
     private static Vector<Command> serverCommands;
35 39
            
40
+    /**
41
+     * Loads all channel commands into the specified parser
42
+     * @param parser The parser to load commands into
43
+     */
36 44
     public static void loadChannelCommands(CommandParser parser) {
37 45
         throw new UnsupportedOperationException("Not implemented yet");        
38 46
     }
39 47
     
48
+    /**
49
+     * Loads all server commands into the specified parser
50
+     * @param parser The parser to load commands into
51
+     */
40 52
     public static void loadServerCommands(CommandParser parser) {
41 53
         if (serverCommands == null) {
42 54
             serverCommands = new Vector<Command>(0,1);

+ 31
- 2
src/uk/org/ownage/dmdirc/commandparser/CommandParser.java 查看文件

@@ -26,11 +26,16 @@ import java.util.Hashtable;
26 26
 import uk.org.ownage.dmdirc.Config;
27 27
 
28 28
 /**
29
- *
29
+ * Represents a generic command parser. A command parser takes a line of input
30
+ * from the user, determines if it is an attempt at executing a command (based
31
+ * on the character at the start of the string), and handles it appropriately.
30 32
  * @author chris
31 33
  */
32 34
 abstract public class CommandParser {
33 35
     
36
+    /**
37
+     * Commands that are associated with this parser
38
+     */
34 39
     private Hashtable<String,Command> commands;
35 40
     
36 41
     /** Creates a new instance of CommandParser */
@@ -42,11 +47,18 @@ abstract public class CommandParser {
42 47
     /** Loads the relevant commands into the parser */
43 48
     protected abstract void loadCommands();
44 49
     
50
+    /**
51
+     * Registers the specified command with this parser
52
+     * @param command Command to be registered
53
+     */
45 54
     public void registerCommand(Command command) {
46 55
         commands.put(command.getSignature(), command);
47 56
     }
48 57
     
49
-    /** Parses the specified string as a command */
58
+    /**
59
+     * Parses the specified string as a command
60
+     * @param line The line to be parsed
61
+     */
50 62
     public void parseCommand(String line) {
51 63
         if (line.charAt(0) == Config.getOption("general","commandchar").charAt(0)) {
52 64
             String[] args = line.split(" ");
@@ -72,9 +84,26 @@ abstract public class CommandParser {
72 84
         }
73 85
     }
74 86
     
87
+    /**
88
+     * Executes the specified command with the given arguments.
89
+     * @param command The command to be executed
90
+     * @param args The arguments to the command
91
+     */
75 92
     abstract protected void executeCommand(Command command, String... args);
76 93
     
94
+    /**
95
+     * Called when the user attempted to issue a command (i.e., used the command
96
+     * character) that wasn't found. It could be that the command has a different
97
+     * arity, or that it plain doesn't exist.
98
+     * @param command The command the user tried to execute
99
+     * @param args The arguments passed to the command
100
+     */
77 101
     abstract protected void handleInvalidCommand(String command, String... args);
78 102
 
103
+    /**
104
+     * Called when the input was a line of text that was not a command. This normally
105
+     * means it is sent to the server/channel/user as-is, with no further processing.
106
+     * @param line The line input by the user
107
+     */
79 108
     abstract protected void handleNonCommand(String line);
80 109
 }

+ 7
- 1
src/uk/org/ownage/dmdirc/commandparser/ServerCommand.java 查看文件

@@ -26,7 +26,8 @@ import uk.org.ownage.dmdirc.Channel;
26 26
 import uk.org.ownage.dmdirc.Server;
27 27
 
28 28
 /**
29
- *
29
+ * Represents a generic server command. Server commands are associated with 
30
+ * a server instance.
30 31
  * @author chris
31 32
  */
32 33
 public abstract class ServerCommand extends Command {
@@ -36,5 +37,10 @@ public abstract class ServerCommand extends Command {
36 37
         super();
37 38
     }
38 39
     
40
+    /**
41
+     * Executes this command
42
+     * @param server The server instance that this command is being executed on
43
+     * @param args Arguments passed to this command
44
+     */    
39 45
     public abstract void execute(Server server, String... args);
40 46
 }

+ 30
- 6
src/uk/org/ownage/dmdirc/commandparser/ServerCommandParser.java 查看文件

@@ -25,32 +25,56 @@ package uk.org.ownage.dmdirc.commandparser;
25 25
 import uk.org.ownage.dmdirc.Server;
26 26
 
27 27
 /**
28
- *
28
+ * A command parser used in the context of a server
29 29
  * @author chris
30 30
  */
31 31
 public class ServerCommandParser extends CommandParser {
32 32
     
33
+    /**
34
+     * The server instance that this parser is attached to
35
+     */
33 36
     private Server server;
34 37
     
35
-    /** Creates a new instance of ServerCommandParser */
38
+    /**
39
+     * Creates a new instance of ServerCommandParser
40
+     * @param server The server instance that this parser is attached to
41
+     */
36 42
     public ServerCommandParser(Server server) {
37 43
         super();
38 44
         
39 45
         this.server = server;
40 46
     }
41
-
47
+    
48
+    /** Loads the relevant commands into the parser */
42 49
     protected void loadCommands() {
43 50
         CommandManager.loadServerCommands(this);
44 51
     }
45
-
52
+    
53
+    /**
54
+     * Executes the specified command with the given arguments.
55
+     * @param command The command to be executed
56
+     * @param args The arguments to the command
57
+     */
46 58
     protected void executeCommand(Command command, String... args) {
47 59
         ((ServerCommand)command).execute(server, args);
48 60
     }
49
-
61
+    
62
+    /**
63
+     * Called when the user attempted to issue a command (i.e., used the command
64
+     * character) that wasn't found. It could be that the command has a different
65
+     * arity, or that it plain doesn't exist.
66
+     * @param command The command the user tried to execute
67
+     * @param args The arguments passed to the command
68
+     */
50 69
     protected void handleInvalidCommand(String command, String... args) {
51 70
         server.addLine("Unknown command: "+command+"/"+(args.length-1));
52 71
     }
53
-
72
+    
73
+    /**
74
+     * Called when the input was a line of text that was not a command. This normally
75
+     * means it is sent to the server/channel/user as-is, with no further processing.
76
+     * @param line The line input by the user
77
+     */
54 78
     protected void handleNonCommand(String line) {
55 79
         server.getParser().sendLine(line);
56 80
     }

+ 7
- 1
src/uk/org/ownage/dmdirc/commandparser/commands/Test.java 查看文件

@@ -27,7 +27,8 @@ import uk.org.ownage.dmdirc.commandparser.Command;
27 27
 import uk.org.ownage.dmdirc.commandparser.ServerCommand;
28 28
 
29 29
 /**
30
- *
30
+ * A sample command. Takes no arguments, and merely prints the SVN ID string of 
31
+ * the IRC parser.
31 32
  * @author chris
32 33
  */
33 34
 public class Test extends ServerCommand {
@@ -42,6 +43,11 @@ public class Test extends ServerCommand {
42 43
         show = true;
43 44
     }
44 45
 
46
+    /**
47
+     * Executes this command
48
+     * @param server The server instance that this command is being executed on
49
+     * @param args Arguments passed to this command
50
+     */
45 51
     public void execute(Server server, String... args) {
46 52
         server.addLine(server.getParser().getSvnInfo());
47 53
     }

正在加载...
取消
保存