src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java
changeset 47363 77c792d06646
parent 47216 71c04702a3d5
child 47702 cf8310446245
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java	Thu Oct 19 09:53:53 2017 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java	Thu Oct 19 10:59:02 2017 +0200
@@ -88,7 +88,7 @@
 import com.sun.tools.javac.util.ListBuffer;
 import com.sun.tools.javac.util.Log;
 import com.sun.tools.javac.jvm.ModuleNameReader;
-import com.sun.tools.javac.util.Assert;
+import com.sun.tools.javac.util.Iterators;
 import com.sun.tools.javac.util.Pair;
 import com.sun.tools.javac.util.StringUtils;
 
@@ -964,6 +964,7 @@
         private final String name;
         private final String moduleName;
         private final boolean output;
+        boolean explicit;
         Collection<Path> searchPath;
 
         ModuleLocationHandler(LocationHandler parent, String name, String moduleName,
@@ -1083,6 +1084,14 @@
         Set<Location> locations() {
             return Collections.unmodifiableSet(nameMap.values().stream().collect(Collectors.toSet()));
         }
+
+        Set<Location> explicitLocations() {
+            return Collections.unmodifiableSet(nameMap.entrySet()
+                                                      .stream()
+                                                      .filter(e -> e.getValue().explicit)
+                                                      .map(e -> e.getValue())
+                                                      .collect(Collectors.toSet()));
+        }
     }
 
     /**
@@ -1119,10 +1128,20 @@
 
         @Override
         Iterable<Set<Location>> listLocationsForModules() {
+            Set<Location> explicitLocations = moduleTable != null ?
+                    moduleTable.explicitLocations() : Collections.emptySet();
+            Iterable<Set<Location>> explicitLocationsList = !explicitLocations.isEmpty()
+                    ? Collections.singletonList(explicitLocations)
+                    : Collections.emptyList();
+
             if (searchPath == null)
-                return Collections.emptyList();
+                return explicitLocationsList;
 
-            return ModulePathIterator::new;
+            Iterable<Set<Location>> searchPathLocations =
+                    () -> new ModulePathIterator();
+            return () -> Iterators.createCompoundIterator(Arrays.asList(explicitLocationsList,
+                                                                        searchPathLocations),
+                                                          Iterable::iterator);
         }
 
         @Override
@@ -1159,6 +1178,7 @@
                 l.searchPath = checkedPaths;
                 moduleTable.updatePaths(l);
             }
+            l.explicit = true;
         }
 
         private List<Path> checkPaths(Iterable<? extends Path> paths) throws IOException {