8149160: use StringJoiner in sjavac option handling
authoralundblad
Wed, 10 Feb 2016 14:22:50 +0100
changeset 35808 fe1936c9412e
parent 35807 2eb1d877da0f
child 35809 f02d72332452
8149160: use StringJoiner in sjavac option handling Summary: Concatenation of strings now uses StringJoiner. Reviewed-by: alundblad, jjg Contributed-by: cushon@google.com
langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/options/Options.java
langtools/test/tools/sjavac/JavacOptionPrep.java
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/options/Options.java	Tue Feb 09 14:07:23 2016 -0800
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/options/Options.java	Wed Feb 10 14:22:50 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -34,6 +34,7 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.HashSet;
+import java.util.StringJoiner;
 
 import com.sun.tools.sjavac.Transformer;
 import com.sun.tools.sjavac.Util;
@@ -225,10 +226,7 @@
             }
 
             String getResult() {
-                String result = "";
-                for (String s : args)
-                    result += s + " ";
-                return result.trim();
+                return String.join(" ", args);
             }
 
             public void addAll(Collection<String> toAdd) {
@@ -337,10 +335,11 @@
     // Helper method to join a list of source locations separated by
     // File.pathSeparator
     private static String concatenateSourceLocations(List<SourceLocation> locs) {
-        String s = "";
-        for (SourceLocation loc : locs)
-            s += (s.isEmpty() ? "" : java.io.File.pathSeparator) + loc.getPath();
-        return s;
+        StringJoiner joiner = new StringJoiner(java.io.File.pathSeparator);
+        for (SourceLocation loc : locs) {
+            joiner.add(loc.getPath().toString());
+        }
+        return joiner.toString();
     }
 
     // OptionHelper that records the traversed options in this Options instance.
--- a/langtools/test/tools/sjavac/JavacOptionPrep.java	Tue Feb 09 14:07:23 2016 -0800
+++ b/langtools/test/tools/sjavac/JavacOptionPrep.java	Wed Feb 10 14:22:50 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -65,7 +65,7 @@
         //  - Sources provided without preceding option (SRC2)
         //  - An unrecognized option which is to be passed on to javac
         String sjavacArgs = "-cp " + TestPath.CP1 + SEP + TestPath.CP2 +
-                            " -d dest " +
+                            " -d dest" +
                             " -h header" +
                             " -sourcepath " + TestPath.SOURCEPATH1 +
                             " -src " + TestPath.SRC1 +