Parcourir la source

Remove some deprecated uses of getConnection().

pull/173/head
Chris Smith il y a 9 ans
Parent
révision
39bfa3f01f

+ 3
- 3
src/com/dmdirc/ChannelEventHandler.java Voir le fichier

@@ -114,7 +114,7 @@ public class ChannelEventHandler extends EventHandler implements
114 114
     @Nonnull
115 115
     @Override
116 116
     protected Connection getConnection() {
117
-        return owner.getConnection();
117
+        return owner.getOptionalConnection().get();
118 118
     }
119 119
 
120 120
     /**
@@ -125,7 +125,7 @@ public class ChannelEventHandler extends EventHandler implements
125 125
      * @return True if the client is ourself, false otherwise.
126 126
      */
127 127
     protected boolean isMyself(final ChannelClientInfo client) {
128
-        return client.getClient().equals(owner.getConnection().getParser().getLocalClient());
128
+        return client.getClient().equals(getConnection().getParser().getLocalClient());
129 129
     }
130 130
 
131 131
     @Override
@@ -321,7 +321,7 @@ public class ChannelEventHandler extends EventHandler implements
321 321
         final ChannelCtcpEvent event = new ChannelCtcpEvent(owner, client, type, message);
322 322
         final String format = EventUtils.postDisplayable(eventBus, event, "channelCTCP");
323 323
         if (!event.isHandled()) {
324
-            owner.getConnection().sendCTCPReply(client.getClient().getNickname(), type, message);
324
+            getConnection().sendCTCPReply(client.getClient().getNickname(), type, message);
325 325
         }
326 326
         owner.doNotification(date, format, client, type, message);
327 327
     }

+ 4
- 4
src/com/dmdirc/CustomWindow.java Voir le fichier

@@ -28,7 +28,7 @@ import com.dmdirc.ui.core.components.WindowComponent;
28 28
 import com.dmdirc.ui.messages.ColourManagerFactory;
29 29
 import com.dmdirc.util.URLBuilder;
30 30
 
31
-import java.util.Arrays;
31
+import java.util.Collections;
32 32
 import java.util.Optional;
33 33
 
