langtools/src/java.compiler/share/classes/javax/tools/StandardJavaFileManager.java
author amurillo
Thu, 13 Aug 2015 15:50:52 -0700
changeset 32224 dae855d05f6c
parent 28332 cd3ea1087d2b
child 34912 954fa9df99c7
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
     2
 * Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4548
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4548
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4548
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4548
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4548
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package javax.tools;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.io.File;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
    30
import java.nio.file.Path;
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
    31
import java.util.Arrays;
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
    32
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
    33
import static javax.tools.FileManagerUtils.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
/**
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
    36
 * File manager based on {@linkplain File java.io.File} and {@linkplain Path java.nio.file.Path}.
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
    37
 *
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
    38
 * A common way to obtain an instance of this class is using
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
    39
 * {@linkplain JavaCompiler#getStandardFileManager getStandardFileManager}, for example:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 * <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 *   JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 *   {@code DiagnosticCollector<JavaFileObject>} diagnostics =
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 *       new {@code DiagnosticCollector<JavaFileObject>()};
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 *   StandardJavaFileManager fm = compiler.getStandardFileManager(diagnostics, null, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 * </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 * This file manager creates file objects representing regular
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 * {@linkplain File files},
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 * {@linkplain java.util.zip.ZipEntry zip file entries}, or entries in
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 * similar file system based containers.  Any file object returned
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 * from a file manager implementing this interface must observe the
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 * following behavior:
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 * <ul>
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
 *   <li>
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
 *     File names need not be canonical.
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
 *   </li>
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
 *   <li>
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
 *     For file objects representing regular files
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
 *     <ul>
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
 *       <li>
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
 *         the method <code>{@linkplain FileObject#delete()}</code>
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
 *         is equivalent to <code>{@linkplain File#delete()}</code>,
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
 *       </li>
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
 *       <li>
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
 *         the method <code>{@linkplain FileObject#getLastModified()}</code>
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
 *         is equivalent to <code>{@linkplain File#lastModified()}</code>,
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
 *       </li>
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
 *       <li>
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
 *         the methods <code>{@linkplain FileObject#getCharContent(boolean)}</code>,
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
 *         <code>{@linkplain FileObject#openInputStream()}</code>, and
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
 *         <code>{@linkplain FileObject#openReader(boolean)}</code>
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
 *         must succeed if the following would succeed (ignoring
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
 *         encoding issues):
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
 *         <blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
 *           <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>
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
 *         </blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
 *       </li>
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
 *       <li>
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
 *         and the methods
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
 *         <code>{@linkplain FileObject#openOutputStream()}</code>, and
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
 *         <code>{@linkplain FileObject#openWriter()}</code> must
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
 *         succeed if the following would succeed (ignoring encoding
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
 *         issues):
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
 *         <blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
 *           <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>
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
 *         </blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
 *       </li>
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
 *     </ul>
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
 *   </li>
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
 *   <li>
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
 *     The {@linkplain java.net.URI URI} returned from
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
 *     <code>{@linkplain FileObject#toUri()}</code>
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
 *     <ul>
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
 *       <li>
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
 *         must be {@linkplain java.net.URI#isAbsolute() absolute} (have a schema), and
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
 *       </li>
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
 *       <li>
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
 *         must have a {@linkplain java.net.URI#normalize() normalized}
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
 *         {@linkplain java.net.URI#getPath() path component} which
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
 *         can be resolved without any process-specific context such
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
 *         as the current directory (file names must be absolute).
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
 *       </li>
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
 *     </ul>
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
 *   </li>
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
 * </ul>
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
 * According to these rules, the following URIs, for example, are
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
 * allowed:
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
 * <ul>
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
 *   <li>
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
 *     <code>file:///C:/Documents%20and%20Settings/UncleBob/BobsApp/Test.java</code>
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
 *   </li>
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
 *   <li>
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   116
 *     <code>jar:///C:/Documents%20and%20Settings/UncleBob/lib/vendorA.jar!/com/vendora/LibraryClass.class</code>
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
 *   </li>
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
 * </ul>
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
 * Whereas these are not (reason in parentheses):
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
 * <ul>
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
 *   <li>
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
 *     <code>file:BobsApp/Test.java</code> (the file name is relative
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
 *     and depend on the current directory)
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
 *   </li>
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
 *   <li>
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   126
 *     <code>jar:lib/vendorA.jar!/com/vendora/LibraryClass.class</code>
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
 *     (the first half of the path depends on the current directory,
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
 *     whereas the component after ! is legal)
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
 *   </li>
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
 *   <li>
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
 *     <code>Test.java</code> (this URI depends on the current
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
 *     directory and does not have a schema)
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
 *   </li>
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
 *   <li>
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
 *     <code>jar:///C:/Documents%20and%20Settings/UncleBob/BobsApp/../lib/vendorA.jar!com/vendora/LibraryClass.class</code>
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
 *     (the path is not normalized)
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
 *   </li>
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
 * </ul>
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
 *
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   140
 * <p>All implementations of this interface must support Path objects representing
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   141
 * files in the {@linkplain java.nio.file.FileSystems#getDefault() default file system.}
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   142
 * It is recommended that implementations should support Path objects from any filesystem.</p>
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   143
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
 * @author Peter von der Ah&eacute;
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
 * @since 1.6
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
public interface StandardJavaFileManager extends JavaFileManager {
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
     * Compares two file objects and return true if they represent the
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
     * same canonical file, zip file entry, or entry in any file
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
     * system based container.
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
     * @param a a file object
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
     * @param b a file object
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
     * @return true if the given file objects represent the same
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   157
     * canonical file, zip file entry or path; false otherwise
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
     * @throws IllegalArgumentException if either of the arguments
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
     * were created with another file manager implementation
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
     */
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   162
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    boolean isSameFile(FileObject a, FileObject b);
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 5520
diff changeset
   166
     * Returns file objects representing the given files.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
     * @param files a list of files
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
     * @return a list of file objects
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     * @throws IllegalArgumentException if the list of files includes
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
     * a directory
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
    Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles(
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
        Iterable<? extends File> files);
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
    /**
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   177
     * Returns file objects representing the given paths.
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   178
     *
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   179
     * <p>The default implementation converts each path to a file and calls
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   180
     * {@link #getJavaFileObjectsFromFiles getJavaObjectsFromFiles}.
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   181
     * IllegalArgumentException will be thrown if any of the paths
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   182
     * cannot be converted to a file.
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   183
     *
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   184
     * @param paths a list of paths
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   185
     * @return a list of file objects
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   186
     * @throws IllegalArgumentException if the list of paths includes
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   187
     * a directory or if this file manager does not support any of the
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   188
     * given paths.
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   189
     *
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   190
     * @since 1.9
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   191
     */
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   192
    default Iterable<? extends JavaFileObject> getJavaFileObjectsFromPaths(
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   193
            Iterable<? extends Path> paths) {
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   194
        return getJavaFileObjectsFromFiles(asFiles(paths));
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   195
    }
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   196
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   197
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 5520
diff changeset
   198
     * Returns file objects representing the given files.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
     * Convenience method equivalent to:
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
     * <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
     *     getJavaFileObjectsFromFiles({@linkplain java.util.Arrays#asList Arrays.asList}(files))
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
     * </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
     * @param files an array of files
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
     * @return a list of file objects
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
     * @throws IllegalArgumentException if the array of files includes
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
     * a directory
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
     * @throws NullPointerException if the given array contains null
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
     * elements
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
    Iterable<? extends JavaFileObject> getJavaFileObjects(File... files);
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
    /**
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   215
     * Returns file objects representing the given paths.
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   216
     * Convenience method equivalent to:
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   217
     *
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   218
     * <pre>
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   219
     *     getJavaFileObjectsFromPaths({@linkplain java.util.Arrays#asList Arrays.asList}(paths))
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   220
     * </pre>
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   221
     *
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   222
     * @param paths an array of paths
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   223
     * @return a list of file objects
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   224
     * @throws IllegalArgumentException if the array of files includes
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   225
     * a directory
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   226
     * @throws NullPointerException if the given array contains null
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   227
     * elements
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   228
     *
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   229
     * @since 1.9
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   230
     */
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   231
    default Iterable<? extends JavaFileObject> getJavaFileObjects(Path... paths) {
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   232
        return getJavaFileObjectsFromPaths(Arrays.asList(paths));
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   233
    }
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   234
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   235
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 5520
diff changeset
   236
     * Returns file objects representing the given file names.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
     * @param names a list of file names
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
     * @return a list of file objects
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
     * @throws IllegalArgumentException if the list of file names
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
     * includes a directory
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
    Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
        Iterable<String> names);
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 5520
diff changeset
   247
     * Returns file objects representing the given file names.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
     * Convenience method equivalent to:
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
     * <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
     *     getJavaFileObjectsFromStrings({@linkplain java.util.Arrays#asList Arrays.asList}(names))
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
     * </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
     * @param names a list of file names
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
     * @return a list of file objects
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
     * @throws IllegalArgumentException if the array of file names
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
     * includes a directory
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
     * @throws NullPointerException if the given array contains null
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
     * elements
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
    Iterable<? extends JavaFileObject> getJavaFileObjects(String... names);
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
    /**
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   264
     * Associates the given search path with the given location.  Any
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
     * previous value will be discarded.
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
     * @param location a location
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   268
     * @param files a list of files, if {@code null} use the default
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   269
     * search path for this location
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
     * @see #getLocation
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   271
     * @throws IllegalArgumentException if {@code location} is an output
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   272
     * location and {@code files} does not contain exactly one element
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   273
     * @throws IOException if {@code location} is an output location and
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
     * does not represent an existing directory
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
     */
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   276
    void setLocation(Location location, Iterable<? extends File> files)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
        throws IOException;
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
    /**
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   280
     * Associates the given search path with the given location.  Any
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   281
     * previous value will be discarded.
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   282
     *
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   283
     * <p>The default implementation converts each path to a file and calls
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   284
     * {@link #getJavaFileObjectsFromFiles getJavaObjectsFromFiles}.
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   285
     * IllegalArgumentException will be thrown if any of the paths
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   286
     * cannot be converted to a file.</p>
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   287
     *
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   288
     * @param location a location
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   289
     * @param paths a list of paths, if {@code null} use the default
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   290
     * search path for this location
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   291
     * @see #getLocation
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   292
     * @throws IllegalArgumentException if {@code location} is an output
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   293
     * location and {@code paths} does not contain exactly one element
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   294
     * or if this file manager does not support any of the given paths
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   295
     * @throws IOException if {@code location} is an output location and
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   296
     * {@code paths} does not represent an existing directory
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   297
     *
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   298
     * @since 1.9
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   299
     */
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   300
    default void setLocationFromPaths(Location location, Iterable<? extends Path> paths)
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   301
        throws IOException {
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   302
        setLocation(location, asFiles(paths));
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   303
    }
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   304
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   305
    /**
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   306
     * Returns the search path associated with the given location.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
     * @param location a location
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
     * @return a list of files or {@code null} if this location has no
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   310
     * associated search path
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   311
     * @throws IllegalStateException if any element of the search path
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   312
     * cannot be converted to a {@linkplain File}.
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   313
     *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
     * @see #setLocation
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   315
     * @see Path#toFile
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
    Iterable<? extends File> getLocation(Location location);
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   319
    /**
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   320
     * Returns the search path associated with the given location.
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   321
     *
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   322
     * @param location a location
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   323
     * @return a list of paths or {@code null} if this location has no
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   324
     * associated search path
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   325
     *
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   326
     * @see #setLocationFromPaths
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   327
     * @since 1.9
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   328
     */
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   329
    default Iterable<? extends Path> getLocationAsPaths(Location location) {
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   330
        return asPaths(getLocation(location));
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   331
    }
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   333
    /**
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   334
     * Returns the path, if any, underlying this file object (optional operation).
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   335
     * File objects derived from a {@link java.nio.file.FileSystem FileSystem},
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   336
     * including the default file system, typically have a corresponding underlying
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   337
     * {@link java.nio.file.Path Path} object. In such cases, this method may be
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   338
     * used to access that object.
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   339
     *
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   340
     * <p>The default implementation throws {@link UnsupportedOperationException}
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   341
     * for all files.</p>
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   342
     *
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   343
     * @param file a file object
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   344
     * @return a path representing the same underlying file system artifact
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   345
     * @throws IllegalArgumentException if the file object does not have an underlying path
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   346
     * @throws UnsupportedOperationException if the operation is not supported by this file manager
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   347
     *
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   348
     * @since 1.9
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   349
     */
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   350
    default Path asPath(FileObject file) {
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   351
        throw new UnsupportedOperationException();
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   352
    }
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   353
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
}