60 * <p><b>This is NOT part of any supported API. |
60 * <p><b>This is NOT part of any supported API. |
61 * If you write code that depends on this, you do so at your own risk. |
61 * If you write code that depends on this, you do so at your own risk. |
62 * This code and its internal interfaces are subject to change or |
62 * This code and its internal interfaces are subject to change or |
63 * deletion without notice.</b> |
63 * deletion without notice.</b> |
64 */ |
64 */ |
65 abstract class PathFileObject implements JavaFileObject { |
65 public abstract class PathFileObject implements JavaFileObject { |
66 private JavacPathFileManager fileManager; |
66 private final BaseFileManager fileManager; |
67 private Path path; |
67 private final Path path; |
68 |
68 |
69 /** |
69 /** |
70 * Create a PathFileObject within a directory, such that the binary name |
70 * Create a PathFileObject within a directory, such that the binary name |
71 * can be inferred from the relationship to the parent directory. |
71 * can be inferred from the relationship to the parent directory. |
72 */ |
72 */ |
73 static PathFileObject createDirectoryPathFileObject(JavacPathFileManager fileManager, |
73 static PathFileObject createDirectoryPathFileObject(BaseFileManager fileManager, |
74 final Path path, final Path dir) { |
74 final Path path, final Path dir) { |
75 return new PathFileObject(fileManager, path) { |
75 return new PathFileObject(fileManager, path) { |
76 @Override |
76 @Override |
77 String inferBinaryName(Iterable<? extends Path> paths) { |
77 public String inferBinaryName(Iterable<? extends Path> paths) { |
78 return toBinaryName(dir.relativize(path)); |
78 return toBinaryName(dir.relativize(path)); |
79 } |
79 } |
80 }; |
80 }; |
81 } |
81 } |
82 |
82 |
83 /** |
83 /** |
84 * Create a PathFileObject in a file system such as a jar file, such that |
84 * Create a PathFileObject in a file system such as a jar file, such that |
85 * the binary name can be inferred from its position within the filesystem. |
85 * the binary name can be inferred from its position within the filesystem. |
86 */ |
86 */ |
87 static PathFileObject createJarPathFileObject(JavacPathFileManager fileManager, |
87 public static PathFileObject createJarPathFileObject(BaseFileManager fileManager, |
88 final Path path) { |
88 final Path path) { |
89 return new PathFileObject(fileManager, path) { |
89 return new PathFileObject(fileManager, path) { |
90 @Override |
90 @Override |
91 String inferBinaryName(Iterable<? extends Path> paths) { |
91 public String inferBinaryName(Iterable<? extends Path> paths) { |
92 return toBinaryName(path); |
92 return toBinaryName(path); |
|
93 } |
|
94 }; |
|
95 } |
|
96 |
|
97 /** |
|
98 * Create a PathFileObject in a modular file system, such as jrt:, such that |
|
99 * the binary name can be inferred from its position within the filesystem. |
|
100 */ |
|
101 public static PathFileObject createJRTPathFileObject(BaseFileManager fileManager, |
|
102 final Path path) { |
|
103 return new PathFileObject(fileManager, path) { |
|
104 @Override |
|
105 public String inferBinaryName(Iterable<? extends Path> paths) { |
|
106 // use subpath to ignore the leading component containing the module name |
|
107 return toBinaryName(path.subpath(1, path.getNameCount())); |
93 } |
108 } |
94 }; |
109 }; |
95 } |
110 } |
96 |
111 |
97 /** |
112 /** |
98 * Create a PathFileObject whose binary name can be inferred from the |
113 * Create a PathFileObject whose binary name can be inferred from the |
99 * relative path to a sibling. |
114 * relative path to a sibling. |
100 */ |
115 */ |
101 static PathFileObject createSiblingPathFileObject(JavacPathFileManager fileManager, |
116 static PathFileObject createSiblingPathFileObject(BaseFileManager fileManager, |
102 final Path path, final String relativePath) { |
117 final Path path, final String relativePath) { |
103 return new PathFileObject(fileManager, path) { |
118 return new PathFileObject(fileManager, path) { |
104 @Override |
119 @Override |
105 String inferBinaryName(Iterable<? extends Path> paths) { |
120 public String inferBinaryName(Iterable<? extends Path> paths) { |
106 return toBinaryName(relativePath, "/"); |
121 return toBinaryName(relativePath, "/"); |
107 } |
122 } |
108 }; |
123 }; |
109 } |
124 } |
110 |
125 |
111 /** |
126 /** |
112 * Create a PathFileObject whose binary name might be inferred from its |
127 * Create a PathFileObject whose binary name might be inferred from its |
113 * position on a search path. |
128 * position on a search path. |
114 */ |
129 */ |
115 static PathFileObject createSimplePathFileObject(JavacPathFileManager fileManager, |
130 static PathFileObject createSimplePathFileObject(BaseFileManager fileManager, |
116 final Path path) { |
131 final Path path) { |
117 return new PathFileObject(fileManager, path) { |
132 return new PathFileObject(fileManager, path) { |
118 @Override |
133 @Override |
119 String inferBinaryName(Iterable<? extends Path> paths) { |
134 public String inferBinaryName(Iterable<? extends Path> paths) { |
120 Path absPath = path.toAbsolutePath(); |
135 Path absPath = path.toAbsolutePath(); |
121 for (Path p: paths) { |
136 for (Path p: paths) { |
122 Path ap = p.toAbsolutePath(); |
137 Path ap = p.toAbsolutePath(); |
123 if (absPath.startsWith(ap)) { |
138 if (absPath.startsWith(ap)) { |
124 try { |
139 try { |