langtools/src/java.compiler/share/classes/javax/annotation/processing/Filer.java
author jlahoda
Tue, 14 Mar 2017 10:51:19 +0100
changeset 44291 e1b620ac6c98
parent 43567 d0d89c3da7be
permissions -rw-r--r--
8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile? Summary: Clarifications and improvements to jx.a.processing.Filer for creating and reading files in and from modules. Reviewed-by: darcy, jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
43567
d0d89c3da7be 8173676: Improvements to javax.annotation.processing and javax.lang.model doc
darcy
parents: 42815
diff changeset
     2
 * Copyright (c) 2005, 2017, 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: 2214
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: 2214
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: 2214
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2214
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 2214
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.annotation.processing;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import javax.tools.JavaFileManager;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import javax.tools.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import javax.lang.model.element.Element;
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
    31
import javax.lang.model.util.Elements;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import java.io.IOException;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 * This interface supports the creation of new files by an annotation
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 * processor.  Files created in this way will be known to the
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * annotation processing tool implementing this interface, better
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 * enabling the tool to manage them.  Source and class files so
2214
7a15129e2154 6501749: 6501749 Filer should state connection between created files and root elements
darcy
parents: 10
diff changeset
    39
 * created will be {@linkplain RoundEnvironment#getRootElements
7a15129e2154 6501749: 6501749 Filer should state connection between created files and root elements
darcy
parents: 10
diff changeset
    40
 * considered for processing} by the tool in a subsequent {@linkplain
7a15129e2154 6501749: 6501749 Filer should state connection between created files and root elements
darcy
parents: 10
diff changeset
    41
 * RoundEnvironment round of processing} after the {@code close}
