瀏覽代碼

Minor changes to facilitate testing.

Remove some 'final' modifiers for CommandParser methods.

Modify the Logger class so it only calls into the ErrorManager if
it actually needs it. The ErrorManager constructor requires an
IdentityManager which causes any test that executes a Logger.assert
line to require most of the client is constructed, regardless of
what the test is actually doing.

Change-Id: I63879db5c13517cfa60941fce73a2ba01e63f1cd
Reviewed-on: http://gerrit.dmdirc.com/2681
Reviewed-by: Greg Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
tags/0.8rc1
Chris Smith 10 年之前
父節點
當前提交
771606c649
共有 2 個檔案被更改,包括 18 行新增14 行删除
  1. 5
    7
      src/com/dmdirc/commandparser/parsers/CommandParser.java
  2. 13
    7
      src/com/dmdirc/logger/Logger.java

+ 5
- 7
src/com/dmdirc/commandparser/parsers/CommandParser.java 查看文件

@@ -75,9 +75,8 @@ public abstract class CommandParser implements Serializable {
75 75
     /** Creates a new instance of CommandParser. */
76 76
     protected CommandParser(final ConfigManager configManager,
77 77
             final CommandManager commandManager) {
78
-        commands = new HashMap<String, CommandInfoPair>();
79
-        history = new RollingList<PreviousCommand>(configManager
80
-                .getOptionInt("general", "commandhistory"));
78
+        commands = new HashMap<>();
79
+        history = new RollingList<>(configManager.getOptionInt("general", "commandhistory"));
81 80
         this.commandManager = commandManager;
82 81
         loadCommands();
83 82
     }
@@ -121,7 +120,7 @@ public abstract class CommandParser implements Serializable {
121 120
      * @return A map of commands known to this parser
122 121
      */
123 122
     public Map<String, CommandInfoPair> getCommands() {
124
-        return new HashMap<String, CommandInfoPair>(commands);
123
+        return new HashMap<>(commands);
125 124
     }
126 125
 
127 126
     /**
@@ -257,8 +256,7 @@ public abstract class CommandParser implements Serializable {
257 256
      * @param line The line to be parsed
258 257
      * @since 0.6.4
259 258
      */
260
-    public final void parseCommand(final FrameContainer origin,
261
-            final String line) {
259
+    public void parseCommand(final FrameContainer origin, final String line) {
262 260
         parseCommand(origin, line, true);
263 261
     }
264 262
 
@@ -268,7 +266,7 @@ public abstract class CommandParser implements Serializable {
268 266
      * @param origin The window in which the command was typed
269 267
      * @param line The line to be parsed
270 268
      */
271
-    public final void parseCommandCtrl(final FrameContainer origin, final String line) {
269
+    public void parseCommandCtrl(final FrameContainer origin, final String line) {
272 270
         handleNonCommand(origin, line);
273 271
     }
274 272
 

+ 13
- 7
src/com/dmdirc/logger/Logger.java 查看文件

@@ -27,9 +27,6 @@ package com.dmdirc.logger;
27 27
  */
28 28
 public final class Logger {
29 29
 
30
-    /** The MANAGER to use to report errors. */
31
-    protected static final ErrorManager MANAGER = ErrorManager.getErrorManager();
32
-
33 30
     /** Prevent instantiation of a new instance of Logger. */
34 31
     private Logger() {
35 32
         //Ignore
@@ -42,7 +39,7 @@ public final class Logger {
42 39
      * @param message Brief error description
43 40
      */
44 41
     public static void userError(final ErrorLevel level, final String message) {
45
-        MANAGER.addError(level, message);
42
+        getErrorManager().addError(level, message);
46 43
     }
47 44
 
48 45
     /**
@@ -54,7 +51,7 @@ public final class Logger {
54 51
      */
55 52
     public static void userError(final ErrorLevel level, final String message,
56 53
             final String details) {
57
-        MANAGER.addError(level, message, new String[]{details}, false);
54
+        getErrorManager().addError(level, message, new String[]{details}, false);
58 55
     }
59 56
 
60 57
     /**
@@ -66,7 +63,7 @@ public final class Logger {
66 63
      */
67 64
     public static void userError(final ErrorLevel level,
68 65
             final String message, final Throwable exception) {
69
-        MANAGER.addError(level, message, exception, false);
66
+        getErrorManager().addError(level, message, exception, false);
70 67
     }
71 68
 
72 69
     /**
@@ -79,7 +76,7 @@ public final class Logger {
79 76
      */
80 77
     public static void appError(final ErrorLevel level,
81 78
             final String message, final Throwable exception) {
82
-        MANAGER.addError(level, message, exception, true);
79
+        getErrorManager().addError(level, message, exception, true);
83 80
     }
84 81
 
85 82
     /**
@@ -94,4 +91,13 @@ public final class Logger {
94 91
         }
95 92
     }
96 93
 
94
+    /**
95
+     * Gets the manager that should be used to report errors.
96
+     *
97
+     * @return The error manager to be used.
98
+     */
99
+    private static ErrorManager getErrorManager() {
100
+        return ErrorManager.getErrorManager();
101
+    }
102
+
97 103
 }

Loading…
取消
儲存