ソースを参照

Assorted tidying.

Change-Id: I918bb6183a19d0e400e37176e3f213b80a36514a
Reviewed-on: http://gerrit.dmdirc.com/4069
Reviewed-by: Greg Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
pull/1/head
Chris Smith 9年前
コミット
b1c59cce2c

+ 18
- 23
src/com/dmdirc/plugins/PluginInfo.java ファイルの表示

98
     /** Map of exports. */
98
     /** Map of exports. */
99
     private final Map<String, ExportInfo> exports = new HashMap<>();
99
     private final Map<String, ExportInfo> exports = new HashMap<>();
100
     /** List of configuration providers. */
100
     /** List of configuration providers. */
101
-    private final List<ConfigProvider> configProviders = new ArrayList<>();
101
+    private final Collection<ConfigProvider> configProviders = new ArrayList<>();
102
     /** Event bus to post plugin loaded events to. */
102
     /** Event bus to post plugin loaded events to. */
103
     private final DMDircMBassador eventBus;
103
     private final DMDircMBassador eventBus;
104
     /** File system for the plugin's jar. */
104
     /** File system for the plugin's jar. */
196
      * @return The injector used for this plugin
196
      * @return The injector used for this plugin
197
      */
197
      */
198
     public SimpleInjector getInjector() {
198
     public SimpleInjector getInjector() {
199
-        final SimpleInjector injector;
200
         final SimpleInjector[] parents = new SimpleInjector[metaData.getParent() == null ? 0 : 1];
199
         final SimpleInjector[] parents = new SimpleInjector[metaData.getParent() == null ? 0 : 1];
201
         final Plugin[] plugins = new Plugin[parents.length];
200
         final Plugin[] plugins = new Plugin[parents.length];
202
 
201
 
207
             plugins[0] = parent.getPlugin();
206
             plugins[0] = parent.getPlugin();
208
         }
207
         }
209
 
208
 
210
-        injector = new SimpleInjector(parents);
209
+        final SimpleInjector injector = new SimpleInjector(parents);
211
 
210
 
212
         for (Plugin parentPlugin : plugins) {
211
         for (Plugin parentPlugin : plugins) {
213
             injector.addParameter(parentPlugin);
212
             injector.addParameter(parentPlugin);
253
      * @throws IOException if there is an error with the ResourceManager.
252
      * @throws IOException if there is an error with the ResourceManager.
254
      */
253
      */
255
     public Map<String, InputStream> getLicenceStreams() throws IOException {
254
     public Map<String, InputStream> getLicenceStreams() throws IOException {
256
-        final TreeMap<String, InputStream> licences = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
255
+        final Map<String, InputStream> licences = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
257
         if (!Files.exists(pluginFilesystem.getPath("/META-INF/licenses/"))) {
256
         if (!Files.exists(pluginFilesystem.getPath("/META-INF/licenses/"))) {
258
             return licences;
257
             return licences;
259
         }
258
         }
333
                     } catch (final InvalidIdentityFileException ex) {
332
                     } catch (final InvalidIdentityFileException ex) {
334
                         eventBus.publish(new UserErrorEvent(ErrorLevel.MEDIUM, ex,
333
                         eventBus.publish(new UserErrorEvent(ErrorLevel.MEDIUM, ex,
335
                                 "Error with identity file '" + name + "' in plugin '"
334
                                 "Error with identity file '" + name + "' in plugin '"
336
-                                + metaData.getName() + "'", ""));
335
+                                + metaData.getName() + '\'', ""));
337
                     }
336
                     }
338
                 }
337
                 }
339
             }
338
             }
340
         } catch (final IOException ioe) {
339
         } catch (final IOException ioe) {
341
             eventBus.publish(new UserErrorEvent(ErrorLevel.MEDIUM, ioe,
340
             eventBus.publish(new UserErrorEvent(ErrorLevel.MEDIUM, ioe,
342
-                    "Error finding identities in plugin '" + metaData.getName() + "'", ""));
341
+                    "Error finding identities in plugin '" + metaData.getName() + '\'', ""));
343
         }
342
         }
