You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CommandParser.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.commandparser.parsers;
  23. import com.dmdirc.commandparser.CommandInfo;
  24. import com.dmdirc.commandparser.CommandInfoPair;
  25. import com.dmdirc.commandparser.commands.Command;
  26. import com.dmdirc.interfaces.WindowModel;
  27. import javax.annotation.Nonnull;
  28. import javax.annotation.Nullable;
  29. import java.util.Map;
  30. /**
  31. * A command parser takes a line of input from the user, determines if it is an attempt at executing a command (based
  32. * on the character at the start of the string), and handles it appropriately.
  33. */
  34. public interface CommandParser {
  35. /**
  36. * Registers the specified command with this parser.
  37. *
  38. * @param command Command to be registered
  39. * @param info The information the command should be registered with
  40. */
  41. void registerCommand(Command command, CommandInfo info);
  42. /**
  43. * Unregisters the specified command with this parser.
  44. *
  45. * @param info Command information to be unregistered
  46. */
  47. void unregisterCommand(CommandInfo info);
  48. /**
  49. * Retrieves a map of commands known by this command parser.
  50. *
  51. * @return A map of commands known to this parser
  52. */
  53. Map<String, CommandInfoPair> getCommands();
  54. /**
  55. * Parses the specified string as a command.
  56. *
  57. * @param origin The container which received the command
  58. * @param line The line to be parsed
  59. * @param parseChannel Whether or not to try and parse the first argument as a channel name
  60. */
  61. void parseCommand(@Nonnull WindowModel origin, String line, boolean parseChannel);
  62. /**
  63. * Parses the specified string as a command.
  64. *
  65. * @param origin The container which received the command
  66. * @param line The line to be parsed
  67. */
  68. void parseCommand(@Nonnull WindowModel origin, String line);
  69. /**
  70. * Handles the specified string as a non-command.
  71. *
  72. * @param origin The window in which the command was typed
  73. * @param line The line to be parsed
  74. */
  75. void parseCommandCtrl(WindowModel origin, String line);
  76. /**
  77. * Gets the command with the given name that was previously registered with this parser.
  78. *
  79. * @param commandName The name of the command to retrieve.
  80. * @return The command info pair, or {@code null} if the command does not exist.
  81. */
  82. @Nullable
  83. CommandInfoPair getCommand(String commandName);
  84. }