File Source: Ifplugin.java
/*
P/P * Method: com.dmdirc.commandparser.commands.global.Ifplugin__static_init
*/
1 /*
2 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
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
23 package com.dmdirc.commandparser.commands.global;
24
25 import com.dmdirc.commandparser.CommandArguments;
26 import com.dmdirc.commandparser.CommandManager;
27 import com.dmdirc.commandparser.commands.GlobalCommand;
28 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
29 import com.dmdirc.commandparser.commands.IntelligentCommand;
30 import com.dmdirc.plugins.PluginInfo;
31 import com.dmdirc.plugins.PluginManager;
32 import com.dmdirc.ui.input.AdditionalTabTargets;
33 import com.dmdirc.ui.input.TabCompleter;
34 import com.dmdirc.ui.interfaces.InputWindow;
35
36 import java.util.List;
37
38 /**
39 * The if plugin command allows the user to execute commands based on whether
40 * or not a plugin is loaded.
41 *
42 * @author chris
43 */
44 public final class Ifplugin extends GlobalCommand implements IntelligentCommand {
45
46 /**
47 * Creates a new instance of Ifplugin.
48 */
49 public Ifplugin() {
/*
P/P * Method: void com.dmdirc.commandparser.commands.global.Ifplugin()
*
* Preconditions:
* init'ed(com/dmdirc/commandparser/CommandManager.commandChar)
*/
50 super();
51
52 CommandManager.registerCommand(this);
53 }
54
55 /** {@inheritDoc} */
56 @Override
57 public void execute(final InputWindow origin, final boolean isSilent,
58 final CommandArguments args) {
/*
P/P * Method: void execute(InputWindow, bool, CommandArguments)
*
* Preconditions:
* args != null
* init'ed(args.words)
* (soft) args.line != null
* (soft) init'ed(com.dmdirc.config.ConfigManager$1__static_init.new int[](ConfigManager$1__static_init#1)[...])
* (soft) init'ed(com/dmdirc/commandparser/CommandManager.commandChar)
* (soft) init'ed(com/dmdirc/commandparser/CommandManager.silenceChar)
* (soft) init'ed(com/dmdirc/commandparser/parsers/GlobalCommandParser.me)
* (soft) init'ed(com/dmdirc/config/IdentityManager.globalconfig)
*
* Presumptions:
* com.dmdirc.plugins.PluginManager:getPluginManager(...)@68 != null
* com.dmdirc.ui.interfaces.InputWindow:getCommandParser(...).commands@81 != null
* com.dmdirc.ui.interfaces.InputWindow:getCommandParser(...).history@81 != null
* com.dmdirc.ui.interfaces.InputWindow:getCommandParser(...)@81 != null
* getArguments(...).length@64 >= 1
* ...
*
* Postconditions:
* args.words != null
* com/dmdirc/commandparser/parsers/GlobalCommandParser.me == One-of{old com/dmdirc/commandparser/parsers/GlobalCommandParser.me, &new GlobalCommandParser(getGlobalCommandParser#1)}
* init'ed(com/dmdirc/commandparser/parsers/GlobalCommandParser.me)
* com/dmdirc/config/IdentityManager.globalconfig == One-of{old com/dmdirc/config/IdentityManager.globalconfig, &new ConfigManager(getGlobalConfig#1)}
* init'ed(com/dmdirc/config/IdentityManager.globalconfig)
* init'ed(java.lang.String:split(...)._tainted)
* java.lang.String:split(...)._tainted == 0
* init'ed(java.lang.String:split(...).length)
* java.lang.StringBuilder:toString(...)._tainted == 0
* new ArrayList(getSources#1) num objects <= 1
* ...
*
* Test Vectors:
* origin: Inverse{null}, Addr_Set{null}
* com.dmdirc.plugins.PluginInfo:isLoaded(...)@72: {1}, {0}
* com.dmdirc.plugins.PluginManager:getPluginInfoByName(...)@68: Addr_Set{null}, Inverse{null}
* getArguments(...).length@59: {2..+Inf}, {0,1}
*/
59 if (args.getArguments().length <= 1) {
60 showUsage(origin, isSilent, "ifplugin", "<[!]plugin> <command>");
61 return;
62 }
63
64 final boolean negative = args.getArguments()[0].charAt(0) == '!';
65
66 final String pname = args.getArguments()[0].substring(negative ? 1 : 0);
67
68 final PluginInfo pluginInfo = PluginManager.getPluginManager().getPluginInfoByName(pname);
69
70 boolean result = true;
71
72 if (pluginInfo == null || !pluginInfo.isLoaded()) {
73 result = false;
74 }
75
76 if (result != negative) {
77 if (origin == null) {
78 GlobalCommandParser.getGlobalCommandParser().parseCommand(null,
79 args.getArgumentsAsString(1));
80 } else {
81 origin.getCommandParser().parseCommand(origin, args.getArgumentsAsString(1));
82 }
83 }
84 }
85
86 /** {@inheritDoc} */
87 @Override
88 public String getName() {
/*
P/P * Method: String getName()
*
* Postconditions:
* return_value == &"ifplugin"
*/
89 return "ifplugin";
90 }
91
92 /** {@inheritDoc} */
93 @Override
94 public boolean showInHelp() {
/*
P/P * Method: bool showInHelp()
*
* Postconditions:
* return_value == 1
*/
95 return true;
96 }
97
98 /** {@inheritDoc} */
99 @Override
100 public String getHelp() {
/*
P/P * Method: String getHelp()
*
* Postconditions:
* return_value == &"ifplugin <[!]plugin> <command> - executes a command if the specified plugin is.isn't loaded"
*/
101 return "ifplugin <[!]plugin> <command> - executes a command if the " +
102 "specified plugin is/isn't loaded";
103 }
104
105 /** {@inheritDoc} */
106 @Override
107 public AdditionalTabTargets getSuggestions(final int arg, final List<String> previousArgs) {
108 AdditionalTabTargets res;
109
/*
P/P * Method: AdditionalTabTargets getSuggestions(int, List)
*
* Presumptions:
* com.dmdirc.plugins.PluginManager:getPluginInfos(...)@114 != null
* com.dmdirc.plugins.PluginManager:getPluginManager(...)@114 != null
* com.dmdirc.ui.input.AdditionalTabTargets:excludeAll(...)@111 != null
* java.util.Iterator:next(...)@114 != null
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* arg: {-231..-1, 1..232-1}, {0}
*/
110 if (arg == 0) {
111 res = new AdditionalTabTargets().excludeAll();
112
113 for (PluginInfo possPlugin
114 : PluginManager.getPluginManager().getPluginInfos()) {
115 res.add(possPlugin.getName());
116 res.add("!" + possPlugin.getName());
117 }
118 } else {
119 res = TabCompleter.getIntelligentResults(arg, previousArgs, 1);
120 }
121
122 return res;
123 }
124
125 }
SofCheck Inspector Build Version : 2.17854
| Ifplugin.java |
2009-Jun-25 01:54:24 |
| Ifplugin.class |
2009-Sep-02 17:04:16 |