Explorar el Código

Tidy up some TabCompleter usages.

Change-Id: I1d61d1895025f3b7febd7cae1e8411d0b198f141
Depends-On: I2eb5ac89568b524ef13cf1d455eb5b51904c806c
Reviewed-on: http://gerrit.dmdirc.com/2867
Reviewed-by: Greg Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
tags/0.8rc1
Chris Smith hace 10 años
padre
commit
8727a298ac

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

@@ -30,7 +30,7 @@ import com.dmdirc.commandparser.CommandType;
30 30
 import com.dmdirc.commandparser.commands.Command;
31 31
 import com.dmdirc.commandparser.commands.IntelligentCommand;
32 32
 import com.dmdirc.commandparser.commands.IntelligentCommand.IntelligentCommandContext;
33
-import com.dmdirc.config.IdentityManager;
33
+import com.dmdirc.interfaces.CommandController;
34 34
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
35 35
 import com.dmdirc.util.collections.MapList;
36 36
 
@@ -53,40 +53,42 @@ public class TabCompleter {
53 53
     @Nullable
54 54
     private final TabCompleter parent;
55 55
 
56
-    /**
57
-     * The config manager to use for reading settings.
58
-     */
56
+    /** The config manager to use for reading settings. */
59 57
     private final AggregateConfigProvider configManager;
60 58
 
61
-    /**
62
-     * The entries in this completer.
63
-     */
64
-    private final MapList<TabCompletionType, String> entries = new MapList<>();
59
+    /** The controller to use to retrieve command information. */
60
+    private final CommandController commandController;
65 61
 
66
-    /** Creates a new instance of TabCompleter. */
67
-    @Deprecated
68
-    public TabCompleter() {
69
-        this(IdentityManager.getIdentityManager().getGlobalConfiguration());
70
-    }
62
+    /** The entries in this completer. */
63
+    private final MapList<TabCompletionType, String> entries = new MapList<>();
71 64
 
72 65
     /**
73 66
      * Creates a new instance of {@link TabCompleter}.
74 67
      *
68
+     * @param commandController The controller to use for command information.
75 69
      * @param configManager The manager to read config settings from.
76 70
      */
77
-    public TabCompleter(final AggregateConfigProvider configManager) {
71
+    public TabCompleter(
72
+            final CommandController commandController,
73
+            final AggregateConfigProvider configManager) {
78 74
         this.parent = null;
75
+        this.commandController = commandController;
79 76
         this.configManager = configManager;
80 77
     }
81 78
 
82 79
     /**
83 80
      * Creates a new instance of {@link TabCompleter}.
84 81
      *
82
+     * @param commandController The controller to use for command information.
85 83
      * @param configManager The manager to read config settings from.
86 84
      * @param parent The parent tab completer to inherit completions from.
87 85
      */
88
-    public TabCompleter(final AggregateConfigProvider configManager, final TabCompleter parent) {
86
+    public TabCompleter(
87
+            final CommandController commandController,
88
+            final AggregateConfigProvider configManager,
89
+            final TabCompleter parent) {
89 90
         this.parent = parent;
91
+        this.commandController = commandController;
90 92
         this.configManager = configManager;
91 93
     }
92 94
 
@@ -156,11 +158,11 @@ public class TabCompleter {
156 158
         entries.add(type, entry);
157 159
 
158 160
         if (type == TabCompletionType.COMMAND && entry.length() > 1
159
-                && entry.charAt(0) == CommandManager.getCommandManager().getCommandChar()
160
-                && entry.charAt(1) != CommandManager.getCommandManager().getSilenceChar()) {
161
+                && entry.charAt(0) == commandController.getCommandChar()
162
+                && entry.charAt(1) != commandController.getSilenceChar()) {
161 163
             // If we're adding a command name that doesn't include the silence
162 164
             // character, also add a version with the silence char
163
-            addEntry(type, entry.substring(0, 1) + CommandManager.getCommandManager().getSilenceChar()
165
+            addEntry(type, entry.substring(0, 1) + commandController.getSilenceChar()
164 166
                     + entry.substring(1));
165 167
         }
166 168
     }

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

@@ -73,7 +73,7 @@ public class TabCompleterFactory {
73 73
     public TabCompleter getTabCompleter(
74 74
             final AggregateConfigProvider configProvider,
75 75
             final CommandType ... commandTypes) {
76
-        final TabCompleter tabCompleter = new TabCompleter(configProvider);
76
+        final TabCompleter tabCompleter = new TabCompleter(commandController.get(), configProvider);
77 77
         addCommands(tabCompleter, commandTypes);
78 78
         tabCompleter.addEntries(TabCompletionType.COMMAND, aliasWrapper.get().getAliases());
79 79
         return tabCompleter;
@@ -92,7 +92,8 @@ public class TabCompleterFactory {
92 92
             final TabCompleter parent,
93 93
             final AggregateConfigProvider configProvider,
94 94
             final CommandType ... commandTypes) {
95
-        final TabCompleter tabCompleter = new TabCompleter(configProvider, parent);
95
+        final TabCompleter tabCompleter = new TabCompleter(commandController.get(),
96
+                configProvider, parent);
96 97
         addCommands(tabCompleter, commandTypes);
97 98
         return tabCompleter;
98 99
     }

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

@@ -26,12 +26,15 @@ import com.dmdirc.Server;
26 26
 import com.dmdirc.WritableFrameContainer;
27 27
 import com.dmdirc.commandparser.CommandManager;
28 28
 import com.dmdirc.commandparser.parsers.GlobalCommandParser;
29
+import com.dmdirc.interfaces.CommandController;
29 30
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
30 31
 import com.dmdirc.messages.MessageSinkManager;
31 32
 import com.dmdirc.ui.input.TabCompleter;
32 33
 
33 34
 import java.util.Collections;
34 35
 
36
+import static org.mockito.Mockito.*;
37
+
35 38
 public class TestWritableFrameContainer extends WritableFrameContainer {
36 39
 
37 40
     private final int lineLength;
@@ -73,6 +76,6 @@ public class TestWritableFrameContainer extends WritableFrameContainer {
73 76
 
74 77
     @Override
75 78
     public TabCompleter getTabCompleter() {
76
-        return new TabCompleter(getConfigManager());
79
+        return new TabCompleter(mock(CommandController.class), getConfigManager());
77 80
     }
78 81
 }

Loading…
Cancelar
Guardar