author | hseigel |
Wed, 01 Mar 2017 08:00:02 -0500 | |
changeset 46194 | 5596e6f63072 |
parent 43772 | 4e5350b7be75 |
child 44063 | 5f0cf4126949 |
permissions | -rw-r--r-- |
33362 | 1 |
/* |
37848
3c8ff4204d2d
8154956: Module system implementation refresh (4/2016)
alanb
parents:
33715
diff
changeset
|
2 |
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. |
33362 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package jdk.jshell; |
|
27 |
||
28 |
import java.io.ByteArrayInputStream; |
|
29 |
import java.io.ByteArrayOutputStream; |
|
30 |
import java.io.IOException; |
|
31 |
import java.io.InputStream; |
|
32 |
import java.io.OutputStream; |
|
33 |
import java.net.URI; |
|
34 |
import java.nio.file.FileSystems; |
|
35 |
import java.nio.file.Files; |
|
36 |
import java.nio.file.Path; |
|
37 |
import java.util.Collection; |
|
38 |
import java.util.Iterator; |
|
39 |
import java.util.Map; |
|
40 |
import java.util.NoSuchElementException; |
|
41 |
import java.util.Set; |
|
42 |
import java.util.TreeMap; |
|
33715
74b1bed86932
8141092: JShell: Completion hangs on identifier completion
jlahoda
parents:
33362
diff
changeset
|
43 |
|
33362 | 44 |
import javax.tools.JavaFileObject.Kind; |
45 |
import static javax.tools.StandardLocation.CLASS_PATH; |
|
46 |
import javax.tools.FileObject; |
|
47 |
import javax.tools.JavaFileManager; |
|
48 |
import javax.tools.JavaFileObject; |
|
49 |
import javax.tools.SimpleJavaFileObject; |
|
50 |
import javax.tools.StandardJavaFileManager; |
|
33715
74b1bed86932
8141092: JShell: Completion hangs on identifier completion
jlahoda
parents:
33362
diff
changeset
|
51 |
import javax.tools.StandardLocation; |
33362 | 52 |
|
53 |
||
54 |
import static jdk.internal.jshell.debug.InternalDebugControl.DBG_FMGR; |
|
55 |
||
56 |
/** |
|
57 |
* File manager for the compiler API. Reads from memory (Strings) and writes |
|
58 |
* class files to memory (cached OutputMemoryJavaFileObject). |
|
59 |
* |
|
60 |
* @author Robert Field |
|
61 |
*/ |
|
62 |
class MemoryFileManager implements JavaFileManager { |
|
63 |
||
64 |
private final StandardJavaFileManager stdFileManager; |
|
65 |
||
66 |
private final Map<String, OutputMemoryJavaFileObject> classObjects = new TreeMap<>(); |
|
67 |
||
68 |
private ClassFileCreationListener classListener = null; |
|
69 |
||
70 |
private final JShell proc; |
|
71 |
||
33715
74b1bed86932
8141092: JShell: Completion hangs on identifier completion
jlahoda
parents:
33362
diff
changeset
|
72 |
Iterable<? extends Path> getLocationAsPaths(Location loc) { |
74b1bed86932
8141092: JShell: Completion hangs on identifier completion
jlahoda
parents:
33362
diff
changeset
|
73 |
return this.stdFileManager.getLocationAsPaths(loc); |
74b1bed86932
8141092: JShell: Completion hangs on identifier completion
jlahoda
parents:
33362
diff
changeset
|
74 |
} |
74b1bed86932
8141092: JShell: Completion hangs on identifier completion
jlahoda
parents:
33362
diff
changeset
|
75 |
|
33362 | 76 |
static abstract class MemoryJavaFileObject extends SimpleJavaFileObject { |
77 |
||
78 |
public MemoryJavaFileObject(String name, JavaFileObject.Kind kind) { |
|
79 |
super(URI.create("string:///" + name.replace('.', '/') |
|
80 |
+ kind.extension), kind); |
|
81 |
} |
|
82 |
} |
|
83 |
||
84 |
class SourceMemoryJavaFileObject extends MemoryJavaFileObject { |
|
85 |
private final String src; |
|
86 |
private final Object origin; |
|
87 |
||
88 |
SourceMemoryJavaFileObject(Object origin, String className, String code) { |
|
89 |
super(className, JavaFileObject.Kind.SOURCE); |
|
90 |
this.origin = origin; |
|
91 |
this.src = code; |
|
92 |
} |
|
93 |
||
94 |
public Object getOrigin() { |
|
95 |
return origin; |
|
96 |
} |
|
97 |
||
40606
eb2c81860c86
8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents:
40603
diff
changeset
|
98 |
@Override |
33362 | 99 |
public CharSequence getCharContent(boolean ignoreEncodingErrors) { |
100 |
return src; |
|
101 |
} |
|
102 |
} |
|
103 |
||
104 |
static class OutputMemoryJavaFileObject extends MemoryJavaFileObject { |
|
105 |
||
106 |
/** |
|
107 |
* Byte code created by the compiler will be stored in this |
|
108 |
* ByteArrayOutputStream. |
|
109 |
*/ |
|
110 |
private ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
|
111 |
private byte[] bytes = null; |
|
112 |
||
113 |
private final String className; |
|
114 |
||
115 |
public OutputMemoryJavaFileObject(String name, JavaFileObject.Kind kind) { |
|
116 |
super(name, kind); |
|
117 |
this.className = name; |
|
118 |
} |
|
119 |
||
120 |
public byte[] getBytes() { |
|
121 |
if (bytes == null) { |
|
122 |
bytes = bos.toByteArray(); |
|
123 |
bos = null; |
|
124 |
} |
|
125 |
return bytes; |
|
126 |
} |
|
127 |
||
128 |
public void dump() { |
|
129 |
try { |
|
130 |
Path dumpDir = FileSystems.getDefault().getPath("dump"); |
|
131 |
if (Files.notExists(dumpDir)) { |
|
132 |
Files.createDirectory(dumpDir); |
|
133 |
} |
|
134 |
Path file = FileSystems.getDefault().getPath("dump", getName() + ".class"); |
|
135 |
Files.write(file, getBytes()); |
|
136 |
} catch (IOException ex) { |
|
137 |
throw new RuntimeException(ex); |
|
138 |
} |
|
139 |
} |
|
140 |
||
40606
eb2c81860c86
8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents:
40603
diff
changeset
|
141 |
@Override |
33362 | 142 |
public String getName() { |
143 |
return className; |
|
144 |
} |
|
145 |
||
146 |
/** |
|
147 |
* Will provide the compiler with an output stream that leads to our |
|
148 |
* byte array. |
|
149 |
*/ |
|
40606
eb2c81860c86
8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents:
40603
diff
changeset
|
150 |
@Override |
33362 | 151 |
public OutputStream openOutputStream() throws IOException { |
152 |
return bos; |
|
153 |
} |
|
154 |
||
40606
eb2c81860c86
8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents:
40603
diff
changeset
|
155 |
@Override |
33362 | 156 |
public InputStream openInputStream() throws IOException { |
157 |
return new ByteArrayInputStream(getBytes()); |
|
158 |
} |
|
159 |
} |
|
160 |
||
161 |
public MemoryFileManager(StandardJavaFileManager standardManager, JShell proc) { |
|
43758 | 162 |
this.stdFileManager = proc.fileManagerMapping != null |
163 |
? proc.fileManagerMapping.apply(standardManager) |
|
164 |
: standardManager; |
|
33362 | 165 |
this.proc = proc; |
166 |
} |
|
167 |
||
168 |
private Collection<OutputMemoryJavaFileObject> generatedClasses() { |
|
169 |
return classObjects.values(); |
|
170 |
} |
|
171 |
||
172 |
// For debugging dumps |
|
173 |
public void dumpClasses() { |
|
174 |
for (OutputMemoryJavaFileObject co : generatedClasses()) { |
|
175 |
co.dump(); |
|
176 |
} |
|
177 |
} |
|
178 |
||
179 |
public JavaFileObject createSourceFileObject(Object origin, String name, String code) { |
|
180 |
return new SourceMemoryJavaFileObject(origin, name, code); |
|
181 |
} |
|
182 |
||
183 |
/** |
|
184 |
* Returns a class loader for loading plug-ins from the given location. For |
|
185 |
* example, to load annotation processors, a compiler will request a class |
|
186 |
* loader for the {@link |
|
187 |
* StandardLocation#ANNOTATION_PROCESSOR_PATH |
|
188 |
* ANNOTATION_PROCESSOR_PATH} location. |
|
189 |
* |
|
190 |
* @param location a location |
|
191 |
* @return a class loader for the given location; or {@code null} |
|
192 |
* if loading plug-ins from the given location is disabled or if |
|
193 |
* the location is not known |
|
194 |
* @throws SecurityException if a class loader can not be created |
|
195 |
* in the current security context |
|
196 |
* @throws IllegalStateException if {@link #close} has been called |
|
197 |
* and this file manager cannot be reopened |
|
198 |
*/ |
|
40606
eb2c81860c86
8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents:
40603
diff
changeset
|
199 |
@Override |
33362 | 200 |
public ClassLoader getClassLoader(JavaFileManager.Location location) { |
201 |
proc.debug(DBG_FMGR, "getClassLoader: location\n", location); |
|
40603
a890cefaa41b
8158507: JShell: new jdk.jshell.MemoryFileManager(StandardJavaFileManager, JShell) creates a jdk.jshell.MemoryFileManager$REPLClassLoader classloader, which should be performed within a doPrivileged block
rfield
parents:
37848
diff
changeset
|
202 |
return stdFileManager.getClassLoader(location); |
33362 | 203 |
} |
204 |
||
205 |
/** |
|
206 |
* Lists all file objects matching the given criteria in the given |
|
207 |
* location. List file objects in "subpackages" if recurse is |
|
208 |
* true. |
|
209 |
* |
|
210 |
* <p>Note: even if the given location is unknown to this file |
|
211 |
* manager, it may not return {@code null}. Also, an unknown |
|
212 |
* location may not cause an exception. |
|
213 |
* |
|
214 |
* @param location a location |
|
215 |
* @param packageName a package name |
|
216 |
* @param kinds return objects only of these kinds |
|
217 |
* @param recurse if true include "subpackages" |
|
218 |
* @return an Iterable of file objects matching the given criteria |
|
219 |
* @throws IOException if an I/O error occurred, or if {@link |
|
220 |
* #close} has been called and this file manager cannot be |
|
221 |
* reopened |
|
222 |
* @throws IllegalStateException if {@link #close} has been called |
|
223 |
* and this file manager cannot be reopened |
|
224 |
*/ |
|
40606
eb2c81860c86
8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents:
40603
diff
changeset
|
225 |
@Override |
33362 | 226 |
public Iterable<JavaFileObject> list(JavaFileManager.Location location, |
227 |
String packageName, |
|
228 |
Set<JavaFileObject.Kind> kinds, |
|
229 |
boolean recurse) |
|
230 |
throws IOException { |
|
231 |
Iterable<JavaFileObject> stdList = stdFileManager.list(location, packageName, kinds, recurse); |
|
232 |
if (location==CLASS_PATH && packageName.equals("REPL")) { |
|
233 |
// if the desired list is for our JShell package, lazily iterate over |
|
234 |
// first the standard list then any generated classes. |
|
235 |
return () -> new Iterator<JavaFileObject>() { |
|
236 |
boolean stdDone = false; |
|
237 |
Iterator<? extends JavaFileObject> it; |
|
238 |
||
239 |
@Override |
|
240 |
public boolean hasNext() { |
|
241 |
if (it == null) { |
|
242 |
it = stdList.iterator(); |
|
243 |
} |
|
244 |
if (it.hasNext()) { |
|
245 |
return true; |
|
246 |
} |
|
247 |
if (stdDone) { |
|
248 |
return false; |
|
249 |
} else { |
|
250 |
stdDone = true; |
|
251 |
it = generatedClasses().iterator(); |
|
252 |
return it.hasNext(); |
|
253 |
} |
|
254 |
} |
|
255 |
||
256 |
@Override |
|
257 |
public JavaFileObject next() { |
|
258 |
if (!hasNext()) { |
|
259 |
throw new NoSuchElementException(); |
|
260 |
} |
|
261 |
return it.next(); |
|
262 |
} |
|
263 |
||
264 |
}; |
|
265 |
} else { |
|
266 |
return stdList; |
|
267 |
} |
|
268 |
} |
|
269 |
||
270 |
/** |
|
271 |
* Infers a binary name of a file object based on a location. The |
|
272 |
* binary name returned might not be a valid binary name according to |
|
273 |
* <cite>The Java&trade { throw new UnsupportedOperationException("Not supported yet."); } Language Specification</cite>. |
|
274 |
* |
|
275 |
* @param location a location |
|
276 |
* @param file a file object |
|
277 |
* @return a binary name or {@code null} the file object is not |
|
278 |
* found in the given location |
|
279 |
* @throws IllegalStateException if {@link #close} has been called |
|
280 |
* and this file manager cannot be reopened |
|
281 |
*/ |
|
40606
eb2c81860c86
8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents:
40603
diff
changeset
|
282 |
@Override |
33362 | 283 |
public String inferBinaryName(JavaFileManager.Location location, JavaFileObject file) { |
284 |
if (file instanceof OutputMemoryJavaFileObject) { |
|
285 |
OutputMemoryJavaFileObject ofo = (OutputMemoryJavaFileObject) file; |
|
286 |
proc.debug(DBG_FMGR, "inferBinaryName %s => %s\n", file, ofo.getName()); |
|
287 |
return ofo.getName(); |
|
288 |
} else { |
|
289 |
return stdFileManager.inferBinaryName(location, file); |
|
290 |
} |
|
291 |
} |
|
292 |
||
293 |
/** |
|
294 |
* Compares two file objects and return true if they represent the |
|
295 |
* same underlying object. |
|
296 |
* |
|
297 |
* @param a a file object |
|
298 |
* @param b a file object |
|
299 |
* @return true if the given file objects represent the same |
|
300 |
* underlying object |
|
301 |
* |
|
302 |
* @throws IllegalArgumentException if either of the arguments |
|
303 |
* were created with another file manager and this file manager |
|
304 |
* does not support foreign file objects |
|
305 |
*/ |
|
40606
eb2c81860c86
8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents:
40603
diff
changeset
|
306 |
@Override |
33362 | 307 |
public boolean isSameFile(FileObject a, FileObject b) { |
308 |
return stdFileManager.isSameFile(b, b); |
|
309 |
} |
|
310 |
||
311 |
/** |
|
312 |
* Determines if the given option is supported and if so, the |
|
313 |
* number of arguments the option takes. |
|
314 |
* |
|
315 |
* @param option an option |
|
316 |
* @return the number of arguments the given option takes or -1 if |
|
317 |
* the option is not supported |
|
318 |
*/ |
|
40606
eb2c81860c86
8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents:
40603
diff
changeset
|
319 |
@Override |
33362 | 320 |
public int isSupportedOption(String option) { |
321 |
proc.debug(DBG_FMGR, "isSupportedOption: %s\n", option); |
|
322 |
return stdFileManager.isSupportedOption(option); |
|
323 |
} |
|
324 |
||
325 |
/** |
|
326 |
* Handles one option. If {@code current} is an option to this |
|
327 |
* file manager it will consume any arguments to that option from |
|
328 |
* {@code remaining} and return true, otherwise return false. |
|
329 |
* |
|
330 |
* @param current current option |
|
331 |
* @param remaining remaining options |
|
332 |
* @return true if this option was handled by this file manager, |
|
333 |
* false otherwise |
|
334 |
* @throws IllegalArgumentException if this option to this file |
|
335 |
* manager is used incorrectly |
|
336 |
* @throws IllegalStateException if {@link #close} has been called |
|
337 |
* and this file manager cannot be reopened |
|
338 |
*/ |
|
40606
eb2c81860c86
8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents:
40603
diff
changeset
|
339 |
@Override |
33362 | 340 |
public boolean handleOption(String current, Iterator<String> remaining) { |
341 |
proc.debug(DBG_FMGR, "handleOption: current: %s\n", current + |
|
342 |
", remaining: " + remaining); |
|
343 |
return stdFileManager.handleOption(current, remaining); |
|
344 |
} |
|
345 |
||
346 |
/** |
|
347 |
* Determines if a location is known to this file manager. |
|
348 |
* |
|
349 |
* @param location a location |
|
350 |
* @return true if the location is known |
|
351 |
*/ |
|
40606
eb2c81860c86
8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents:
40603
diff
changeset
|
352 |
@Override |
33362 | 353 |
public boolean hasLocation(JavaFileManager.Location location) { |
354 |
proc.debug(DBG_FMGR, "hasLocation: location: %s\n", location); |
|
355 |
return stdFileManager.hasLocation(location); |
|
356 |
} |
|
357 |
||
358 |
interface ClassFileCreationListener { |
|
359 |
void newClassFile(OutputMemoryJavaFileObject jfo, JavaFileManager.Location location, |
|
360 |
String className, Kind kind, FileObject sibling); |
|
361 |
} |
|
362 |
||
363 |
void registerClassFileCreationListener(ClassFileCreationListener listen) { |
|
364 |
this.classListener = listen; |
|
365 |
} |
|
366 |
||
367 |
/** |
|
368 |
* Returns a {@linkplain JavaFileObject file object} for input |
|
369 |
* representing the specified class of the specified kind in the |
|
370 |
* given location. |
|
371 |
* |
|
372 |
* @param location a location |
|
373 |
* @param className the name of a class |
|
374 |
* @param kind the kind of file, must be one of {@link |
|
375 |
* JavaFileObject.Kind#SOURCE SOURCE} or {@link |
|
376 |
* JavaFileObject.Kind#CLASS CLASS} |
|
377 |
* @return a file object, might return {@code null} if the |
|
378 |
* file does not exist |
|
379 |
* @throws IllegalArgumentException if the location is not known |
|
380 |
* to this file manager and the file manager does not support |
|
381 |
* unknown locations, or if the kind is not valid |
|
382 |
* @throws IOException if an I/O error occurred, or if {@link |
|
383 |
* #close} has been called and this file manager cannot be |
|
384 |
* reopened |
|
385 |
* @throws IllegalStateException if {@link #close} has been called |
|
386 |
* and this file manager cannot be reopened |
|
387 |
*/ |
|
40606
eb2c81860c86
8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents:
40603
diff
changeset
|
388 |
@Override |
33362 | 389 |
public JavaFileObject getJavaFileForInput(JavaFileManager.Location location, |
390 |
String className, |
|
391 |
JavaFileObject.Kind kind) |
|
392 |
throws IOException { |
|
393 |
return stdFileManager.getJavaFileForInput(location, className, kind); |
|
394 |
} |
|
395 |
||
396 |
/** |
|
397 |
* Returns a {@linkplain JavaFileObject file object} for output |
|
398 |
* representing the specified class of the specified kind in the |
|
399 |
* given location. |
|
400 |
* |
|
401 |
* <p>Optionally, this file manager might consider the sibling as |
|
402 |
* a hint for where to place the output. The exact semantics of |
|
403 |
* this hint is unspecified. The JDK compiler, javac, for |
|
404 |
* example, will place class files in the same directories as |
|
405 |
* originating source files unless a class file output directory |
|
406 |
* is provided. To facilitate this behavior, javac might provide |
|
407 |
* the originating source file as sibling when calling this |
|
408 |
* method. |
|
409 |
* |
|
410 |
* @param location a location |
|
411 |
* @param className the name of a class |
|
412 |
* @param kind the kind of file, must be one of {@link |
|
413 |
* JavaFileObject.Kind#SOURCE SOURCE} or {@link |
|
414 |
* JavaFileObject.Kind#CLASS CLASS} |
|
415 |
* @param sibling a file object to be used as hint for placement; |
|
416 |
* might be {@code null} |
|
417 |
* @return a file object for output |
|
418 |
* @throws IllegalArgumentException if sibling is not known to |
|
419 |
* this file manager, or if the location is not known to this file |
|
420 |
* manager and the file manager does not support unknown |
|
421 |
* locations, or if the kind is not valid |
|
422 |
* @throws IOException if an I/O error occurred, or if {@link |
|
423 |
* #close} has been called and this file manager cannot be |
|
424 |
* reopened |
|
425 |
* @throws IllegalStateException {@link #close} has been called |
|
426 |
* and this file manager cannot be reopened |
|
427 |
*/ |
|
40606
eb2c81860c86
8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents:
40603
diff
changeset
|
428 |
@Override |
33362 | 429 |
public JavaFileObject getJavaFileForOutput(JavaFileManager.Location location, |
430 |
String className, Kind kind, FileObject sibling) throws IOException { |
|
431 |
||
432 |
OutputMemoryJavaFileObject fo; |
|
433 |
fo = new OutputMemoryJavaFileObject(className, kind); |
|
434 |
classObjects.put(className, fo); |
|
435 |
proc.debug(DBG_FMGR, "Set out file: %s = %s\n", className, fo); |
|
436 |
if (classListener != null) { |
|
437 |
classListener.newClassFile(fo, location, className, kind, sibling); |
|
438 |
} |
|
439 |
return fo; |
|
440 |
} |
|
441 |
||
442 |
/** |
|
443 |
* Returns a {@linkplain FileObject file object} for input |
|
444 |
* representing the specified <a href="JavaFileManager.html#relative_name">relative |
|
445 |
* name</a> in the specified package in the given location. |
|
446 |
* |
|
447 |
* <p>If the returned object represents a {@linkplain |
|
448 |
* JavaFileObject.Kind#SOURCE source} or {@linkplain |
|
449 |
* JavaFileObject.Kind#CLASS class} file, it must be an instance |
|
450 |
* of {@link JavaFileObject}. |
|
451 |
* |
|
452 |
* <p>Informally, the file object returned by this method is |
|
453 |
* located in the concatenation of the location, package name, and |
|
454 |
* relative name. For example, to locate the properties file |
|
455 |
* "resources/compiler.properties" in the package |
|
456 |
* "com.sun.tools.javac" in the {@linkplain |
|
457 |
* StandardLocation#SOURCE_PATH SOURCE_PATH} location, this method |
|
458 |
* might be called like so: |
|
459 |
* |
|
460 |
* <pre>getFileForInput(SOURCE_PATH, "com.sun.tools.javac", "resources/compiler.properties");</pre> |
|
461 |
* |
|
462 |
* <p>If the call was executed on Windows, with SOURCE_PATH set to |
|
463 |
* <code>"C:\Documents and Settings\UncleBob\src\share\classes"</code>, |
|
464 |
* a valid result would be a file object representing the file |
|
465 |
* <code>"C:\Documents and Settings\UncleBob\src\share\classes\com\sun\tools\javac\resources\compiler.properties"</code>. |
|
466 |
* |
|
467 |
* @param location a location |
|
468 |
* @param packageName a package name |
|
469 |
* @param relativeName a relative name |
|
470 |
* @return a file object, might return {@code null} if the file |
|
471 |
* does not exist |
|
472 |
* @throws IllegalArgumentException if the location is not known |
|
473 |
* to this file manager and the file manager does not support |
|
474 |
* unknown locations, or if {@code relativeName} is not valid |
|
475 |
* @throws IOException if an I/O error occurred, or if {@link |
|
476 |
* #close} has been called and this file manager cannot be |
|
477 |
* reopened |
|
478 |
* @throws IllegalStateException if {@link #close} has been called |
|
479 |
* and this file manager cannot be reopened |
|
480 |
*/ |
|
40606
eb2c81860c86
8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents:
40603
diff
changeset
|
481 |
@Override |
33362 | 482 |
public FileObject getFileForInput(JavaFileManager.Location location, |
483 |
String packageName, |
|
484 |
String relativeName) |
|
485 |
throws IOException { |
|
486 |
proc.debug(DBG_FMGR, "getFileForInput location=%s packageName=%s\n", location, packageName); |
|
487 |
return stdFileManager.getFileForInput(location, packageName, relativeName); |
|
488 |
} |
|
489 |
||
490 |
/** |
|
491 |
* Returns a {@linkplain FileObject file object} for output |
|
492 |
* representing the specified <a href="JavaFileManager.html#relative_name">relative |
|
493 |
* name</a> in the specified package in the given location. |
|
494 |
* |
|
495 |
* <p>Optionally, this file manager might consider the sibling as |
|
496 |
* a hint for where to place the output. The exact semantics of |
|
497 |
* this hint is unspecified. The JDK compiler, javac, for |
|
498 |
* example, will place class files in the same directories as |
|
499 |
* originating source files unless a class file output directory |
|
500 |
* is provided. To facilitate this behavior, javac might provide |
|
501 |
* the originating source file as sibling when calling this |
|
502 |
* method. |
|
503 |
* |
|
504 |
* <p>If the returned object represents a {@linkplain |
|
505 |
* JavaFileObject.Kind#SOURCE source} or {@linkplain |
|
506 |
* JavaFileObject.Kind#CLASS class} file, it must be an instance |
|
507 |
* of {@link JavaFileObject}. |
|
508 |
* |
|
509 |
* <p>Informally, the file object returned by this method is |
|
510 |
* located in the concatenation of the location, package name, and |
|
511 |
* relative name or next to the sibling argument. See {@link |
|
512 |
* #getFileForInput getFileForInput} for an example. |
|
513 |
* |
|
514 |
* @param location a location |
|
515 |
* @param packageName a package name |
|
516 |
* @param relativeName a relative name |
|
517 |
* @param sibling a file object to be used as hint for placement; |
|
518 |
* might be {@code null} |
|
519 |
* @return a file object |
|
520 |
* @throws IllegalArgumentException if sibling is not known to |
|
521 |
* this file manager, or if the location is not known to this file |
|
522 |
* manager and the file manager does not support unknown |
|
523 |
* locations, or if {@code relativeName} is not valid |
|
524 |
* @throws IOException if an I/O error occurred, or if {@link |
|
525 |
* #close} has been called and this file manager cannot be |
|
526 |
* reopened |
|
527 |
* @throws IllegalStateException if {@link #close} has been called |
|
528 |
* and this file manager cannot be reopened |
|
529 |
*/ |
|
40606
eb2c81860c86
8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents:
40603
diff
changeset
|
530 |
@Override |
33362 | 531 |
public FileObject getFileForOutput(JavaFileManager.Location location, |
532 |
String packageName, |
|
533 |
String relativeName, |
|
534 |
FileObject sibling) |
|
535 |
throws IOException { |
|
536 |
throw new UnsupportedOperationException("getFileForOutput: location: " + location + |
|
537 |
", packageName: " + packageName + |
|
538 |
", relativeName: " + relativeName + |
|
539 |
", sibling: " + sibling); |
|
540 |
} |
|
541 |
||
43772
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43758
diff
changeset
|
542 |
@Override |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43758
diff
changeset
|
543 |
public Location getLocationForModule(Location location, String moduleName) throws IOException { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43758
diff
changeset
|
544 |
return stdFileManager.getLocationForModule(location, moduleName); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43758
diff
changeset
|
545 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43758
diff
changeset
|
546 |
|
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43758
diff
changeset
|
547 |
@Override |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43758
diff
changeset
|
548 |
public Location getLocationForModule(Location location, JavaFileObject fo, String pkgName) throws IOException { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43758
diff
changeset
|
549 |
return stdFileManager.getLocationForModule(location, fo, pkgName); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43758
diff
changeset
|
550 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43758
diff
changeset
|
551 |
|
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43758
diff
changeset
|
552 |
@Override |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43758
diff
changeset
|
553 |
public String inferModuleName(Location location) throws IOException { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43758
diff
changeset
|
554 |
return stdFileManager.inferModuleName(location); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43758
diff
changeset
|
555 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43758
diff
changeset
|
556 |
|
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43758
diff
changeset
|
557 |
@Override |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43758
diff
changeset
|
558 |
public Iterable<Set<Location>> listLocationsForModules(Location location) throws IOException { |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43758
diff
changeset
|
559 |
return stdFileManager.listLocationsForModules(location); |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43758
diff
changeset
|
560 |
} |
4e5350b7be75
8173777: Merge javac -Xmodule into javac--patch-module
jlahoda
parents:
43758
diff
changeset
|
561 |
|
33362 | 562 |
/** |
563 |
* Flushes any resources opened for output by this file manager |
|
564 |
* directly or indirectly. Flushing a closed file manager has no |
|
565 |
* effect. |
|
566 |
* |
|
567 |
* @throws IOException if an I/O error occurred |
|
568 |
* @see #close |
|
569 |
*/ |
|
40606
eb2c81860c86
8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents:
40603
diff
changeset
|
570 |
@Override |
33362 | 571 |
public void flush() throws IOException { |
572 |
// Nothing to flush |
|
573 |
} |
|
574 |
||
575 |
/** |
|
576 |
* Releases any resources opened by this file manager directly or |
|
577 |
* indirectly. This might render this file manager useless and |
|
578 |
* the effect of subsequent calls to methods on this object or any |
|
579 |
* objects obtained through this object is undefined unless |
|
580 |
* explicitly allowed. However, closing a file manager which has |
|
581 |
* already been closed has no effect. |
|
582 |
* |
|
583 |
* @throws IOException if an I/O error occurred |
|
584 |
* @see #flush |
|
585 |
*/ |
|
40606
eb2c81860c86
8164836: TEST_BUG: adjust scope of the DefinedByAnalyzer in tools/all/RunCodingRules.java
jlahoda
parents:
40603
diff
changeset
|
586 |
@Override |
33362 | 587 |
public void close() throws IOException { |
588 |
// Nothing to close |
|
589 |
} |
|
590 |
} |