From 325070d711019204bdbc831e0b8152db7c08f5d9 Mon Sep 17 00:00:00 2001 From: Rodrigo Bonifacio Date: Thu, 15 Jun 2017 11:48:49 -0300 Subject: [PATCH] Refactoring towards Java language evolution. - use the diamond operator in a few places - use of multi-catch in a few places --- app/src/processing/app/Library.java | 17 ++++++----------- app/src/processing/app/ui/MarkerColumn.java | 2 +- .../FileTextFieldTransferHandler.java | 10 ++-------- core/src/processing/data/FloatDict.java | 2 +- java/libraries/io/src/processing/io/LED.java | 2 +- .../processing/mode/java/VariableInspector.java | 6 +++--- .../mode/java/debug/ArrayFieldNode.java | 4 +--- .../mode/java/debug/LocalVariableNode.java | 4 +--- .../mode/java/debug/VariableNode.java | 2 +- 9 files changed, 17 insertions(+), 32 deletions(-) diff --git a/app/src/processing/app/Library.java b/app/src/processing/app/Library.java index 12c15b146..761cd74fb 100644 --- a/app/src/processing/app/Library.java +++ b/app/src/processing/app/Library.java @@ -28,7 +28,7 @@ public class Library extends LocalContribution { StringList packageList; /** Per-platform exports for this library. */ - HashMap exportList; + HashMap exportList; /** Applet exports (cross-platform by definition). */ String[] appletExportList; @@ -282,7 +282,7 @@ public class Library extends LocalContribution { } - static protected HashMap packageWarningMap = new HashMap(); + static protected HashMap packageWarningMap = new HashMap<>(); /** * Add the packages provided by this library to the master list that maps @@ -461,12 +461,7 @@ public class Library extends LocalContribution { static public boolean hasMultipleArch(int platform, List libraries) { - for (Library library : libraries) { - if (library.hasMultipleArch(platform)) { - return true; - } - } - return false; + return libraries.stream().anyMatch(library -> library.hasMultipleArch(platform)); } @@ -484,7 +479,7 @@ public class Library extends LocalContribution { static public List discover(File folder) { - List libraries = new ArrayList(); + List libraries = new ArrayList<>(); String[] folderNames = folder.list(junkFolderFilter); // if a bad folder or something like that, this might come back null @@ -529,8 +524,8 @@ public class Library extends LocalContribution { static public List list(File folder) { - List libraries = new ArrayList(); - List librariesFolders = new ArrayList(); + List libraries = new ArrayList<>(); + List librariesFolders = new ArrayList<>(); librariesFolders.addAll(discover(folder)); for (File baseFolder : librariesFolders) { diff --git a/app/src/processing/app/ui/MarkerColumn.java b/app/src/processing/app/ui/MarkerColumn.java index 03dc948e3..12a1ee655 100644 --- a/app/src/processing/app/ui/MarkerColumn.java +++ b/app/src/processing/app/ui/MarkerColumn.java @@ -60,7 +60,7 @@ public class MarkerColumn extends JPanel { private Color warningColor; // Stores error markers displayed PER TAB along the error bar. - private List errorPoints = new ArrayList(); + private List errorPoints = new ArrayList<>(); public MarkerColumn(Editor editor, int height) { diff --git a/build/shared/tools/MovieMaker/src/ch/randelshofer/gui/datatransfer/FileTextFieldTransferHandler.java b/build/shared/tools/MovieMaker/src/ch/randelshofer/gui/datatransfer/FileTextFieldTransferHandler.java index adb7f01cb..dc56b1157 100644 --- a/build/shared/tools/MovieMaker/src/ch/randelshofer/gui/datatransfer/FileTextFieldTransferHandler.java +++ b/build/shared/tools/MovieMaker/src/ch/randelshofer/gui/datatransfer/FileTextFieldTransferHandler.java @@ -109,9 +109,7 @@ public class FileTextFieldTransferHandler extends TransferHandler { c.setText(file.getPath()); } imported = true; - } catch (UnsupportedFlavorException ex) { - // ex.printStackTrace(); - } catch (IOException ex) { + } catch (UnsupportedFlavorException | IOException ex) { // ex.printStackTrace(); } } @@ -129,11 +127,7 @@ public class FileTextFieldTransferHandler extends TransferHandler { boolean useRead = false; handleReaderImport(r, c, useRead); imported = true; - } catch (UnsupportedFlavorException ex) { - // ex.printStackTrace(); - } catch (BadLocationException ex) { - // ex.printStackTrace(); - } catch (IOException ex) { + } catch (UnsupportedFlavorException | BadLocationException | IOException ex) { // ex.printStackTrace(); } } diff --git a/core/src/processing/data/FloatDict.java b/core/src/processing/data/FloatDict.java index dbb89ecee..f6db5d301 100644 --- a/core/src/processing/data/FloatDict.java +++ b/core/src/processing/data/FloatDict.java @@ -23,7 +23,7 @@ public class FloatDict { protected float[] values; /** Internal implementation for faster lookups */ - private HashMap indices = new HashMap(); + private HashMap indices = new HashMap<>(); public FloatDict() { diff --git a/java/libraries/io/src/processing/io/LED.java b/java/libraries/io/src/processing/io/LED.java index 61635f4d0..32925e6ea 100644 --- a/java/libraries/io/src/processing/io/LED.java +++ b/java/libraries/io/src/processing/io/LED.java @@ -161,7 +161,7 @@ public class LED { return new String[]{ "led0", "led1" }; } - ArrayList devs = new ArrayList(); + ArrayList devs = new ArrayList<>(); File dir = new File("/sys/class/leds"); File[] files = dir.listFiles(); if (files != null) { diff --git a/java/src/processing/mode/java/VariableInspector.java b/java/src/processing/mode/java/VariableInspector.java index f0cdde4f6..8f6b2fc2d 100644 --- a/java/src/processing/mode/java/VariableInspector.java +++ b/java/src/processing/mode/java/VariableInspector.java @@ -81,7 +81,7 @@ public class VariableInspector extends JDialog { // protected Debugger dbg; /// list of expanded tree paths. (using list to maintain the order of expansion) - protected List expandedNodes = new ArrayList(); + protected List expandedNodes = new ArrayList<>(); public VariableInspector(final JavaEditor editor) { @@ -696,7 +696,7 @@ public class VariableInspector extends JDialog { // first remove all children of collapsed path // this makes sure children do not appear before parents in the list. // (children can't be expanded before their parents) - List removalList = new ArrayList(); + List removalList = new ArrayList<>(); for (TreePath path : expandedNodes) { if (path.getParentPath().equals(tee.getPath())) { removalList.add(path); @@ -911,7 +911,7 @@ public class VariableInspector extends JDialog { * @return the filtered list. */ protected List filterNodes(List nodes, VariableNodeFilter filter) { - List filtered = new ArrayList(); + List filtered = new ArrayList<>(); for (VariableNode node : nodes) { if (filter.accept(node)) { filtered.add(node); diff --git a/java/src/processing/mode/java/debug/ArrayFieldNode.java b/java/src/processing/mode/java/debug/ArrayFieldNode.java index ac7d6a08d..8d527573e 100644 --- a/java/src/processing/mode/java/debug/ArrayFieldNode.java +++ b/java/src/processing/mode/java/debug/ArrayFieldNode.java @@ -52,9 +52,7 @@ public class ArrayFieldNode extends VariableNode { public void setValue(Value value) { try { array.setValue(index, value); - } catch (InvalidTypeException ex) { - Messages.loge(null, ex); - } catch (ClassNotLoadedException ex) { + } catch (InvalidTypeException | ClassNotLoadedException ex) { Messages.loge(null, ex); } this.value = value; diff --git a/java/src/processing/mode/java/debug/LocalVariableNode.java b/java/src/processing/mode/java/debug/LocalVariableNode.java index 39c42a2a7..34bb91afc 100644 --- a/java/src/processing/mode/java/debug/LocalVariableNode.java +++ b/java/src/processing/mode/java/debug/LocalVariableNode.java @@ -51,9 +51,7 @@ public class LocalVariableNode extends VariableNode { public void setValue(Value value) { try { frame.setValue(var, value); - } catch (InvalidTypeException ex) { - Messages.loge(null, ex); - } catch (ClassNotLoadedException ex) { + } catch (InvalidTypeException | ClassNotLoadedException ex) { Messages.loge(null, ex); } this.value = value; diff --git a/java/src/processing/mode/java/debug/VariableNode.java b/java/src/processing/mode/java/debug/VariableNode.java index d9ad2e5f4..b8b268447 100644 --- a/java/src/processing/mode/java/debug/VariableNode.java +++ b/java/src/processing/mode/java/debug/VariableNode.java @@ -55,7 +55,7 @@ public class VariableNode implements MutableTreeNode { protected String type; protected String name; protected Value value; - protected List children = new ArrayList(); + protected List children = new ArrayList<>(); protected MutableTreeNode parent;