Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/src/share/classes/javax/tools/StandardJavaFileManager.java
38900 views
/*1* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.tools;2627import java.io.File;28import java.io.IOException;29import java.util.*;3031/**32* File manager based on {@linkplain File java.io.File}. A common way33* to obtain an instance of this class is using {@linkplain34* JavaCompiler#getStandardFileManager35* getStandardFileManager}, for example:36*37* <pre>38* JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();39* {@code DiagnosticCollector<JavaFileObject>} diagnostics =40* new {@code DiagnosticCollector<JavaFileObject>()};41* StandardJavaFileManager fm = compiler.getStandardFileManager(diagnostics, null, null);42* </pre>43*44* This file manager creates file objects representing regular45* {@linkplain File files},46* {@linkplain java.util.zip.ZipEntry zip file entries}, or entries in47* similar file system based containers. Any file object returned48* from a file manager implementing this interface must observe the49* following behavior:50*51* <ul>52* <li>53* File names need not be canonical.54* </li>55* <li>56* For file objects representing regular files57* <ul>58* <li>59* the method <code>{@linkplain FileObject#delete()}</code>60* is equivalent to <code>{@linkplain File#delete()}</code>,61* </li>62* <li>63* the method <code>{@linkplain FileObject#getLastModified()}</code>64* is equivalent to <code>{@linkplain File#lastModified()}</code>,65* </li>66* <li>67* the methods <code>{@linkplain FileObject#getCharContent(boolean)}</code>,68* <code>{@linkplain FileObject#openInputStream()}</code>, and69* <code>{@linkplain FileObject#openReader(boolean)}</code>70* must succeed if the following would succeed (ignoring71* encoding issues):72* <blockquote>73* <pre>new {@linkplain java.io.FileInputStream#FileInputStream(File) FileInputStream}(new {@linkplain File#File(java.net.URI) File}({@linkplain FileObject fileObject}.{@linkplain FileObject#toUri() toUri}()))</pre>74* </blockquote>75* </li>76* <li>77* and the methods78* <code>{@linkplain FileObject#openOutputStream()}</code>, and79* <code>{@linkplain FileObject#openWriter()}</code> must80* succeed if the following would succeed (ignoring encoding81* issues):82* <blockquote>83* <pre>new {@linkplain java.io.FileOutputStream#FileOutputStream(File) FileOutputStream}(new {@linkplain File#File(java.net.URI) File}({@linkplain FileObject fileObject}.{@linkplain FileObject#toUri() toUri}()))</pre>84* </blockquote>85* </li>86* </ul>87* </li>88* <li>89* The {@linkplain java.net.URI URI} returned from90* <code>{@linkplain FileObject#toUri()}</code>91* <ul>92* <li>93* must be {@linkplain java.net.URI#isAbsolute() absolute} (have a schema), and94* </li>95* <li>96* must have a {@linkplain java.net.URI#normalize() normalized}97* {@linkplain java.net.URI#getPath() path component} which98* can be resolved without any process-specific context such99* as the current directory (file names must be absolute).100* </li>101* </ul>102* </li>103* </ul>104*105* According to these rules, the following URIs, for example, are106* allowed:107* <ul>108* <li>109* <code>file:///C:/Documents%20and%20Settings/UncleBob/BobsApp/Test.java</code>110* </li>111* <li>112* <code>jar:///C:/Documents%20and%20Settings/UncleBob/lib/vendorA.jar!com/vendora/LibraryClass.class</code>113* </li>114* </ul>115* Whereas these are not (reason in parentheses):116* <ul>117* <li>118* <code>file:BobsApp/Test.java</code> (the file name is relative119* and depend on the current directory)120* </li>121* <li>122* <code>jar:lib/vendorA.jar!com/vendora/LibraryClass.class</code>123* (the first half of the path depends on the current directory,124* whereas the component after ! is legal)125* </li>126* <li>127* <code>Test.java</code> (this URI depends on the current128* directory and does not have a schema)129* </li>130* <li>131* <code>jar:///C:/Documents%20and%20Settings/UncleBob/BobsApp/../lib/vendorA.jar!com/vendora/LibraryClass.class</code>132* (the path is not normalized)133* </li>134* </ul>135*136* @author Peter von der Ahé137* @since 1.6138*/139public interface StandardJavaFileManager extends JavaFileManager {140141/**142* Compares two file objects and return true if they represent the143* same canonical file, zip file entry, or entry in any file144* system based container.145*146* @param a a file object147* @param b a file object148* @return true if the given file objects represent the same149* canonical file or zip file entry; false otherwise150*151* @throws IllegalArgumentException if either of the arguments152* were created with another file manager implementation153*/154boolean isSameFile(FileObject a, FileObject b);155156/**157* Gets file objects representing the given files.158*159* @param files a list of files160* @return a list of file objects161* @throws IllegalArgumentException if the list of files includes162* a directory163*/164Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles(165Iterable<? extends File> files);166167/**168* Gets file objects representing the given files.169* Convenience method equivalent to:170*171* <pre>172* getJavaFileObjectsFromFiles({@linkplain java.util.Arrays#asList Arrays.asList}(files))173* </pre>174*175* @param files an array of files176* @return a list of file objects177* @throws IllegalArgumentException if the array of files includes178* a directory179* @throws NullPointerException if the given array contains null180* elements181*/182Iterable<? extends JavaFileObject> getJavaFileObjects(File... files);183184/**185* Gets file objects representing the given file names.186*187* @param names a list of file names188* @return a list of file objects189* @throws IllegalArgumentException if the list of file names190* includes a directory191*/192Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(193Iterable<String> names);194195/**196* Gets file objects representing the given file names.197* Convenience method equivalent to:198*199* <pre>200* getJavaFileObjectsFromStrings({@linkplain java.util.Arrays#asList Arrays.asList}(names))201* </pre>202*203* @param names a list of file names204* @return a list of file objects205* @throws IllegalArgumentException if the array of file names206* includes a directory207* @throws NullPointerException if the given array contains null208* elements209*/210Iterable<? extends JavaFileObject> getJavaFileObjects(String... names);211212/**213* Associates the given path with the given location. Any214* previous value will be discarded.215*216* @param location a location217* @param path a list of files, if {@code null} use the default218* path for this location219* @see #getLocation220* @throws IllegalArgumentException if location is an output221* location and path does not contain exactly one element222* @throws IOException if location is an output location and path223* does not represent an existing directory224*/225void setLocation(Location location, Iterable<? extends File> path)226throws IOException;227228/**229* Gets the path associated with the given location.230*231* @param location a location232* @return a list of files or {@code null} if this location has no233* associated path234* @see #setLocation235*/236Iterable<? extends File> getLocation(Location location);237238}239240241