344
     }
343
     }
345
 
344
 
376
                 final String name = bits[0];
375
                 final String name = bits[0];
377
                 final String type = bits.length > 1 ? bits[1] : "misc";
376
                 final String type = bits.length > 1 ? bits[1] : "misc";
378
 
377
 
379
-                if (!name.equalsIgnoreCase("any") && !type.equalsIgnoreCase("export")) {
378
+                if (!"any".equalsIgnoreCase(name) && !"export".equalsIgnoreCase(type)) {
380
                     final Service service = metaData.getManager().getService(type, name, true);
379
                     final Service service = metaData.getManager().getService(type, name, true);
381
                     synchronized (provides) {
380
                     synchronized (provides) {
382
                         service.addProvider(this);
381
                         service.addProvider(this);
446
     @Override
445
     @Override
447
     public String getProviderName() {
446
     public String getProviderName() {
448
         return "Plugin: " + metaData.getFriendlyName() + " ("
447
         return "Plugin: " + metaData.getFriendlyName() + " ("
449
-                + metaData.getName() + " / " + getFilename() + ")";
448
+                + metaData.getName() + " / " + getFilename() + ')';
450
     }
449
     }
451
 
450
 
452
     @Override
451
     @Override
556
             }
555
             }
557
         }
556
         }
558
 
557
 
559
-        if (metaData.getParent() != null) {
560
-            return loadRequiredPlugin(metaData.getParent());
561
-        }
562
-
563
-        return true;
558
+        return metaData.getParent() == null || loadRequiredPlugin(metaData.getParent());
564
     }
559
     }
565
 
560
 
566
     /**
561
     /**
594
      */
589
      */
595
     public void loadPlugin() {
590
     public void loadPlugin() {
596
         if (isLoaded() || isLoading) {
591
         if (isLoaded() || isLoading) {
597
-            lastError = "Not Loading: (" + isLoaded() + "||" + isLoading + ")";
592
+            lastError = "Not Loading: (" + isLoaded() + "||" + isLoading + ')';
598
             return;
593
             return;
599
         }
594
         }
600
 
595
 
613
                 plugin.load(this, getObjectGraph());
608
                 plugin.load(this, getObjectGraph());
614
                 plugin.onLoad();
609
                 plugin.onLoad();
615
             } catch (LinkageError | Exception e) {
610
             } catch (LinkageError | Exception e) {
616
-                lastError = "Error in onLoad for " + metaData.getName() + ":"
611
+                lastError = "Error in onLoad for " + metaData.getName() + ':'
617
                         + e.getMessage();
612
                         + e.getMessage();
618
                 eventBus.publishAsync(new AppErrorEvent(ErrorLevel.MEDIUM, e, lastError, ""));
613
                 eventBus.publishAsync(new AppErrorEvent(ErrorLevel.MEDIUM, e, lastError, ""));
619
                 unloadPlugin();
614
                 unloadPlugin();
741
                     if (prerequisites.isFailure()) {
736
                     if (prerequisites.isFailure()) {
742
                         if (!tempLoaded) {
737
                         if (!tempLoaded) {
743
                             lastError = "Prerequisites for plugin not met. ('"
738
                             lastError = "Prerequisites for plugin not met. ('"
744
-                                    + filename + ":" + metaData.getMainClass()
739
+                                    + filename + ':' + metaData.getMainClass()
745
                                     + "' -> '" + prerequisites.getFailureReason() + "') ";
740
                                     + "' -> '" + prerequisites.getFailureReason() + "') ";
746
                             eventBus.publish(new UserErrorEvent(ErrorLevel.LOW, null, lastError, ""));
741
                             eventBus.publish(new UserErrorEvent(ErrorLevel.LOW, null, lastError, ""));
747
                         }
742
                         }
758
                                 plugin.onLoad();
753
                                 plugin.onLoad();
759
                             } catch (LinkageError | Exception e) {
754
                             } catch (LinkageError | Exception e) {
760
                                 lastError = "Error in onLoad for "
755
                                 lastError = "Error in onLoad for "
761
-                                        + metaData.getName() + ":" + e.getMessage();
756
+                                        + metaData.getName() + ':' + e.getMessage();
762
                                 eventBus.publishAsync(new AppErrorEvent(ErrorLevel.MEDIUM,
757
                                 eventBus.publishAsync(new AppErrorEvent(ErrorLevel.MEDIUM,
763
                                         e, lastError, ""));
758
                                         e, lastError, ""));
764
                                 unloadPlugin();
759
                                 unloadPlugin();
768
                 }
763
                 }
769
             }
764
             }
