src/java.compiler/share/classes/javax/tools/StandardJavaFileManager.java
author naoto
Fri, 16 Feb 2018 14:03:34 -0800
changeset 48910 67cdc215ed70
parent 48456 b51755ee57f6
child 54298 6207397a6603
permissions -rw-r--r--
8198228: Spec clarification: j.u.Locale.getDisplayName() Reviewed-by: rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
48456
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
     2
 * Copyright (c) 2006, 2018, 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;
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
    32
import java.util.Collection;
48456
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
    33
import java.util.Iterator;
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
 *
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   144
 *
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   145
 * @apiNote
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   146
 * Some methods on this interface take a {@code Collection<? extends Path>}
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   147
 * instead of {@code Iterable<? extends Path>}.
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   148
 * This is to prevent the possibility of accidentally calling the method
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   149
 * with a single {@code Path} as such an argument, because although
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   150
 * {@code Path} implements {@code Iterable<Path>}, it would almost never be
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   151
 * correct to call these methods with a single {@code Path} and have it be treated as
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   152
 * an {@code Iterable} of its components.
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   153
 *
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   154
 *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
 * @author Peter von der Ah&eacute;
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
 * @since 1.6
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
public interface StandardJavaFileManager extends JavaFileManager {
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
     * Compares two file objects and return true if they represent the
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
     * same canonical file, zip file entry, or entry in any file
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
     * system based container.
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
     * @param a a file object
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
     * @param b a file object
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
     * @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
   168
     * canonical file, zip file entry or path; false otherwise
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     * @throws IllegalArgumentException if either of the arguments
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
     * were created with another file manager implementation
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
     */
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   173
    @Override
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
    boolean isSameFile(FileObject a, FileObject b);
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 5520
diff changeset
   177
     * Returns file objects representing the given files.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
     * @param files a list of files
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
     * @return a list of file objects
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
     * @throws IllegalArgumentException if the list of files includes
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
     * a directory
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles(
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
        Iterable<? extends File> files);
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
    /**
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   188
     * Returns file objects representing the given paths.
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   189
     *
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   190
     * @implSpec
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   191
     * The default implementation converts each path to a file and calls
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   192
     * {@link #getJavaFileObjectsFromFiles getJavaObjectsFromFiles}.
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   193
     * IllegalArgumentException will be thrown if any of the paths
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   194
     * cannot be converted to a file.
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
     * @param paths a list of paths
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   197
     * @return a list of file objects
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   198
     * @throws IllegalArgumentException if the list of paths includes
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   199
     * 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
   200
     * given paths.
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   201
     *
34912
954fa9df99c7 8146572: Update "@since 1.9" to "@since 9" to match java.version.specification [langtools]
jjg
parents: 28332
diff changeset
   202
     * @since 9
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   203
     */
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   204
    default Iterable<? extends JavaFileObject> getJavaFileObjectsFromPaths(
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   205
            Iterable<? extends Path> paths) {
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   206
        return getJavaFileObjectsFromFiles(asFiles(paths));
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   207
    }
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   208
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   209
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 5520
diff changeset
   210
     * Returns file objects representing the given files.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
     * Convenience method equivalent to:
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
     * <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
     *     getJavaFileObjectsFromFiles({@linkplain java.util.Arrays#asList Arrays.asList}(files))
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
     * </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
     * @param files an array of files
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
     * @return a list of file objects
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
     * @throws IllegalArgumentException if the array of files includes
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
     * a directory
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
     * @throws NullPointerException if the given array contains null
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
     * elements
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
    Iterable<? extends JavaFileObject> getJavaFileObjects(File... files);
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
    /**
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   227
     * Returns file objects representing the given paths.
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   228
     * Convenience method equivalent to:
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   229
     *
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   230
     * <pre>
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   231
     *     getJavaFileObjectsFromPaths({@linkplain java.util.Arrays#asList Arrays.asList}(paths))
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   232
     * </pre>
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
     * @param paths an array of paths
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   235
     * @return a list of file objects
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   236
     * @throws IllegalArgumentException if the array of files includes
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   237
     * a directory
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   238
     * @throws NullPointerException if the given array contains null
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   239
     * elements
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   240
     *
34912
954fa9df99c7 8146572: Update "@since 1.9" to "@since 9" to match java.version.specification [langtools]
jjg
parents: 28332
diff changeset
   241
     * @since 9
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   242
     */
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   243
    default Iterable<? extends JavaFileObject> getJavaFileObjects(Path... paths) {
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   244
        return getJavaFileObjectsFromPaths(Arrays.asList(paths));
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   245
    }
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   246
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   247
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 5520
diff changeset
   248
     * Returns file objects representing the given file names.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
     * @param names a list of file names
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
     * @return a list of file objects
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
     * @throws IllegalArgumentException if the list of file names
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
     * includes a directory
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
    Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
        Iterable<String> names);
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
    /**
25287
d2440361b323 8046614: Fill in missing doc comments
jjg
parents: 5520
diff changeset
   259
     * Returns file objects representing the given file names.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
     * Convenience method equivalent to:
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
     * <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
     *     getJavaFileObjectsFromStrings({@linkplain java.util.Arrays#asList Arrays.asList}(names))
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
     * </pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
     * @param names a list of file names
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
     * @return a list of file objects
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
     * @throws IllegalArgumentException if the array of file names
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
     * includes a directory
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
     * @throws NullPointerException if the given array contains null
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
     * elements
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
    Iterable<? extends JavaFileObject> getJavaFileObjects(String... names);
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
    /**
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   276
     * Associates the given search path with the given location.  Any
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
     * previous value will be discarded.
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
     *
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   279
     * If the location is a module-oriented or output location, any module-specific
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   280
     * associations set up by {@linkplain #setLocationForModule setLocationForModule}
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   281
     * will be cancelled.
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   282
     *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
     * @param location a location
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   284
     * @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
   285
     * search path for this location
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
     * @see #getLocation
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   287
     * @throws IllegalArgumentException if {@code location} is an output
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   288
     * location and {@code files} does not contain exactly one element
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   289
     * @throws IOException if {@code location} is an output location and
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
     * does not represent an existing directory
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
     */
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   292
    void setLocation(Location location, Iterable<? extends File> files)
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
        throws IOException;
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
    /**
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   296
     * Associates the given search path with the given location.
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   297
     * Any previous value will be discarded.
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   298
     *
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   299
     * If the location is a module-oriented or output location, any module-specific
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   300
     * associations set up by {@linkplain #setLocationForModule setLocationForModule}
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   301
     * will be cancelled.
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   302
     *
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   303
     * @implSpec
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   304
     * The default implementation converts each path to a file and calls
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   305
     * {@link #getJavaFileObjectsFromFiles getJavaObjectsFromFiles}.
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   306
     * {@linkplain IllegalArgumentException IllegalArgumentException}
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   307
     * will be thrown if any of the paths cannot be converted to a file.
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   308
     *
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   309
     * @param location a location
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   310
     * @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
   311
     * search path for this location
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   312
     * @see #getLocation
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   313
     * @throws IllegalArgumentException if {@code location} is an output
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   314
     * location and {@code paths} does not contain exactly one element
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   315
     * 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
   316
     * @throws IOException if {@code location} is an output location and
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   317
     * {@code paths} does not represent an existing directory
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   318
     *
34912
954fa9df99c7 8146572: Update "@since 1.9" to "@since 9" to match java.version.specification [langtools]
jjg
parents: 28332
diff changeset
   319
     * @since 9
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   320
     */
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   321
    default void setLocationFromPaths(Location location, Collection<? extends Path> paths)
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   322
            throws IOException {
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   323
        setLocation(location, asFiles(paths));
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   324
    }
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
    /**
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   327
     * Associates the given search path with the given module and location,
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   328
     * which must be a module-oriented or output location.
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   329
     * Any previous value will be discarded.
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   330
     * This overrides any default association derived from the search path
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   331
     * associated with the location itself.
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   332
     *
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   333
     * All such module-specific associations will be cancelled if a
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   334
     * new search path is associated with the location by calling
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   335
     * {@linkplain #setLocation setLocation } or
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   336
     * {@linkplain #setLocationFromPaths setLocationFromPaths}.
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   337
     *
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   338
     * @throws IllegalStateException if the location is not a module-oriented
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   339
     *  or output location.
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   340
     * @throws UnsupportedOperationException if this operation is not supported by
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   341
     *  this file manager.
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   342
     * @throws IOException if {@code location} is an output location and
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   343
     * {@code paths} does not represent an existing directory
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   344
     *
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   345
     * @param location the location
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   346
     * @param moduleName the name of the module
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   347
     * @param paths the search path to associate with the location and module.
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   348
     *
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   349
     * @see setLocation
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   350
     * @see setLocationFromPaths
44197
380e1f22e460 8176492: @since value errors in java.compiler module
jjg
parents: 44019
diff changeset
   351
     *
380e1f22e460 8176492: @since value errors in java.compiler module
jjg
parents: 44019
diff changeset
   352
     * @since 9
44019
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   353
     */
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   354
    default void setLocationForModule(Location location, String moduleName,
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   355
            Collection<? extends Path> paths) throws IOException {
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   356
        throw new UnsupportedOperationException();
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   357
    }
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   358
284fa2ebd030 8173914: StandardJavaFileManager.setLocationForModule
jjg
parents: 37944
diff changeset
   359
    /**
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   360
     * Returns the search path associated with the given location.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
     * @param location a location
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
     * @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
   364
     * associated search path
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   365
     * @throws IllegalStateException if any element of the search path
44690
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44197
diff changeset
   366
     * cannot be converted to a {@linkplain File}, or if the search path
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44197
diff changeset
   367
     * cannot be represented as a simple series of files.
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   368
     *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
     * @see #setLocation
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   370
     * @see Path#toFile
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
    Iterable<? extends File> getLocation(Location location);
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   374
    /**
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   375
     * Returns the search path associated with the given location.
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   376
     *
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   377
     * @implSpec
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   378
     * The default implementation calls {@link #getLocation getLocation}
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   379
     * and then returns an {@code Iterable} formed by calling {@code toPath()}
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   380
     * on each {@code File} returned from {@code getLocation}.
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   381
     *
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   382
     * @param location a location
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   383
     * @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
   384
     * associated search path
44690
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44197
diff changeset
   385
     * @throws IllegalStateException if the search path cannot be represented
aec722d1b538 8178509: MODULE_SOURCE_PATH: Implement missing methods
jjg
parents: 44197
diff changeset
   386
     * as a simple series of paths.
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   387
     *
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   388
     * @see #setLocationFromPaths
34912
954fa9df99c7 8146572: Update "@since 1.9" to "@since 9" to match java.version.specification [langtools]
jjg
parents: 28332
diff changeset
   389
     * @since 9
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   390
     */
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   391
    default Iterable<? extends Path> getLocationAsPaths(Location location) {
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   392
        return asPaths(getLocation(location));
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   393
    }
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   394
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   395
    /**
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   396
     * 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
   397
     * 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
   398
     * including the default file system, typically have a corresponding underlying
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   399
     * {@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
   400
     * used to access that object.
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   401
     *
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   402
     * @implSpec
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   403
     * The default implementation throws {@link UnsupportedOperationException}
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   404
     * for all files.
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   405
     *
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   406
     * @param file a file object
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   407
     * @return a path representing the same underlying file system artifact
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   408
     * @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
   409
     * @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
   410
     *
34912
954fa9df99c7 8146572: Update "@since 1.9" to "@since 9" to match java.version.specification [langtools]
jjg
parents: 28332
diff changeset
   411
     * @since 9
28332
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   412
     */
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   413
    default Path asPath(FileObject file) {
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   414
        throw new UnsupportedOperationException();
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   415
    }
cd3ea1087d2b 8059977: StandardJavaFileManager should support java.nio.file.Path
jjg
parents: 25874
diff changeset
   416
37944
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   417
    /**
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   418
     * Factory to create {@code Path} objects from strings.
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   419
     *
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   420
     * @since 9
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   421
     */
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   422
    interface PathFactory {
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   423
        /**
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   424
         * Converts a path string, or a sequence of strings that when joined form a path string, to a Path.
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   425
         *
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   426
         * @param first  the path string or initial part of the path string
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   427
         * @param more   additional strings to be joined to form the path string
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   428
         * @return       the resulting {@code Path}
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   429
         */
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   430
        Path getPath(String first, String... more);
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   431
    }
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   432
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   433
     /**
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   434
      * Specify a factory that can be used to generate a path from a string, or series of strings.
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   435
      *
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   436
      * If this method is not called, a factory whose {@code getPath} method is
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   437
      * equivalent to calling
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   438
      * {@link java.nio.file.Paths#get(String, String...) java.nio.file.Paths.get(first, more)}
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   439
      * will be used.
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   440
      *
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   441
      * @implSpec
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   442
      * The default implementation of this method ignores the factory that is provided.
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   443
      *
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   444
      * @param f  the factory
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   445
      *
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   446
      * @since 9
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   447
      */
1153fab98d25 8149843: StandardJavaFileManager should provide a way to get paths from strings
jjg
parents: 34912
diff changeset
   448
    default void setPathFactory(PathFactory f) { }
48456
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   449
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   450
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   451
    private static Iterable<Path> asPaths(final Iterable<? extends File> files) {
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   452
        return () -> new Iterator<Path>() {
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   453
            Iterator<? extends File> iter = files.iterator();
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   454
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   455
            @Override
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   456
            public boolean hasNext() {
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   457
                return iter.hasNext();
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   458
            }
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   459
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   460
            @Override
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   461
            public Path next() {
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   462
                return iter.next().toPath();
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   463
            }
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   464
        };
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   465
    }
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   466
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   467
    private static Iterable<File> asFiles(final Iterable<? extends Path> paths) {
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   468
        return () -> new Iterator<File>() {
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   469
            Iterator<? extends Path> iter = paths.iterator();
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   470
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   471
            @Override
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   472
            public boolean hasNext() {
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   473
                return iter.hasNext();
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   474
            }
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   475
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   476
            @Override
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   477
            public File next() {
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   478
                Path p = iter.next();
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   479
                try {
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   480
                    return p.toFile();
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   481
                } catch (UnsupportedOperationException e) {
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   482
                    throw new IllegalArgumentException(p.toString(), e);
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   483
                }
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   484
            }
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   485
        };
b51755ee57f6 8151850: eliminate javax.tools.FileManagerUtils
jjg
parents: 47216
diff changeset
   486
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
}