553N/A * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 553N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 553N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 553N/A * or visit www.oracle.com if you need additional information or have any 0N/A * This interface supports the creation of new files by an annotation 0N/A * processor. Files created in this way will be known to the 0N/A * annotation processing tool implementing this interface, better 0N/A * enabling the tool to manage them. Source and class files so 230N/A * created will be {@linkplain RoundEnvironment#getRootElements 230N/A * considered for processing} by the tool in a subsequent {@linkplain 230N/A * RoundEnvironment round of processing} after the {@code close} 230N/A * method has been called on the {@code Writer} or {@code 230N/A * OutputStream} used to write the contents of the file. 0N/A * Three kinds of files are distinguished: source files, class files, 0N/A * and auxiliary resource files. 0N/A * <p> There are two distinguished supported locations (subtrees 0N/A * within the logical file system) where newly created files are 0N/A * placed: one for {@linkplain 0N/A * javax.tools.StandardLocation#SOURCE_OUTPUT new source files}, and 0N/A * one for {@linkplain javax.tools.StandardLocation#CLASS_OUTPUT new 0N/A * class files}. (These might be specified on a tool's command line, 0N/A * for example, using flags such as {@code -s} and {@code -d}.) The 0N/A * actual locations for new source files and new class files may or 0N/A * may not be distinct on a particular run of the tool. Resource 0N/A * files may be created in either location. The methods for reading 0N/A * and writing resources take a relative name argument. A relative 0N/A * name is a non-null, non-empty sequence of path segments separated 0N/A * by {@code '/'}; {@code '.'} and {@code '..'} are invalid path 0N/A * segments. A valid relative name must match the 0N/A * "path-rootless" rule of <a 0N/A * <p>The file creation methods take a variable number of arguments to 0N/A * allow the <em>originating elements</em> to be provided as hints to 0N/A * the tool infrastructure to better manage dependencies. The 0N/A * originating elements are the types or packages (representing {@code 0N/A * package-info} files) which caused an annotation processor to 0N/A * attempt to create a new file. For example, if an annotation 0N/A * processor tries to create a source file, {@code 0N/A * GeneratedFromUserSource}, in response to processing 0N/A * public class UserSource {} 0N/A * </pre></blockquote> 0N/A * the type element for {@code UserSource} should be passed as part of 0N/A * the creation method call as in: 0N/A * filer.createSourceFile("GeneratedFromUserSource", 0N/A * eltUtils.getTypeElement("UserSource")); 0N/A * </pre></blockquote> 0N/A * If there are no originating elements, none need to be passed. This 0N/A * information may be used in an incremental environment to determine 0N/A * the need to rerun processors or remove generated files. 0N/A * Non-incremental environments may ignore the originating element 0N/A * <p> During each run of an annotation processing tool, a file with a 0N/A * given pathname may be created only once. If that file already 0N/A * exists before the first attempt to create it, the old contents will 0N/A * be deleted. Any subsequent attempt to create the same file during 0N/A * a run will throw a {@link FilerException}, as will attempting to 0N/A * create both a class file and source file for the same type name or 0N/A * same package name. The {@linkplain Processor initial inputs} to 0N/A * the tool are considered to be created by the zeroth round; 0N/A * therefore, attempting to create a source or class file 0N/A * corresponding to one of those inputs will result in a {@link 0N/A * <p> In general, processors must not knowingly attempt to overwrite 0N/A * existing files that were not generated by some processor. A {@code 0N/A * Filer} may reject attempts to open a file corresponding to an 0N/A * existing type, like {@code java.lang.Object}. Likewise, the 0N/A * invoker of the annotation processing tool must not knowingly 0N/A * configure the tool such that the discovered processors will attempt 0N/A * to overwrite existing files that were not generated. 0N/A * <p> Processors can indicate a source or class file is generated by 0N/A * including an {@link javax.annotation.Generated @Generated} 0N/A * <p> Note that some of the effect of overwriting a file can be 0N/A * achieved by using a <i>decorator</i>-style pattern. Instead of 0N/A * modifying a class directly, the class is designed so that either 0N/A * its superclass is generated by annotation processing or subclasses 0N/A * of the class are generated by annotation processing. If the 0N/A * subclasses are generated, the parent class may be designed to use 0N/A * factories instead of public constructors so that only subclass 0N/A * instances would be presented to clients of the parent class. 0N/A * @author Joseph D. Darcy 0N/A * @author Scott Seligman 0N/A * @author Peter von der Ahé 0N/A * Creates a new source file and returns an object to allow 0N/A * writing to it. The file's name and path (relative to the 0N/A * {@linkplain StandardLocation#SOURCE_OUTPUT root output location 0N/A * for source files}) are based on the type to be declared in that 0N/A * file. If more than one type is being declared, the name of the 0N/A * principal top-level type (the public one, for example) should 0N/A * be used. A source file can also be created to hold information 0N/A * about a package, including package annotations. To create a 0N/A * source file for a named package, have {@code name} be the 0N/A * package's name followed by {@code ".package-info"}; to create a 0N/A * source file for an unnamed package, use {@code "package-info"}. 0N/A * <p> Note that to use a particular {@linkplain 0N/A * java.nio.charset.Charset charset} to encode the contents of the 0N/A * file, an {@code OutputStreamWriter} with the chosen charset can 0N/A * be created from the {@code OutputStream} from the returned 0N/A * object. If the {@code Writer} from the returned object is 0N/A * directly used for writing, its charset is determined by the 0N/A * implementation. An annotation processing tool may have an 0N/A * {@code -encoding} flag or analogous option for specifying this; 0N/A * otherwise, it will typically be the platform's default 0N/A * <p>To avoid subsequent errors, the contents of the source file 0N/A * should be compatible with the {@linkplain 0N/A * ProcessingEnvironment#getSourceVersion source version} being used 0N/A * @param name canonical (fully qualified) name of the principal type 0N/A * being declared in this file or a package name followed by 0N/A * {@code ".package-info"} for a package information file 0N/A * @param originatingElements type or package elements causally 0N/A * associated with the creation of this file, may be elided or 0N/A * @return a {@code JavaFileObject} to write the new source file 0N/A * @throws FilerException if the same pathname has already been 0N/A * created, the same type has already been created, or the name is 0N/A * not valid for a type 0N/A * @throws IOException if the file cannot be created 0N/A * Creates a new class file, and returns an object to allow 0N/A * writing to it. The file's name and path (relative to the 0N/A * {@linkplain StandardLocation#CLASS_OUTPUT root output location 0N/A * for class files}) are based on the name of the type being 0N/A * written. A class file can also be created to hold information 0N/A * about a package, including package annotations. To create a 0N/A * class file for a named package, have {@code name} be the 0N/A * package's name followed by {@code ".package-info"}; creating a 0N/A * class file for an unnamed package is not supported. 0N/A * <p>To avoid subsequent errors, the contents of the class file 0N/A * should be compatible with the {@linkplain 0N/A * ProcessingEnvironment#getSourceVersion source version} being used 0N/A * @param name binary name of the type being written or a package name followed by 0N/A * {@code ".package-info"} for a package information file 0N/A * @param originatingElements type or package elements causally 0N/A * associated with the creation of this file, may be elided or 0N/A * @return a {@code JavaFileObject} to write the new class file 0N/A * @throws FilerException if the same pathname has already been 0N/A * created, the same type has already been created, or the name is 0N/A * not valid for a type 0N/A * @throws IOException if the file cannot be created 0N/A * Creates a new auxiliary resource file for writing and returns a 0N/A * file object for it. The file may be located along with the 0N/A * newly created source files, newly created binary files, or 0N/A * other supported location. The locations {@link 0N/A * StandardLocation#CLASS_OUTPUT CLASS_OUTPUT} and {@link 0N/A * StandardLocation#SOURCE_OUTPUT SOURCE_OUTPUT} must be 0N/A * supported. The resource may be named relative to some package 0N/A * (as are source and class files), and from there by a relative 0N/A * pathname. In a loose sense, the full pathname of the new file 0N/A * will be the concatenation of {@code location}, {@code pkg}, and 0N/A * {@code relativeName}. 0N/A * <p>Files created via this method are not registered for 0N/A * annotation processing, even if the full pathname of the file 0N/A * would correspond to the full pathname of a new source file 0N/A * or new class file. 0N/A * @param location location of the new file 0N/A * @param pkg package relative to which the file should be named, 0N/A * or the empty string if none 0N/A * @param relativeName final pathname components of the file 0N/A * @param originatingElements type or package elements causally 0N/A * associated with the creation of this file, may be elided or 0N/A * @return a {@code FileObject} to write the new resource 0N/A * @throws IOException if the file cannot be created 0N/A * @throws FilerException if the same pathname has already been 0N/A * @throws IllegalArgumentException for an unsupported location 0N/A * @throws IllegalArgumentException if {@code relativeName} is not relative 0N/A * Returns an object for reading an existing resource. The 0N/A * locations {@link StandardLocation#CLASS_OUTPUT CLASS_OUTPUT} 0N/A * and {@link StandardLocation#SOURCE_OUTPUT SOURCE_OUTPUT} must 0N/A * @param location location of the file 0N/A * @param pkg package relative to which the file should be searched, 0N/A * or the empty string if none 0N/A * @param relativeName final pathname components of the file 0N/A * @return an object to read the file 0N/A * @throws FilerException if the same pathname has already been 0N/A * opened for writing 0N/A * @throws IOException if the file cannot be opened 0N/A * @throws IllegalArgumentException for an unsupported location 0N/A * @throws IllegalArgumentException if {@code relativeName} is not relative