src/jdk.compiler/share/classes/com/sun/tools/sjavac/Util.java

Print this page
rev 2819 : imported patch my-classpath-deps-00


  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.sjavac;
  27 
  28 import java.io.File;
  29 import java.io.PrintWriter;
  30 import java.io.StringWriter;
  31 import java.nio.file.Path;
  32 import java.util.Arrays;

  33 import java.util.HashSet;

  34 import java.util.Set;
  35 import java.util.StringTokenizer;


  36 
  37 /**
  38  * Utilities.
  39  *
  40  *  <p><b>This is NOT part of any supported API.
  41  *  If you write code that depends on this, you do so at your own risk.
  42  *  This code and its internal interfaces are subject to change or
  43  *  deletion without notice.</b>
  44  */
  45 public class Util {
  46 
  47     public static String toFileSystemPath(String pkgId) {
  48         if (pkgId == null || pkgId.length()==0) return null;
  49         String pn;
  50         if (pkgId.charAt(0) == ':') {
  51             // When the module is the default empty module.
  52             // Do not prepend the module directory, because there is none.
  53             // Thus :java.foo.bar translates to java/foo/bar (or \)
  54             pn = pkgId.substring(1).replace('.',File.separatorChar);
  55         } else {


 166     /**
 167      * Locate the setting for the server properties.
 168      */
 169     public static String findServerSettings(String[] args) {
 170         for (String s : args) {
 171             if (s.startsWith("--server:")) {
 172                 return s;
 173             }
 174         }
 175         return null;
 176     }
 177 
 178     public static <E> Set<E> union(Set<? extends E> s1,
 179                                    Set<? extends E> s2) {
 180         Set<E> union = new HashSet<>();
 181         union.addAll(s1);
 182         union.addAll(s2);
 183         return union;
 184     }
 185 







 186     public static String getStackTrace(Throwable t) {
 187         StringWriter sw = new StringWriter();
 188         t.printStackTrace(new PrintWriter(sw));
 189         return sw.toString();
 190     }
 191 
 192     // TODO: Remove when refactoring from java.io.File to java.nio.file.Path.
 193     public static File pathToFile(Path path) {
 194         return path == null ? null : path.toFile();












 195     }
 196 }


  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.sjavac;
  27 
  28 import java.io.File;
  29 import java.io.PrintWriter;
  30 import java.io.StringWriter;
  31 import java.nio.file.Path;
  32 import java.util.Arrays;
  33 import java.util.Collection;
  34 import java.util.HashSet;
  35 import java.util.Map;
  36 import java.util.Set;
  37 import java.util.StringTokenizer;
  38 import java.util.function.Function;
  39 import java.util.stream.Collectors;
  40 
  41 /**
  42  * Utilities.
  43  *
  44  *  <p><b>This is NOT part of any supported API.
  45  *  If you write code that depends on this, you do so at your own risk.
  46  *  This code and its internal interfaces are subject to change or
  47  *  deletion without notice.</b>
  48  */
  49 public class Util {
  50 
  51     public static String toFileSystemPath(String pkgId) {
  52         if (pkgId == null || pkgId.length()==0) return null;
  53         String pn;
  54         if (pkgId.charAt(0) == ':') {
  55             // When the module is the default empty module.
  56             // Do not prepend the module directory, because there is none.
  57             // Thus :java.foo.bar translates to java/foo/bar (or \)
  58             pn = pkgId.substring(1).replace('.',File.separatorChar);
  59         } else {


 170     /**
 171      * Locate the setting for the server properties.
 172      */
 173     public static String findServerSettings(String[] args) {
 174         for (String s : args) {
 175             if (s.startsWith("--server:")) {
 176                 return s;
 177             }
 178         }
 179         return null;
 180     }
 181 
 182     public static <E> Set<E> union(Set<? extends E> s1,
 183                                    Set<? extends E> s2) {
 184         Set<E> union = new HashSet<>();
 185         union.addAll(s1);
 186         union.addAll(s2);
 187         return union;
 188     }
 189 
 190     public static <E> Set<E> subtract(Set<? extends E> orig,
 191                                       Set<? extends E> toSubtract) {
 192         Set<E> difference = new HashSet<>(orig);
 193         difference.removeAll(toSubtract);
 194         return difference;
 195     }
 196 
 197     public static String getStackTrace(Throwable t) {
 198         StringWriter sw = new StringWriter();
 199         t.printStackTrace(new PrintWriter(sw));
 200         return sw.toString();
 201     }
 202 
 203     // TODO: Remove when refactoring from java.io.File to java.nio.file.Path.
 204     public static File pathToFile(Path path) {
 205         return path == null ? null : path.toFile();
 206     }
 207 
 208     public static <E> Set<E> intersection(Collection<? extends E> c1,
 209                                           Collection<? extends E> c2) {
 210         Set<E> intersection = new HashSet<E>(c1);
 211         intersection.retainAll(c2);
 212         return intersection;
 213     }
 214 
 215     public static <I, T> Map<I, T> indexBy(Collection<? extends T> c,
 216                                            Function<? super T, ? extends I> indexFunction) {
 217         return c.stream().collect(Collectors.toMap(indexFunction, o -> o));
 218     }
 219 }