34 34
 /**
@@ -52,7 +52,7 @@ public class CustomWindow extends FrameContainer {
52 52
             final ColourManagerFactory colourManagerFactory) {
53 53
         super(parent, "custom", name, title, parent.getConfigManager(), colourManagerFactory,
54 54
                 urlBuilder, parent.getEventBus(),
55
-                Arrays.asList(WindowComponent.TEXTAREA.getIdentifier()));
55
+                Collections.singletonList(WindowComponent.TEXTAREA.getIdentifier()));
56 56
     }
57 57
 
58 58
     /**
@@ -72,12 +72,12 @@ public class CustomWindow extends FrameContainer {
72 72
             final DMDircMBassador eventBus,
73 73
             final ColourManagerFactory colourManagerFactory) {
74 74
         super(null, "custom", name, title, configProvider, colourManagerFactory, urlBuilder,
75
-                eventBus, Arrays.asList(WindowComponent.TEXTAREA.getIdentifier()));
75
+                eventBus, Collections.singletonList(WindowComponent.TEXTAREA.getIdentifier()));
76 76
     }
77 77
 
78 78
     @Override
79 79
     public Connection getConnection() {
80
-        return getParent().map(FrameContainer::getConnection).orElse(null);
80
+        return getOptionalConnection().orElse(null);
81 81
     }
82 82
 
83 83
     @Override

+ 1
- 1
src/com/dmdirc/actions/CoreActionComponent.java Voir le fichier

@@ -736,7 +736,7 @@ public enum CoreActionComponent implements ActionComponent {
736 736
     WINDOW_SERVER {
737 737
         @Override
738 738
         public Object get(final Object arg) {
739
-            return ((Window) arg).getContainer().getConnection();
739
+            return ((Window) arg).getContainer().getOptionalConnection().orElse(null);
740 740
         }
741 741
 
742 742
         @Override

+ 1
- 1
src/com/dmdirc/commandparser/commands/channel/Mode.java Voir le fichier

@@ -74,7 +74,7 @@ public class Mode extends Command implements IntelligentCommand,
74 74
         if (args.getArguments().length == 0) {
75 75
             sendLine(origin, args.isSilent(), "channelModeDiscovered", cChannel.getModes(), cChannel);
76 76
         } else {
77
-            channel.getConnection().getParser().sendRawMessage("MODE "
77
+            channel.getOptionalConnection().get().getParser().sendRawMessage("MODE "
78 78
                     + cChannel + " " + args.getArgumentsAsString());
79 79
         }
80 80
     }

+ 1
- 1
src/com/dmdirc/commandparser/commands/channel/Names.java Voir le fichier

@@ -67,7 +67,7 @@ public class Names extends Command implements IntelligentCommand,
67 67
     public void execute(@Nonnull final FrameContainer origin,
68 68
             final CommandArguments args, final CommandContext context) {
69 69
         final Channel channel = ((ChannelCommandContext) context).getChannel();
70
-        channel.getConnection().getParser().sendRawMessage("NAMES "
70
+        channel.getOptionalConnection().get().getParser().sendRawMessage("NAMES "
71 71
                 + channel.getChannelInfo().getName());
72 72
     }
73 73
 

+ 2
- 2
src/com/dmdirc/commandparser/commands/channel/ShowTopic.java Voir le fichier

@@ -71,8 +71,8 @@ public class ShowTopic extends Command implements ExternalCommand {
71 71
             if (cChannel.getTopic().isEmpty()) {
72 72
                 sendLine(origin, args.isSilent(), "channelNoTopic", cChannel);
73 73
             } else {
74
-                final String[] parts = channel.getConnection().parseHostmask(cChannel.
75
-                        getTopicSetter());
74
+                final String[] parts = channel.getOptionalConnection().get().parseHostmask(
75
+                        cChannel.getTopicSetter());
76 76
 
77 77
                 sendLine(origin, args.isSilent(), "channelTopicDiscovered",
78 78
                         "", parts[0], parts[1], parts[2], cChannel.getTopic(),

+ 9
- 4
src/com/dmdirc/commandparser/commands/chat/Me.java Voir le fichier

@@ -33,8 +33,12 @@ import com.dmdirc.commandparser.commands.ValidatingCommand;
33 33
 import com.dmdirc.commandparser.commands.context.ChatCommandContext;
34 34
 import com.dmdirc.commandparser.commands.context.CommandContext;
35 35
 import com.dmdirc.interfaces.CommandController;
36
+import com.dmdirc.interfaces.Connection;
37
+import com.dmdirc.parser.interfaces.Parser;
36 38
 import com.dmdirc.util.validators.ValidationResponse;
37 39
 
40
+import java.util.Optional;
41
+
38 42
 import javax.annotation.Nonnull;
39 43
 import javax.inject.Inject;
40 44
 
@@ -74,15 +78,16 @@ public class Me extends Command implements ValidatingCommand {
74 78
     public ValidationResponse validateArguments(
75 79
             final FrameContainer origin,
76 80
             final CommandArguments arguments) {
77
-        if (origin.getConnection() == null
78
-                || origin.getConnection().getParser() == null) {
81
+        final Optional<Connection> connection = origin.getOptionalConnection();
82
+        final Optional<Parser> parser = connection.flatMap(c -> Optional.ofNullable(c.getParser()));
83
+
84
+        if (!parser.isPresent()) {
79 85
             return new ValidationResponse();
80 86
         }
81 87
 
82 88
         final int length = 2 + arguments.getArgumentsAsString().length();
83 89
 
84
-        if (origin.getConnection().getParser().getMaxLength("PRIVMSG",
85
-                origin.getName()) <= length) {
90
+        if (parser.get().getMaxLength("PRIVMSG", origin.getName()) <= length) {
86 91
             return new ValidationResponse("Too long");
87 92
         } else {
88 93
             return new ValidationResponse();

+ 6
- 3
src/com/dmdirc/commandparser/parsers/CommandParser.java Voir le fichier

@@ -44,6 +44,7 @@ import com.dmdirc.util.collections.RollingList;
44 44
 import java.io.Serializable;
45 45
 import java.util.HashMap;
46 46
 import java.util.Map;
47
+import java.util.Optional;
47 48
 
48 49
 import javax.annotation.Nonnull;
49 50
 
@@ -178,14 +179,16 @@ public abstract class CommandParser implements Serializable {
178 179
         final boolean silent = args.isSilent();
179 180
         final String command = args.getCommandName();
180 181
         final String[] cargs = args.getArguments();
182
+        final Optional<Connection> connection = origin.getOptionalConnection();
181 183
 
182
-        if (cargs.length == 0 || !parseChannel
183
-                || origin.getConnection() == null
184
+        if (cargs.length == 0
185
+                || !parseChannel
186
+                || !connection.isPresent()
184 187
                 || !commandManager.isChannelCommand(command)) {
185 188
             return false;
186 189
         }
187 190
 
188
-        final Connection server = origin.getConnection();
191
+        final Connection server = connection.get();
189 192
         final String[] parts = cargs[0].split(",");
190 193
         boolean someValid = false;
191 194
         for (String part : parts) {

Chargement…
Annuler
Enregistrer