Browse Source

Fix getConnection issues in debug plugin.

pull/162/head
Chris Smith 9 years ago
parent
commit
4f2d8f57ec

+ 2
- 1
debug/src/com/dmdirc/addons/debug/DebugCommand.java View File

@@ -26,6 +26,7 @@ import com.dmdirc.FrameContainer;
26 26
 import com.dmdirc.commandparser.CommandArguments;
27 27
 import com.dmdirc.commandparser.commands.context.CommandContext;
28 28
 
29
+import javax.annotation.Nonnull;
29 30
 import javax.inject.Provider;
30 31
 
31 32
 /**
@@ -82,7 +83,7 @@ public abstract class DebugCommand {
82 83
      * @param args    Arguments passed to this command
83 84
      * @param context The context the command was executed in
84 85
      */
85
-    public abstract void execute(final FrameContainer origin,
86
+    public abstract void execute(@Nonnull final FrameContainer origin,
86 87
             final CommandArguments args, final CommandContext context);
87 88
 
88 89
     /**

+ 11
- 8
debug/src/com/dmdirc/addons/debug/commands/ServerInfo.java View File

@@ -29,6 +29,8 @@ import com.dmdirc.commandparser.CommandArguments;
29 29
 import com.dmdirc.commandparser.commands.context.CommandContext;
30 30
 import com.dmdirc.interfaces.Connection;
31 31
 
32
+import java.util.Optional;
33
+
32 34
 import javax.inject.Inject;
33 35
 import javax.inject.Provider;
34 36
 
@@ -60,11 +62,9 @@ public class ServerInfo extends DebugCommand {
60 62
     @Override
61 63
     public void execute(final FrameContainer origin,
62 64
             final CommandArguments args, final CommandContext context) {
63
-        if (origin.getConnection() == null) {
64
-            sendLine(origin, args.isSilent(), FORMAT_ERROR,
65
-                    "This window isn't connected to a server");
66
-        } else {
67
-            final Connection connection = origin.getConnection();
65
+        final Optional<Connection> optionalConnection = origin.getOptionalConnection();
66
+        if (optionalConnection.isPresent()) {
67
+            final Connection connection = optionalConnection.get();
68 68
             sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Server name: "
69 69
                     + connection.getAddress());
70 70
             sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Actual name: "
@@ -75,10 +75,13 @@ public class ServerInfo extends DebugCommand {
75 75
                     + connection.getParser().getServerSoftware() + " - "
76 76
                     + connection.getParser().getServerSoftwareType());
77 77
             sendLine(origin, args.isSilent(), FORMAT_OUTPUT, "Modes: "
78
-                    + connection.getParser().getBooleanChannelModes() + " "
79
-                    + connection.getParser().getListChannelModes() + " "
80
-                    + connection.getParser().getParameterChannelModes() + " "
78
+                    + connection.getParser().getBooleanChannelModes() + ' '
79
+                    + connection.getParser().getListChannelModes() + ' '
80
+                    + connection.getParser().getParameterChannelModes() + ' '
81 81
                     + connection.getParser().getDoubleParameterChannelModes());
82
+        } else {
83
+            sendLine(origin, args.isSilent(), FORMAT_ERROR,
84
+                    "This window isn't connected to a server");
82 85
         }
83 86
     }
84 87
 

+ 7
- 5
debug/src/com/dmdirc/addons/debug/commands/ServerState.java View File

@@ -29,6 +29,8 @@ import com.dmdirc.commandparser.CommandArguments;
29 29
 import com.dmdirc.commandparser.commands.context.CommandContext;
30 30
 import com.dmdirc.interfaces.Connection;
31 31
 
32
+import java.util.Optional;
33
+
32 34
 import javax.inject.Inject;
33 35
 import javax.inject.Provider;
34 36
 
@@ -60,13 +62,13 @@ public class ServerState extends DebugCommand {
60 62
     @Override
61 63
     public void execute(final FrameContainer origin,
62 64
             final CommandArguments args, final CommandContext context) {
63
-        if (origin.getConnection() == null) {
65
+        final Optional<Connection> optionalConnection = origin.getOptionalConnection();
66
+        if (optionalConnection.isPresent()) {
67
+            sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
68
+                    optionalConnection.get().getStatus().getTransitionHistory());
69
+        } else {
64 70
             sendLine(origin, args.isSilent(), FORMAT_ERROR,
65 71
                     "This window isn't connected to a server");
66
-        } else {
67
-            final Connection connection = origin.getConnection();
68
-            sendLine(origin, args.isSilent(), FORMAT_OUTPUT,
69
-                    connection.getStatus().getTransitionHistory());
70 72
         }
71 73
     }
72 74
 

+ 9
- 4
debug/src/com/dmdirc/addons/debug/commands/ShowRaw.java View File

@@ -27,7 +27,11 @@ import com.dmdirc.addons.debug.Debug;
27 27
 import com.dmdirc.addons.debug.DebugCommand;
28 28
 import com.dmdirc.commandparser.CommandArguments;
29 29
 import com.dmdirc.commandparser.commands.context.CommandContext;
30
+import com.dmdirc.interfaces.Connection;
30 31
 
32
+import java.util.Optional;
33
+
34
+import javax.annotation.Nonnull;
31 35
 import javax.inject.Inject;
32 36
 import javax.inject.Provider;
33 37
 
@@ -57,13 +61,14 @@ public class ShowRaw extends DebugCommand {
57 61
     }
58 62
 
59 63
     @Override
60
-    public void execute(final FrameContainer origin,
64
+    public void execute(@Nonnull final FrameContainer origin,
61 65
             final CommandArguments args, final CommandContext context) {
62
-        if (origin == null || origin.getConnection() == null) {
66
+        final Optional<Connection> connection = origin.getOptionalConnection();
67
+        if (connection.isPresent()) {
68
+            connection.get().addRaw();
69
+        } else {
63 70
             sendLine(origin, args.isSilent(), FORMAT_ERROR,
64 71
                     "Cannot show raw window here.");
65
-        } else {
66
-            origin.getConnection().addRaw();
67 72
         }
68 73
     }
69 74
 

Loading…
Cancel
Save