56 |
56 |
57 import com.sun.tools.javac.file.RelativePath.RelativeFile; |
57 import com.sun.tools.javac.file.RelativePath.RelativeFile; |
58 import com.sun.tools.javac.file.RelativePath.RelativeDirectory; |
58 import com.sun.tools.javac.file.RelativePath.RelativeDirectory; |
59 import com.sun.tools.javac.util.BaseFileManager; |
59 import com.sun.tools.javac.util.BaseFileManager; |
60 import com.sun.tools.javac.util.Context; |
60 import com.sun.tools.javac.util.Context; |
|
61 import com.sun.tools.javac.util.DefinedBy; |
|
62 import com.sun.tools.javac.util.DefinedBy.Api; |
61 import com.sun.tools.javac.util.List; |
63 import com.sun.tools.javac.util.List; |
62 import com.sun.tools.javac.util.ListBuffer; |
64 import com.sun.tools.javac.util.ListBuffer; |
63 |
65 |
64 import static javax.tools.StandardLocation.*; |
66 import static javax.tools.StandardLocation.*; |
65 |
67 |
172 throws IOException |
174 throws IOException |
173 { |
175 { |
174 return getJavaFileForOutput(CLASS_OUTPUT, classname, kind, sibling); |
176 return getJavaFileForOutput(CLASS_OUTPUT, classname, kind, sibling); |
175 } |
177 } |
176 |
178 |
|
179 @DefinedBy(Api.COMPILER) |
177 public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names) { |
180 public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names) { |
178 ListBuffer<File> files = new ListBuffer<>(); |
181 ListBuffer<File> files = new ListBuffer<>(); |
179 for (String name : names) |
182 for (String name : names) |
180 files.append(new File(nullCheck(name))); |
183 files.append(new File(nullCheck(name))); |
181 return getJavaFileObjectsFromFiles(files.toList()); |
184 return getJavaFileObjectsFromFiles(files.toList()); |
182 } |
185 } |
183 |
186 |
|
187 @DefinedBy(Api.COMPILER) |
184 public Iterable<? extends JavaFileObject> getJavaFileObjects(String... names) { |
188 public Iterable<? extends JavaFileObject> getJavaFileObjects(String... names) { |
185 return getJavaFileObjectsFromStrings(Arrays.asList(nullCheck(names))); |
189 return getJavaFileObjectsFromStrings(Arrays.asList(nullCheck(names))); |
186 } |
190 } |
187 |
191 |
188 private static boolean isValidName(String name) { |
192 private static boolean isValidName(String name) { |
554 return archive; |
558 return archive; |
555 } |
559 } |
556 |
560 |
557 /** Flush any output resources. |
561 /** Flush any output resources. |
558 */ |
562 */ |
|
563 @DefinedBy(Api.COMPILER) |
559 public void flush() { |
564 public void flush() { |
560 contentCache.clear(); |
565 contentCache.clear(); |
561 } |
566 } |
562 |
567 |
563 /** |
568 /** |
564 * Close the JavaFileManager, releasing resources. |
569 * Close the JavaFileManager, releasing resources. |
565 */ |
570 */ |
|
571 @DefinedBy(Api.COMPILER) |
566 public void close() { |
572 public void close() { |
567 for (Iterator<Archive> i = archives.values().iterator(); i.hasNext(); ) { |
573 for (Iterator<Archive> i = archives.values().iterator(); i.hasNext(); ) { |
568 Archive a = i.next(); |
574 Archive a = i.next(); |
569 i.remove(); |
575 i.remove(); |
570 try { |
576 try { |
610 for (File directory : path) |
618 for (File directory : path) |
611 listContainer(directory, subdirectory, kinds, recurse, results); |
619 listContainer(directory, subdirectory, kinds, recurse, results); |
612 return results.toList(); |
620 return results.toList(); |
613 } |
621 } |
614 |
622 |
|
623 @DefinedBy(Api.COMPILER) |
615 public String inferBinaryName(Location location, JavaFileObject file) { |
624 public String inferBinaryName(Location location, JavaFileObject file) { |
616 file.getClass(); // null check |
625 file.getClass(); // null check |
617 location.getClass(); // null check |
626 location.getClass(); // null check |
618 // Need to match the path semantics of list(location, ...) |
627 // Need to match the path semantics of list(location, ...) |
619 Iterable<? extends File> path = getLocation(location); |
628 Iterable<? extends File> path = getLocation(location); |
625 return ((BaseFileObject) file).inferBinaryName(path); |
634 return ((BaseFileObject) file).inferBinaryName(path); |
626 } else |
635 } else |
627 throw new IllegalArgumentException(file.getClass().getName()); |
636 throw new IllegalArgumentException(file.getClass().getName()); |
628 } |
637 } |
629 |
638 |
|
639 @DefinedBy(Api.COMPILER) |
630 public boolean isSameFile(FileObject a, FileObject b) { |
640 public boolean isSameFile(FileObject a, FileObject b) { |
631 nullCheck(a); |
641 nullCheck(a); |
632 nullCheck(b); |
642 nullCheck(b); |
633 if (!(a instanceof BaseFileObject)) |
643 if (!(a instanceof BaseFileObject)) |
634 throw new IllegalArgumentException("Not supported: " + a); |
644 throw new IllegalArgumentException("Not supported: " + a); |
635 if (!(b instanceof BaseFileObject)) |
645 if (!(b instanceof BaseFileObject)) |
636 throw new IllegalArgumentException("Not supported: " + b); |
646 throw new IllegalArgumentException("Not supported: " + b); |
637 return a.equals(b); |
647 return a.equals(b); |
638 } |
648 } |
639 |
649 |
|
650 @DefinedBy(Api.COMPILER) |
640 public boolean hasLocation(Location location) { |
651 public boolean hasLocation(Location location) { |
641 return getLocation(location) != null; |
652 return getLocation(location) != null; |
642 } |
653 } |
643 |
654 |
|
655 @DefinedBy(Api.COMPILER) |
644 public JavaFileObject getJavaFileForInput(Location location, |
656 public JavaFileObject getJavaFileForInput(Location location, |
645 String className, |
657 String className, |
646 JavaFileObject.Kind kind) |
658 JavaFileObject.Kind kind) |
647 throws IOException |
659 throws IOException |
648 { |
660 { |
653 if (!sourceOrClass.contains(kind)) |
665 if (!sourceOrClass.contains(kind)) |
654 throw new IllegalArgumentException("Invalid kind: " + kind); |
666 throw new IllegalArgumentException("Invalid kind: " + kind); |
655 return getFileForInput(location, RelativeFile.forClass(className, kind)); |
667 return getFileForInput(location, RelativeFile.forClass(className, kind)); |
656 } |
668 } |
657 |
669 |
|
670 @DefinedBy(Api.COMPILER) |
658 public FileObject getFileForInput(Location location, |
671 public FileObject getFileForInput(Location location, |
659 String packageName, |
672 String packageName, |
660 String relativeName) |
673 String relativeName) |
661 throws IOException |
674 throws IOException |
662 { |
675 { |
709 if (!sourceOrClass.contains(kind)) |
723 if (!sourceOrClass.contains(kind)) |
710 throw new IllegalArgumentException("Invalid kind: " + kind); |
724 throw new IllegalArgumentException("Invalid kind: " + kind); |
711 return getFileForOutput(location, RelativeFile.forClass(className, kind), sibling); |
725 return getFileForOutput(location, RelativeFile.forClass(className, kind), sibling); |
712 } |
726 } |
713 |
727 |
|
728 @DefinedBy(Api.COMPILER) |
714 public FileObject getFileForOutput(Location location, |
729 public FileObject getFileForOutput(Location location, |
715 String packageName, |
730 String packageName, |
716 String relativeName, |
731 String relativeName, |
717 FileObject sibling) |
732 FileObject sibling) |
718 throws IOException |
733 throws IOException |
758 File file = fileName.getFile(dir); // null-safe |
773 File file = fileName.getFile(dir); // null-safe |
759 return new RegularFileObject(this, file); |
774 return new RegularFileObject(this, file); |
760 |
775 |
761 } |
776 } |
762 |
777 |
|
778 @DefinedBy(Api.COMPILER) |
763 public Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles( |
779 public Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles( |
764 Iterable<? extends File> files) |
780 Iterable<? extends File> files) |
765 { |
781 { |
766 ArrayList<RegularFileObject> result; |
782 ArrayList<RegularFileObject> result; |
767 if (files instanceof Collection<?>) |
783 if (files instanceof Collection<?>) |
771 for (File f: files) |
787 for (File f: files) |
772 result.add(new RegularFileObject(this, nullCheck(f))); |
788 result.add(new RegularFileObject(this, nullCheck(f))); |
773 return result; |
789 return result; |
774 } |
790 } |
775 |
791 |
|
792 @DefinedBy(Api.COMPILER) |
776 public Iterable<? extends JavaFileObject> getJavaFileObjects(File... files) { |
793 public Iterable<? extends JavaFileObject> getJavaFileObjects(File... files) { |
777 return getJavaFileObjectsFromFiles(Arrays.asList(nullCheck(files))); |
794 return getJavaFileObjectsFromFiles(Arrays.asList(nullCheck(files))); |
778 } |
795 } |
779 |
796 |
|
797 @DefinedBy(Api.COMPILER) |
780 public void setLocation(Location location, |
798 public void setLocation(Location location, |
781 Iterable<? extends File> path) |
799 Iterable<? extends File> path) |
782 throws IOException |
800 throws IOException |
783 { |
801 { |
784 nullCheck(location); |
802 nullCheck(location); |
785 locations.setLocation(location, path); |
803 locations.setLocation(location, path); |
786 } |
804 } |
787 |
805 |
|
806 @DefinedBy(Api.COMPILER) |
788 public Iterable<? extends File> getLocation(Location location) { |
807 public Iterable<? extends File> getLocation(Location location) { |
789 nullCheck(location); |
808 nullCheck(location); |
790 return locations.getLocation(location); |
809 return locations.getLocation(location); |
791 } |
810 } |
792 |
811 |