< prev index next >

src/java.base/share/classes/jdk/internal/module/ModuleBootstrap.java

Print this page
rev 51919 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: dfuchs, alanb


 533         Map<String, List<String>> map = decode("jdk.module.patch.",
 534                                                File.pathSeparator,
 535                                                false);
 536         return new ModulePatcher(map);
 537     }
 538 
 539     /**
 540      * Returns the set of module names specified by --add-module options.
 541      */
 542     private static Set<String> addModules() {
 543         String prefix = "jdk.module.addmods.";
 544         int index = 0;
 545         // the system property is removed after decoding
 546         String value = getAndRemoveProperty(prefix + index);
 547         if (value == null) {
 548             return Collections.emptySet();
 549         } else {
 550             Set<String> modules = new HashSet<>();
 551             while (value != null) {
 552                 for (String s : value.split(",")) {
 553                     if (s.length() > 0) modules.add(s);

 554                 }
 555                 index++;
 556                 value = getAndRemoveProperty(prefix + index);
 557             }
 558             return modules;
 559         }
 560     }
 561 
 562     /**
 563      * Returns the set of module names specified by --limit-modules.
 564      */
 565     private static Set<String> limitModules() {
 566         String value = getAndRemoveProperty("jdk.module.limitmods");
 567         if (value == null) {
 568             return Collections.emptySet();
 569         } else {
 570             Set<String> names = new HashSet<>();
 571             for (String name : value.split(",")) {
 572                 if (name.length() > 0) names.add(name);
 573             }


 825 
 826             int pos = value.indexOf('=');
 827             if (pos == -1)
 828                 fail(unableToParse(option(prefix), "<module>=<value>", value));
 829             if (pos == 0)
 830                 fail(unableToParse(option(prefix), "<module>=<value>", value));
 831 
 832             // key is <module> or <module>/<package>
 833             String key = value.substring(0, pos);
 834 
 835             String rhs = value.substring(pos+1);
 836             if (rhs.isEmpty())
 837                 fail(unableToParse(option(prefix), "<module>=<value>", value));
 838 
 839             // value is <module>(,<module>)* or <file>(<pathsep><file>)*
 840             if (!allowDuplicates && map.containsKey(key))
 841                 fail(key + " specified more than once to " + option(prefix));
 842             List<String> values = map.computeIfAbsent(key, k -> new ArrayList<>());
 843             int ntargets = 0;
 844             for (String s : rhs.split(regex)) {
 845                 if (s.length() > 0) {
 846                     values.add(s);
 847                     ntargets++;
 848                 }
 849             }
 850             if (ntargets == 0)
 851                 fail("Target must be specified: " + option(prefix) + " " + value);
 852 
 853             index++;
 854             value = getAndRemoveProperty(prefix + index);
 855         }
 856 
 857         return map;
 858     }
 859 
 860     /**
 861      * Decodes the values of --add-reads, -add-exports or --add-opens
 862      * which use the "," to separate the RHS of the option value.
 863      */
 864     private static Map<String, List<String>> decode(String prefix) {
 865         return decode(prefix, ",", true);




 533         Map<String, List<String>> map = decode("jdk.module.patch.",
 534                                                File.pathSeparator,
 535                                                false);
 536         return new ModulePatcher(map);
 537     }
 538 
 539     /**
 540      * Returns the set of module names specified by --add-module options.
 541      */
 542     private static Set<String> addModules() {
 543         String prefix = "jdk.module.addmods.";
 544         int index = 0;
 545         // the system property is removed after decoding
 546         String value = getAndRemoveProperty(prefix + index);
 547         if (value == null) {
 548             return Collections.emptySet();
 549         } else {
 550             Set<String> modules = new HashSet<>();
 551             while (value != null) {
 552                 for (String s : value.split(",")) {
 553                     if (!s.isEmpty())
 554                         modules.add(s);
 555                 }
 556                 index++;
 557                 value = getAndRemoveProperty(prefix + index);
 558             }
 559             return modules;
 560         }
 561     }
 562 
 563     /**
 564      * Returns the set of module names specified by --limit-modules.
 565      */
 566     private static Set<String> limitModules() {
 567         String value = getAndRemoveProperty("jdk.module.limitmods");
 568         if (value == null) {
 569             return Collections.emptySet();
 570         } else {
 571             Set<String> names = new HashSet<>();
 572             for (String name : value.split(",")) {
 573                 if (name.length() > 0) names.add(name);
 574             }


 826 
 827             int pos = value.indexOf('=');
 828             if (pos == -1)
 829                 fail(unableToParse(option(prefix), "<module>=<value>", value));
 830             if (pos == 0)
 831                 fail(unableToParse(option(prefix), "<module>=<value>", value));
 832 
 833             // key is <module> or <module>/<package>
 834             String key = value.substring(0, pos);
 835 
 836             String rhs = value.substring(pos+1);
 837             if (rhs.isEmpty())
 838                 fail(unableToParse(option(prefix), "<module>=<value>", value));
 839 
 840             // value is <module>(,<module>)* or <file>(<pathsep><file>)*
 841             if (!allowDuplicates && map.containsKey(key))
 842                 fail(key + " specified more than once to " + option(prefix));
 843             List<String> values = map.computeIfAbsent(key, k -> new ArrayList<>());
 844             int ntargets = 0;
 845             for (String s : rhs.split(regex)) {
 846                 if (!s.isEmpty()) {
 847                     values.add(s);
 848                     ntargets++;
 849                 }
 850             }
 851             if (ntargets == 0)
 852                 fail("Target must be specified: " + option(prefix) + " " + value);
 853 
 854             index++;
 855             value = getAndRemoveProperty(prefix + index);
 856         }
 857 
 858         return map;
 859     }
 860 
 861     /**
 862      * Decodes the values of --add-reads, -add-exports or --add-opens
 863      * which use the "," to separate the RHS of the option value.
 864      */
 865     private static Map<String, List<String>> decode(String prefix) {
 866         return decode(prefix, ",", true);


< prev index next >