770
         } catch (ClassNotFoundException cnfe) {
765
         } catch (ClassNotFoundException cnfe) {
771
-            lastError = "Class not found ('" + filename + ":" + classname + ":"
766
+            lastError = "Class not found ('" + filename + ':' + classname + ':'
772
                     + classname.equals(metaData.getMainClass()) + "') - "
767
                     + classname.equals(metaData.getMainClass()) + "') - "
773
                     + cnfe.getMessage();
768
                     + cnfe.getMessage();
774
             eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, cnfe, lastError, ""));
769
             eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, cnfe, lastError, ""));
775
         } catch (NoClassDefFoundError ncdf) {
770
         } catch (NoClassDefFoundError ncdf) {
776
-            lastError = "Unable to instantiate plugin ('" + filename + ":"
777
-                    + classname + ":"
771
+            lastError = "Unable to instantiate plugin ('" + filename + ':'
772
+                    + classname + ':'
778
                     + classname.equals(metaData.getMainClass())
773
                     + classname.equals(metaData.getMainClass())
779
                     + "') - Unable to find class: " + ncdf.getMessage();
774
                     + "') - Unable to find class: " + ncdf.getMessage();
780
             eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, ncdf, lastError, ""));
775
             eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, ncdf, lastError, ""));
781
         } catch (VerifyError ve) {
776
         } catch (VerifyError ve) {
782
-            lastError = "Unable to instantiate plugin ('" + filename + ":"
783
-                    + classname + ":"
777
+            lastError = "Unable to instantiate plugin ('" + filename + ':'
778
+                    + classname + ':'
784
                     + classname.equals(metaData.getMainClass())
779
                     + classname.equals(metaData.getMainClass())
785
                     + "') - Incompatible: " + ve.getMessage();
780
                     + "') - Incompatible: " + ve.getMessage();
786
             eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, ve, lastError, ""));
781
             eventBus.publishAsync(new UserErrorEvent(ErrorLevel.LOW, ve, lastError, ""));
846
                     plugin.onUnload();
841
                     plugin.onUnload();
847
                 } catch (Exception | LinkageError e) {
842
                 } catch (Exception | LinkageError e) {
848
                     lastError = "Error in onUnload for " + metaData.getName()
843
                     lastError = "Error in onUnload for " + metaData.getName()
849
-                            + ":" + e + " - " + e.getMessage();
844
+                            + ':' + e + " - " + e.getMessage();
850
                     eventBus.publishAsync(new AppErrorEvent(ErrorLevel.MEDIUM, e, lastError, ""));
845
                     eventBus.publishAsync(new AppErrorEvent(ErrorLevel.MEDIUM, e, lastError, ""));
851
                 }
846
                 }
852
 
847
 

+ 4
- 10
src/com/dmdirc/ui/core/aliases/CoreAliasDialogModel.java ファイルの表示

251
 
251
 
252
     @Override
252
     @Override
253
     public boolean isSelectedAliasValid() {
253
     public boolean isSelectedAliasValid() {
254
-        if (selectedAlias.isPresent()) {
255
-            return isCommandValid() && isMinimumArgumentsValid() && isSubstitutionValid();
256
-        } else {
257
-            return true;
258
-        }
254
+        return !selectedAlias.isPresent() ||
255
+                isCommandValid() && isMinimumArgumentsValid() && isSubstitutionValid();
259
     }
256
     }
260
 
257
 
261
     @Override
258
     @Override