7a15129e2154 6501749: 6501749 Filer should state connection between created files and root elements
darcy
parents: 10
diff changeset
    42
 * method has been called on the {@code Writer} or {@code
7a15129e2154 6501749: 6501749 Filer should state connection between created files and root elements
darcy
parents: 10
diff changeset
    43
 * OutputStream} used to write the contents of the file.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 * Three kinds of files are distinguished: source files, class files,
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 * and auxiliary resource files.
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 * <p> There are two distinguished supported locations (subtrees
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 * within the logical file system) where newly created files are
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 * placed: one for {@linkplain
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 * javax.tools.StandardLocation#SOURCE_OUTPUT new source files}, and
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 * one for {@linkplain javax.tools.StandardLocation#CLASS_OUTPUT new
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 * class files}.  (These might be specified on a tool's command line,
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 * for example, using flags such as {@code -s} and {@code -d}.)  The
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 * actual locations for new source files and new class files may or
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
 * may not be distinct on a particular run of the tool.  Resource
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
 * files may be created in either location.  The methods for reading
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
 * and writing resources take a relative name argument.  A relative
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
 * name is a non-null, non-empty sequence of path segments separated
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
 * by {@code '/'}; {@code '.'} and {@code '..'} are invalid path
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
 * segments.  A valid relative name must match the
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
 * &quot;path-rootless&quot; rule of <a
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
 * href="http://www.ietf.org/rfc/rfc3986.txt">RFC 3986</a>, section
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
 * 3.3.
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
 * <p>The file creation methods take a variable number of arguments to
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
 * allow the <em>originating elements</em> to be provided as hints to
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
 * the tool infrastructure to better manage dependencies.  The
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
 * originating elements are the types or packages (representing {@code
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
    70
 * package-info} files) or modules (representing {@code
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
    71
 * module-info} files) which caused an annotation processor to
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
 * attempt to create a new file.  For example, if an annotation
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
 * processor tries to create a source file, {@code
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
 * GeneratedFromUserSource}, in response to processing
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
 * <blockquote><pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
 *  &#64;Generate
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
 *  public class UserSource {}
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
 * </pre></blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
 * the type element for {@code UserSource} should be passed as part of
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
 * the creation method call as in:
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
 * <blockquote><pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
 *      filer.createSourceFile("GeneratedFromUserSource",
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
 *                             eltUtils.getTypeElement("UserSource"));
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
 * </pre></blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
 * If there are no originating elements, none need to be passed.  This
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
 * information may be used in an incremental environment to determine
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
 * the need to rerun processors or remove generated files.
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
 * Non-incremental environments may ignore the originating element
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
 * information.
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
 * <p> During each run of an annotation processing tool, a file with a
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
 * given pathname may be created only once.  If that file already
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
 * exists before the first attempt to create it, the old contents will
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
 * be deleted.  Any subsequent attempt to create the same file during
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
 * a run will throw a {@link FilerException}, as will attempting to
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
 * create both a class file and source file for the same type name or
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
 * same package name.  The {@linkplain Processor initial inputs} to
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
 * the tool are considered to be created by the zeroth round;
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
 * therefore, attempting to create a source or class file
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
 * corresponding to one of those inputs will result in a {@link
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
 * FilerException}.
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
 * <p> In general, processors must not knowingly attempt to overwrite
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
 * existing files that were not generated by some processor.  A {@code
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
 * Filer} may reject attempts to open a file corresponding to an
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
 * existing type, like {@code java.lang.Object}.  Likewise, the
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
 * invoker of the annotation processing tool must not knowingly
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
 * configure the tool such that the discovered processors will attempt
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
 * to overwrite existing files that were not generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
 * <p> Processors can indicate a source or class file is generated by
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   116
 * including a {@code javax.annotation.Generated} annotation if the
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   117
 * environment is configured so that that type is accessible.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
 *
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   119
 * @apiNote Some of the effect of overwriting a file can be
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
 * achieved by using a <i>decorator</i>-style pattern.  Instead of
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
 * modifying a class directly, the class is designed so that either
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
 * its superclass is generated by annotation processing or subclasses
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
 * of the class are generated by annotation processing.  If the
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
 * subclasses are generated, the parent class may be designed to use
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
 * factories instead of public constructors so that only subclass
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
 * instances would be presented to clients of the parent class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
 * @author Joseph D. Darcy
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
 * @author Scott Seligman
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
 * @author Peter von der Ah&eacute;
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
 * @since 1.6
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
public interface Filer {
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
     * Creates a new source file and returns an object to allow
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   136
     * writing to it. A source file for a type, or a package can
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   137
     * be created.
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   138
     *
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   139
     * The file's name and path (relative to the {@linkplain
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   140
     * StandardLocation#SOURCE_OUTPUT root output location for source
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   141
     * files}) are based on the name of the item to be declared in
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   142
     * that file as well as the specified module for the item (if
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   143
     * any).
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   144
     *
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   145
     * If more than one type is being declared in a single file (that
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   146
     * is, a single compilation unit), the name of the file should
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   147
     * correspond to the name of the principal top-level type (the
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   148
     * public one, for example).
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   149
     *
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   150
     * <p>A source file can also be created to hold information about
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   151
     * a package, including package annotations.  To create a source
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   152
     * file for a named package, have the {@code name} argument be the
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
     * package's name followed by {@code ".package-info"}; to create a
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
     * source file for an unnamed package, use {@code "package-info"}.
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
     *
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   156
     * <p>The optional module name is prefixed to the type name or
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   157
     * package name and separated using a "{@code /}" character. For
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   158
     * example, to create a source file for type {@code a.B} in module
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   159
     * {@code foo}, use a {@code name} argument of {@code "foo/a.B"}.
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   160
     *
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   161
     * <p>If no explicit module prefix is given and modules are supported
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   162
     * in the environment, a suitable module is inferred. If a suitable
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   163
     * module cannot be inferred {@link FilerException} is thrown.
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   164
     * An implementation may use information about the configuration of
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   165
     * the annotation processing tool as part of the inference.
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   166
     *
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   167
     * <p>Creating a source file in or for an unnamed package in a named
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   168
     * module is <em>not</em> supported.
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   169
     *
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   170
     * @apiNote To use a particular {@linkplain
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
     * java.nio.charset.Charset charset} to encode the contents of the
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
     * file, an {@code OutputStreamWriter} with the chosen charset can
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
     * be created from the {@code OutputStream} from the returned
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
     * object. If the {@code Writer} from the returned object is
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
     * directly used for writing, its charset is determined by the
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
     * implementation.  An annotation processing tool may have an
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
     * {@code -encoding} flag or analogous option for specifying this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
     * otherwise, it will typically be the platform's default
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
     * encoding.
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
     * <p>To avoid subsequent errors, the contents of the source file
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
     * should be compatible with the {@linkplain
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
     * ProcessingEnvironment#getSourceVersion source version} being used
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
     * for this run.
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
     *
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   186
     * @implNote In the reference implementation, if the annotation
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   187
     * processing tool is processing a single module <i>M</i>,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   188
     * then <i>M</i> is used as the module for files created without
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   189
     * an explicit module prefix. If the tool is processing multiple
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   190
     * modules, and {@link
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   191
     * Elements#getPackageElement(java.lang.CharSequence)
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   192
     * Elements.getPackageElement(package-of(name))}
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   193
     * returns a package, the module that owns the returned package is used
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   194
     * as the target module. A separate option may be used to provide the target
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   195
     * module if it cannot be determined using the above rules.
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   196
     *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
     * @param name  canonical (fully qualified) name of the principal type
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
     *          being declared in this file or a package name followed by
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
     *          {@code ".package-info"} for a package information file
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   200
     * @param originatingElements type or package or module elements causally
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
     * associated with the creation of this file, may be elided or
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
     * {@code null}
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
     * @return a {@code JavaFileObject} to write the new source file
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
     * @throws FilerException if the same pathname has already been
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   205
     * created, the same type has already been created, the name is
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   206
     * otherwise not valid for the entity requested to being created,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   207
     * if the target module cannot be determined, if the target
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   208
     * module is not writable, or a module is specified when the environment
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   209
     * doesn't support modules.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
     * @throws IOException if the file cannot be created
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   211
     * @jls 7.3 Compilation Units
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
    JavaFileObject createSourceFile(CharSequence name,
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
                                    Element... originatingElements) throws IOException;
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
     * Creates a new class file, and returns an object to allow
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   218
     * writing to it. A class file for a type, or a package can
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   219
     * be created.
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   220
     *
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   221
     * The file's name and path (relative to the {@linkplain
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   222
     * StandardLocation#CLASS_OUTPUT root output location for class
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   223
     * files}) are based on the name of the item to be declared as
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   224
     * well as the specified module for the item (if any).
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   225
     *
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   226
     * <p>A class file can also be created to hold information about a
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   227
     * package, including package annotations. To create a class file
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   228
     * for a named package, have the {@code name} argument be the
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
     * package's name followed by {@code ".package-info"}; creating a
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
     * class file for an unnamed package is not supported.
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
     *
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   232
     * <p>The optional module name is prefixed to the type name or
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   233
     * package name and separated using a "{@code /}" character. For
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   234
     * example, to create a class file for type {@code a.B} in module
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   235
     * {@code foo}, use a {@code name} argument of {@code "foo/a.B"}.
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   236
     *
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   237
     * <p>If no explicit module prefix is given and modules are supported
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   238
     * in the environment, a suitable module is inferred. If a suitable
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   239
     * module cannot be inferred {@link FilerException} is thrown.
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   240
     * An implementation may use information about the configuration of
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   241
     * the annotation processing tool as part of the inference.
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   242
     *
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   243
     * <p>Creating a class file in or for an unnamed package in a named
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   244
     * module is <em>not</em> supported.
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   245
     *
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   246
     * @apiNote To avoid subsequent errors, the contents of the class
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   247
     * file should be compatible with the {@linkplain
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   248
     * ProcessingEnvironment#getSourceVersion source version} being
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   249
     * used for this run.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
     *
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   251
     * @implNote In the reference implementation, if the annotation
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   252
     * processing tool is processing a single module <i>M</i>,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   253
     * then <i>M</i> is used as the module for files created without
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   254
     * an explicit module prefix. If the tool is processing multiple
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   255
     * modules, and {@link
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   256
     * Elements#getPackageElement(java.lang.CharSequence)
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   257
     * Elements.getPackageElement(package-of(name))}
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   258
     * returns a package, the module that owns the returned package is used
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   259
     * as the target module. A separate option may be used to provide the target
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   260
     * module if it cannot be determined using the above rules.
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   261
     *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
     * @param name binary name of the type being written or a package name followed by
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
     *          {@code ".package-info"} for a package information file
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   264
     * @param originatingElements type or package or module elements causally
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
     * associated with the creation of this file, may be elided or
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
     * {@code null}
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
     * @return a {@code JavaFileObject} to write the new class file
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
     * @throws FilerException if the same pathname has already been
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   269
     * created, the same type has already been created, the name is
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   270
     * not valid for a type, if the target module cannot be determined,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   271
     * if the target module is not writable, or a module is specified when
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   272
     * the environment doesn't support modules.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
     * @throws IOException if the file cannot be created
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
    JavaFileObject createClassFile(CharSequence name,
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
                                   Element... originatingElements) throws IOException;
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
     * Creates a new auxiliary resource file for writing and returns a
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
     * file object for it.  The file may be located along with the
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
     * newly created source files, newly created binary files, or
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
     * other supported location.  The locations {@link
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
     * StandardLocation#CLASS_OUTPUT CLASS_OUTPUT} and {@link
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
     * StandardLocation#SOURCE_OUTPUT SOURCE_OUTPUT} must be
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   285
     * supported. The resource may be named relative to some module
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   286
     * and/or package (as are source and class files), and from there
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   287
     * by a relative pathname.  In a loose sense, the full pathname of
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   288
     * the new file will be the concatenation of {@code location},
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   289
     * {@code moduleAndPkg}, and {@code relativeName}.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
     *
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   291
     * If {@code moduleAndPkg} contains a "{@code /}" character, the
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   292
     * prefix before the "{@code /}" character is the module name and
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   293
     * the suffix after the "{@code /}" character is the package
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   294
     * name. The package suffix may be empty. If {@code moduleAndPkg}
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   295
     * does not contain a "{@code /}" character, the entire argument
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   296
     * is interpreted as a package name.
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   297
     *
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   298
     * <p>If the given location is neither a {@linkplain
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   299
     * JavaFileManager.Location#isModuleOrientedLocation()
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   300
     * module oriented location}, nor an {@linkplain
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   301
     * JavaFileManager.Location#isOutputLocation()
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   302
     * output location containing multiple modules}, and the explicit
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   303
     * module prefix is given, {@link FilerException} is thrown.
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   304
     *
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   305
     * <p>If the given location is either a module oriented location,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   306
     * or an output location containing multiple modules, and no explicit
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   307
     * modules prefix is given, a suitable module is
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   308
     * inferred. If a suitable module cannot be inferred {@link
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   309
     * FilerException} is thrown. An implementation may use information
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   310
     * about the configuration of the annotation processing tool
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   311
     * as part of the inference.
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   312
     *
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   313
     * <p>Files created via this method are <em>not</em> registered for
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
     * annotation processing, even if the full pathname of the file
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
     * would correspond to the full pathname of a new source file
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
     * or new class file.
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
     *
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   318
     * @implNote In the reference implementation, if the annotation
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   319
     * processing tool is processing a single module <i>M</i>,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   320
     * then <i>M</i> is used as the module for files created without
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   321
     * an explicit module prefix. If the tool is processing multiple
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   322
     * modules, and {@link
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   323
     * Elements#getPackageElement(java.lang.CharSequence)
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   324
     * Elements.getPackageElement(package-of(name))}
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   325
     * returns a package, the module that owns the returned package is used
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   326
     * as the target module. A separate option may be used to provide the target
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   327
     * module if it cannot be determined using the above rules.
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   328
     *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
     * @param location location of the new file
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   330
     * @param moduleAndPkg module and/or package relative to which the file
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   331
     *           should be named, or the empty string if none
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
     * @param relativeName final pathname components of the file
43567
d0d89c3da7be 8173676: Improvements to javax.annotation.processing and javax.lang.model doc
darcy
parents: 42815
diff changeset
   333
     * @param originatingElements type or package or module elements causally
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
     * associated with the creation of this file, may be elided or
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
     * {@code null}
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
     * @return a {@code FileObject} to write the new resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
     * @throws IOException if the file cannot be created
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
     * @throws FilerException if the same pathname has already been
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   339
     * created, if the target module cannot be determined,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   340
     * or if the target module is not writable, or if an explicit
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   341
     * target module is specified and the location does not support it.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
     * @throws IllegalArgumentException for an unsupported location
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   343
     * @throws IllegalArgumentException if {@code moduleAndPkg} is ill-formed
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
     * @throws IllegalArgumentException if {@code relativeName} is not relative
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
   FileObject createResource(JavaFileManager.Location location,
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   347
                             CharSequence moduleAndPkg,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
                             CharSequence relativeName,
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
                             Element... originatingElements) throws IOException;
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
     * Returns an object for reading an existing resource.  The
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
     * locations {@link StandardLocation#CLASS_OUTPUT CLASS_OUTPUT}
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
     * and {@link StandardLocation#SOURCE_OUTPUT SOURCE_OUTPUT} must
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
     * be supported.
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
     *
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   357
     * <p>If {@code moduleAndPkg} contains a "{@code /}" character, the
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   358
     * prefix before the "{@code /}" character is the module name and
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   359
     * the suffix after the "{@code /}" character is the package
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   360
     * name. The package suffix may be empty; however, if a module
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   361
     * name is present, it must be nonempty. If {@code moduleAndPkg}
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   362
     * does not contain a "{@code /}" character, the entire argument
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   363
     * is interpreted as a package name.
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   364
     *
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   365
     * <p>If the given location is neither a {@linkplain
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   366
     * JavaFileManager.Location#isModuleOrientedLocation()
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   367
     * module oriented location}, nor an {@linkplain
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   368
     * JavaFileManager.Location#isOutputLocation()
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   369
     * output location containing multiple modules}, and the explicit
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   370
     * module prefix is given, {@link FilerException} is thrown.
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   371
     *
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   372
     * <p>If the given location is either a module oriented location,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   373
     * or an output location containing multiple modules, and no explicit
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   374
     * modules prefix is given, a suitable module is
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   375
     * inferred. If a suitable module cannot be inferred {@link
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   376
     * FilerException} is thrown. An implementation may use information
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   377
     * about the configuration of the annotation processing tool
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   378
     * as part of the inference.
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   379
     *
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   380
     * @implNote In the reference implementation, if the annotation
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   381
     * processing tool is processing a single module <i>M</i>,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   382
     * then <i>M</i> is used as the module for files read without
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   383
     * an explicit module prefix. If the tool is processing multiple
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   384
     * modules, and {@link
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   385
     * Elements#getPackageElement(java.lang.CharSequence)
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   386
     * Elements.getPackageElement(package-of(name))}
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   387
     * returns a package, the module that owns the returned package is used
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   388
     * as the source module. A separate option may be used to provide the target
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   389
     * module if it cannot be determined using the above rules.
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   390
     *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
     * @param location location of the file
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   392
     * @param moduleAndPkg module and/or package relative to which the file
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   393
     *          should be searched for, or the empty string if none
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
     * @param relativeName final pathname components of the file
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
     * @return an object to read the file
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
     * @throws FilerException if the same pathname has already been
44291
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   397
     * opened for writing, if the source module cannot be determined,
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   398
     * or if the target module is not writable, or if an explicit target
e1b620ac6c98 8175119: Need to specify module of types created by Filer.createSourceFile/Filer.createClassFile?
jlahoda
parents: 43567
diff changeset
   399
     * module is specified and the location does not support it.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
     * @throws IOException if the file cannot be opened
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
     * @throws IllegalArgumentException for an unsupported location
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   402
     * @throws IllegalArgumentException if {@code moduleAndPkg} is ill-formed
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
     * @throws IllegalArgumentException if {@code relativeName} is not relative
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
    FileObject getResource(JavaFileManager.Location location,
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   406
                           CharSequence moduleAndPkg,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
                           CharSequence relativeName) throws IOException;
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
}