langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java
changeset 37944 1153fab98d25
parent 37394 c36230ee15d9
child 38533 2bd347dde526
equal deleted inserted replaced
37943:2efb75c09230 37944:1153fab98d25
   107     private final Set<JavaFileObject.Kind> sourceOrClass =
   107     private final Set<JavaFileObject.Kind> sourceOrClass =
   108         EnumSet.of(JavaFileObject.Kind.SOURCE, JavaFileObject.Kind.CLASS);
   108         EnumSet.of(JavaFileObject.Kind.SOURCE, JavaFileObject.Kind.CLASS);
   109 
   109 
   110     protected boolean symbolFileEnabled;
   110     protected boolean symbolFileEnabled;
   111 
   111 
       
   112     private PathFactory pathFactory = Paths::get;
       
   113 
   112     protected enum SortFiles implements Comparator<Path> {
   114     protected enum SortFiles implements Comparator<Path> {
   113         FORWARD {
   115         FORWARD {
   114             @Override
   116             @Override
   115             public int compare(Path f1, Path f2) {
   117             public int compare(Path f1, Path f2) {
   116                 return f1.getFileName().compareTo(f2.getFileName());
   118                 return f1.getFileName().compareTo(f2.getFileName());
   164         if (sf != null) {
   166         if (sf != null) {
   165             sortFiles = (sf.equals("reverse") ? SortFiles.REVERSE : SortFiles.FORWARD);
   167             sortFiles = (sf.equals("reverse") ? SortFiles.REVERSE : SortFiles.FORWARD);
   166         }
   168         }
   167     }
   169     }
   168 
   170 
       
   171     @Override @DefinedBy(DefinedBy.Api.COMPILER)
       
   172     public void setPathFactory(PathFactory f) {
       
   173         pathFactory = Objects.requireNonNull(f);
       
   174         locations.setPathFactory(f);
       
   175     }
       
   176 
       
   177     private Path getPath(String first, String... more) {
       
   178         return pathFactory.getPath(first, more);
       
   179     }
       
   180 
   169     /**
   181     /**
   170      * Set whether or not to use ct.sym as an alternate to rt.jar.
   182      * Set whether or not to use ct.sym as an alternate to rt.jar.
   171      */
   183      */
   172     public void setSymbolFileEnabled(boolean b) {
   184     public void setSymbolFileEnabled(boolean b) {
   173         symbolFileEnabled = b;
   185         symbolFileEnabled = b;
   197 
   209 
   198     @Override @DefinedBy(Api.COMPILER)
   210     @Override @DefinedBy(Api.COMPILER)
   199     public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names) {
   211     public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names) {
   200         ListBuffer<Path> paths = new ListBuffer<>();
   212         ListBuffer<Path> paths = new ListBuffer<>();
   201         for (String name : names)
   213         for (String name : names)
   202             paths.append(Paths.get(nullCheck(name)));
   214             paths.append(getPath(nullCheck(name)));
   203         return getJavaFileObjectsFromPaths(paths.toList());
   215         return getJavaFileObjectsFromPaths(paths.toList());
   204     }
   216     }
   205 
   217 
   206     @Override @DefinedBy(Api.COMPILER)
   218     @Override @DefinedBy(Api.COMPILER)
   207     public Iterable<? extends JavaFileObject> getJavaFileObjects(String... names) {
   219     public Iterable<? extends JavaFileObject> getJavaFileObjects(String... names) {
   835             } else {
   847             } else {
   836                 String baseName = fileName.basename();
   848                 String baseName = fileName.basename();
   837                 if (sibling != null && sibling instanceof PathFileObject) {
   849                 if (sibling != null && sibling instanceof PathFileObject) {
   838                     return ((PathFileObject) sibling).getSibling(baseName);
   850                     return ((PathFileObject) sibling).getSibling(baseName);
   839                 } else {
   851                 } else {
   840                     Path p = Paths.get(baseName);
   852                     Path p = getPath(baseName);
   841                     Path real = fsInfo.getCanonicalFile(p);
   853                     Path real = fsInfo.getCanonicalFile(p);
   842                     return PathFileObject.forSimplePath(this, real, p);
   854                     return PathFileObject.forSimplePath(this, real, p);
   843                 }
   855                 }
   844             }
   856             }
   845         } else if (location == SOURCE_OUTPUT) {
   857         } else if (location == SOURCE_OUTPUT) {
   853             }
   865             }
   854         }
   866         }
   855 
   867 
   856         try {
   868         try {
   857             if (dir == null) {
   869             if (dir == null) {
   858                 dir = Paths.get(System.getProperty("user.dir"));
   870                 dir = getPath(System.getProperty("user.dir"));
   859             }
   871             }
   860             Path path = fileName.resolveAgainst(fsInfo.getCanonicalFile(dir));
   872             Path path = fileName.resolveAgainst(fsInfo.getCanonicalFile(dir));
   861             return PathFileObject.forDirectoryPath(this, path, dir, fileName);
   873             return PathFileObject.forDirectoryPath(this, path, dir, fileName);
   862         } catch (InvalidPathException e) {
   874         } catch (InvalidPathException e) {
   863             throw new IOException("bad filename " + fileName, e);
   875             throw new IOException("bad filename " + fileName, e);
   916         locations.setLocation(location, asPaths(searchpath));
   928         locations.setLocation(location, asPaths(searchpath));
   917     }
   929     }
   918 
   930 
   919     @Override @DefinedBy(Api.COMPILER)
   931     @Override @DefinedBy(Api.COMPILER)
   920     public void setLocationFromPaths(Location location,
   932     public void setLocationFromPaths(Location location,
   921                             Iterable<? extends Path> searchpath)
   933                             Collection<? extends Path> searchpath)
   922         throws IOException
   934         throws IOException
   923     {
   935     {
   924         nullCheck(location);
   936         nullCheck(location);
   925         locations.setLocation(location, nullCheck(searchpath));
   937         locations.setLocation(location, nullCheck(searchpath));
   926     }
   938     }