langtools/src/java.compiler/share/classes/javax/annotation/processing/Filer.java
author jlahoda
Tue, 13 Dec 2016 10:49:28 +0100
changeset 42815 050370edaade
parent 25874 83c19f00452c
child 43567 d0d89c3da7be
permissions -rw-r--r--
8072988: Update javax.annotation.processing for modules Summary: Support for generating files in multi-module mode. Reviewed-by: darcy, jjg Contributed-by: joe.darcy@oracle.com, jan.lahoda@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
     2
 * Copyright (c) 2005, 2016, 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;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import java.io.IOException;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
 * This interface supports the creation of new files by an annotation
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 * processor.  Files created in this way will be known to the
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 * annotation processing tool implementing this interface, better
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * 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
    38
 * created will be {@linkplain RoundEnvironment#getRootElements
7a15129e2154 6501749: 6501749 Filer should state connection between created files and root elements
darcy
parents: 10
diff changeset
    39
 * 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
    40
 * 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
    41
 * 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
    42
 * OutputStream} used to write the contents of the file.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * Three kinds of files are distinguished: source files, class files,
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 * and auxiliary resource files.
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 * <p> There are two distinguished supported locations (subtrees
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 * within the logical file system) where newly created files are
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 * placed: one for {@linkplain
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 * javax.tools.StandardLocation#SOURCE_OUTPUT new source files}, and
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 * one for {@linkplain javax.tools.StandardLocation#CLASS_OUTPUT new
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 * class files}.  (These might be specified on a tool's command line,
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 * for example, using flags such as {@code -s} and {@code -d}.)  The
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 * actual locations for new source files and new class files may or
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 * may not be distinct on a particular run of the tool.  Resource
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
 * files may be created in either location.  The methods for reading
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
 * and writing resources take a relative name argument.  A relative
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
 * name is a non-null, non-empty sequence of path segments separated
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
 * by {@code '/'}; {@code '.'} and {@code '..'} are invalid path
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
 * segments.  A valid relative name must match the
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
 * &quot;path-rootless&quot; rule of <a
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
 * href="http://www.ietf.org/rfc/rfc3986.txt">RFC 3986</a>, section
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
 * 3.3.
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
 * <p>The file creation methods take a variable number of arguments to
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
 * allow the <em>originating elements</em> to be provided as hints to
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
 * the tool infrastructure to better manage dependencies.  The
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
 * originating elements are the types or packages (representing {@code
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
    69
 * package-info} files) or modules (representing {@code
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
    70
 * module-info} files) which caused an annotation processor to
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
 * attempt to create a new file.  For example, if an annotation
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
 * processor tries to create a source file, {@code
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
 * GeneratedFromUserSource}, in response to processing
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
 * <blockquote><pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
 *  &#64;Generate
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
 *  public class UserSource {}
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
 * </pre></blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
 * the type element for {@code UserSource} should be passed as part of
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
 * the creation method call as in:
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
 * <blockquote><pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
 *      filer.createSourceFile("GeneratedFromUserSource",
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
 *                             eltUtils.getTypeElement("UserSource"));
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
 * </pre></blockquote>
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
 * If there are no originating elements, none need to be passed.  This
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
 * information may be used in an incremental environment to determine
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
 * the need to rerun processors or remove generated files.
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
 * Non-incremental environments may ignore the originating element
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
 * information.
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
 * <p> During each run of an annotation processing tool, a file with a
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
 * given pathname may be created only once.  If that file already
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
 * exists before the first attempt to create it, the old contents will
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
 * be deleted.  Any subsequent attempt to create the same file during
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
 * a run will throw a {@link FilerException}, as will attempting to
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
 * create both a class file and source file for the same type name or
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
 * same package name.  The {@linkplain Processor initial inputs} to
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
 * the tool are considered to be created by the zeroth round;
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
 * therefore, attempting to create a source or class file
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
 * corresponding to one of those inputs will result in a {@link
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
 * FilerException}.
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
 * <p> In general, processors must not knowingly attempt to overwrite
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
 * existing files that were not generated by some processor.  A {@code
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
 * Filer} may reject attempts to open a file corresponding to an
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
 * existing type, like {@code java.lang.Object}.  Likewise, the
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
 * invoker of the annotation processing tool must not knowingly
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
 * configure the tool such that the discovered processors will attempt
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
 * to overwrite existing files that were not generated.
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
 * <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
   115
 * including a {@code javax.annotation.Generated} annotation if the
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   116
 * environment is configured so that that type is accessible.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
 *
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   118
 * @apiNote Some of the effect of overwriting a file can be
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
 * achieved by using a <i>decorator</i>-style pattern.  Instead of
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
 * modifying a class directly, the class is designed so that either
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
 * its superclass is generated by annotation processing or subclasses
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
 * of the class are generated by annotation processing.  If the
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
 * subclasses are generated, the parent class may be designed to use
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
 * factories instead of public constructors so that only subclass
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
 * instances would be presented to clients of the parent class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
 * @author Joseph D. Darcy
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
 * @author Scott Seligman
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
 * @author Peter von der Ah&eacute;
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
 * @since 1.6
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
public interface Filer {
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
     * 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
   135
     * 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
   136
     * be created.
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   137
     *
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   138
     * The file's name and path (relative to the {@linkplain
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   139
     * StandardLocation#SOURCE_OUTPUT root output location for source
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   140
     * 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
   141
     * 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
   142
     * any).
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   143
     *
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   144
     * 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
   145
     * is, a single compilation unit), the name of the file should
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   146
     * correspond to the name of the principal top-level type (the
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   147
     * public one, for example).
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   148
     *
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   149
     * <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
   150
     * a package, including package annotations.  To create a source
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   151
     * file for a named package, have the {@code name} argument be the
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
     * package's name followed by {@code ".package-info"}; to create a
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
     * source file for an unnamed package, use {@code "package-info"}.
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
     *
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   155
     * <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
   156
     * package name and separated using a "{@code /}" character. For
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   157
     * 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
   158
     * {@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
   159
     *
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   160
     * <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
   161
     * module is <em>not</em> supported.
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   162
     *
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   163
     * @apiNote To use a particular {@linkplain
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
     * java.nio.charset.Charset charset} to encode the contents of the
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
     * file, an {@code OutputStreamWriter} with the chosen charset can
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
     * be created from the {@code OutputStream} from the returned
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
     * object. If the {@code Writer} from the returned object is
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
     * directly used for writing, its charset is determined by the
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
     * implementation.  An annotation processing tool may have an
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     * {@code -encoding} flag or analogous option for specifying this;
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
     * otherwise, it will typically be the platform's default
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
     * encoding.
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
     * <p>To avoid subsequent errors, the contents of the source file
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
     * should be compatible with the {@linkplain
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
     * ProcessingEnvironment#getSourceVersion source version} being used
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
     * for this run.
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
     * @param name  canonical (fully qualified) name of the principal type
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
     *          being declared in this file or a package name followed by
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
     *          {@code ".package-info"} for a package information file
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   182
     * @param originatingElements type or package or module elements causally
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
     * associated with the creation of this file, may be elided or
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
     * {@code null}
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
     * @return a {@code JavaFileObject} to write the new source file
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
     * @throws FilerException if the same pathname has already been
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
     * created, the same type has already been created, or the name is
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   188
     * otherwise not valid for the entity requested to being created
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
     * @throws IOException if the file cannot be created
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   190
     * @jls 7.3 Compilation Units
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
    JavaFileObject createSourceFile(CharSequence name,
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
                                    Element... originatingElements) throws IOException;
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
     * 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
   197
     * 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
   198
     * be created.
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   199
     *
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   200
     * The file's name and path (relative to the {@linkplain
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   201
     * StandardLocation#CLASS_OUTPUT root output location for class
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   202
     * 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
   203
     * well as the specified module for the item (if any).
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   204
     *
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   205
     * <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
   206
     * package, including package annotations. To create a class file
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   207
     * for a named package, have the {@code name} argument be the
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
     * package's name followed by {@code ".package-info"}; creating a
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
     * class file for an unnamed package is not supported.
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
     *
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   211
     * <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
   212
     * package name and separated using a "{@code /}" character. For
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   213
     * 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
   214
     * {@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
   215
     *
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   216
     * <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
   217
     * module is <em>not</em> supported.
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   218
     *
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   219
     * @apiNote To avoid subsequent errors, the contents of the class
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   220
     * file should be compatible with the {@linkplain
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   221
     * ProcessingEnvironment#getSourceVersion source version} being
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   222
     * used for this run.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
     * @param name binary name of the type being written or a package name followed by
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
     *          {@code ".package-info"} for a package information file
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   226
     * @param originatingElements type or package or module elements causally
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
     * associated with the creation of this file, may be elided or
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
     * {@code null}
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
     * @return a {@code JavaFileObject} to write the new class file
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
     * @throws FilerException if the same pathname has already been
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
     * created, the same type has already been created, or the name is
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
     * not valid for a type
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
     * @throws IOException if the file cannot be created
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
    JavaFileObject createClassFile(CharSequence name,
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
                                   Element... originatingElements) throws IOException;
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
     * Creates a new auxiliary resource file for writing and returns a
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
     * file object for it.  The file may be located along with the
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
     * newly created source files, newly created binary files, or
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
     * other supported location.  The locations {@link
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
     * StandardLocation#CLASS_OUTPUT CLASS_OUTPUT} and {@link
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
     * StandardLocation#SOURCE_OUTPUT SOURCE_OUTPUT} must be
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   245
     * supported. The resource may be named relative to some module
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   246
     * 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
   247
     * 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
   248
     * the new file will be the concatenation of {@code location},
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   249
     * {@code moduleAndPkg}, and {@code relativeName}.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
     *
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   251
     * If {@code moduleAndPkg} contains a "{@code /}" character, the
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   252
     * prefix before the "{@code /}" character is the module name and
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   253
     * the suffix after the "{@code /}" character is the package
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   254
     * name. The package suffix may be empty. If {@code moduleAndPkg}
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   255
     * does not contain a "{@code /}" character, the entire argument
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   256
     * is interpreted as a package name.
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   257
     *
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   258
     * <p>Files created via this method are <em>not</em> registered for
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
     * annotation processing, even if the full pathname of the file
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
     * would correspond to the full pathname of a new source file
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
     * or new class file.
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
     * @param location location of the new file
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   264
     * @param moduleAndPkg module and/or package relative to which the file
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   265
     *           should be named, or the empty string if none
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
     * @param relativeName final pathname components of the file
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
     * @param originatingElements type or package elements causally
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
     * associated with the creation of this file, may be elided or
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
     * {@code null}
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
     * @return a {@code FileObject} to write the new resource
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
     * @throws IOException if the file cannot be created
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
     * @throws FilerException if the same pathname has already been
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
     * created
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
     * @throws IllegalArgumentException for an unsupported location
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   275
     * @throws IllegalArgumentException if {@code moduleAndPkg} is ill-formed
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
     * @throws IllegalArgumentException if {@code relativeName} is not relative
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
   FileObject createResource(JavaFileManager.Location location,
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   279
                             CharSequence moduleAndPkg,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
                             CharSequence relativeName,
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
                             Element... originatingElements) throws IOException;
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
     * Returns an object for reading an existing resource.  The
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
     * locations {@link StandardLocation#CLASS_OUTPUT CLASS_OUTPUT}
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
     * and {@link StandardLocation#SOURCE_OUTPUT SOURCE_OUTPUT} must
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
     * be supported.
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
     *
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   289
     * <p>If {@code moduleAndPkg} contains a "{@code /}" character, the
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   290
     * prefix before the "{@code /}" character is the module name and
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   291
     * the suffix after the "{@code /}" character is the package
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   292
     * name. The package suffix may be empty; however, if a module
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   293
     * name is present, it must be nonempty. If {@code moduleAndPkg}
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   294
     * does not contain a "{@code /}" character, the entire argument
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   295
     * is interpreted as a package name.
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   296
     *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
     * @param location location of the file
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   298
     * @param moduleAndPkg module and/or package relative to which the file
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   299
     *          should be searched for, or the empty string if none
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
     * @param relativeName final pathname components of the file
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
     * @return an object to read the file
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
     * @throws FilerException if the same pathname has already been
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
     * opened for writing
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
     * @throws IOException if the file cannot be opened
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
     * @throws IllegalArgumentException for an unsupported location
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   306
     * @throws IllegalArgumentException if {@code moduleAndPkg} is ill-formed
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
     * @throws IllegalArgumentException if {@code relativeName} is not relative
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
    FileObject getResource(JavaFileManager.Location location,
42815
050370edaade 8072988: Update javax.annotation.processing for modules
jlahoda
parents: 25874
diff changeset
   310
                           CharSequence moduleAndPkg,
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
                           CharSequence relativeName) throws IOException;
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
}