262
     public boolean isChangeAliasAllowed() {
259
     public boolean isChangeAliasAllowed() {
263
-        if (selectedAlias.isPresent()) {
264
-            return isCommandValid() && isMinimumArgumentsValid() && isSubstitutionValid();
265
-        } else {
266
-            return true;
267
-        }
260
+        return !selectedAlias.isPresent() ||
261
+                isCommandValid() && isMinimumArgumentsValid() && isSubstitutionValid();
268
     }
262
     }
269
 
263
 
270
     @Override
264
     @Override

+ 14
- 28
src/com/dmdirc/ui/core/profiles/CoreProfilesDialogModel.java ファイルの表示

260
 
260
 
261
     @Override
261
     @Override
262
     public boolean isSelectedProfileNameValid() {
262
     public boolean isSelectedProfileNameValid() {
263
-        if (getSelectedProfileName().isPresent()) {
264
-            return !getSelectedProfileNameValidator()
265
-                    .validate(getSelectedProfileName().get()).isFailure();
266
-        }
267
-        return true;
263
+        return !getSelectedProfileName().isPresent() ||
264
+                !getSelectedProfileNameValidator().validate(getSelectedProfileName().get())
265
+                        .isFailure();
268
     }
266
     }
269
 
267
 
270
     @Override
268
     @Override
291
 
289
 
292
     @Override
290
     @Override
293
     public boolean isSelectedProfileRealnameValid() {
291
     public boolean isSelectedProfileRealnameValid() {
294
-        if (getSelectedProfileRealname().isPresent()) {
295
-            return !getSelectedProfileRealnameValidator()
296
-                    .validate(getSelectedProfileRealname().get()).isFailure();
297
-        }
298
-        return true;
292
+        return !getSelectedProfileRealname().isPresent() ||
293
+                !getSelectedProfileRealnameValidator().validate(getSelectedProfileRealname().get())
294
+                        .isFailure();
299
     }
295
     }
300
 
296
 
301
     @Override
297
     @Override
322
 
318
 
323
     @Override
319
     @Override
324
     public boolean isSelectedProfileIdentValid() {
320
     public boolean isSelectedProfileIdentValid() {
325
-        if (getSelectedProfileIdent().isPresent()) {
326
-            return !getSelectedProfileIdentValidator()
327
-                    .validate(getSelectedProfileIdent().get()).isFailure();
328
-        }
329
-        return true;
321
+        return !getSelectedProfileIdent().isPresent() ||
322
+                !getSelectedProfileIdentValidator().validate(getSelectedProfileIdent().get())
323
+                        .isFailure();
330
     }
324
     }
331
 
325
 
332
     @Override
326
     @Override
358
 
352
 
359
     @Override
353
     @Override
360
     public boolean isSelectedProfileNicknamesValid() {
354
     public boolean isSelectedProfileNicknamesValid() {
361
-        if (getSelectedProfileNicknames().isPresent()) {
362
-            return !getSelectedProfileNicknamesValidator()
363
-                    .validate(getSelectedProfileNicknames().get()).isFailure();
364
-        }
365
-        return true;
355
+        return !getSelectedProfileNicknames().isPresent() || !getSelectedProfileNicknamesValidator()
356
+                .validate(getSelectedProfileNicknames().get()).isFailure();
366
     }
357
     }
367
 
358
 
368
     @Override
359
     @Override
447
 
438
 
448
     @Override
439
     @Override
449
     public boolean canSwitchProfiles() {
440
     public boolean canSwitchProfiles() {
450
-        if (selectedProfile.isPresent()) {
451
-            return isSelectedProfileIdentValid()
452
-                    && isSelectedProfileNameValid()
453
-                    && isSelectedProfileNicknamesValid()
454
-                    && isSelectedProfileRealnameValid();
455
-        } else {
456
-            return true;
457
-        }
441
+        return !selectedProfile.isPresent() ||
442
+                isSelectedProfileIdentValid() && isSelectedProfileNameValid() &&
443
+                        isSelectedProfileNicknamesValid() && isSelectedProfileRealnameValid();
458
     }
444
     }
459
 
445
 
460
     @Override
446
     @Override

読み込み中…
キャンセル
保存