langtools/src/share/classes/com/sun/mirror/apt/Filer.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 10 06bc494ca11e
child 3378 22011d9a9398
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
     2
 * Copyright 2004 Sun Microsystems, Inc.  All Rights Reserved.
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
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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 com.sun.mirror.apt;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.io.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
 * This interface supports the creation of new files by an
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
 * annotation processor.
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 * Files created in this way will be known to the annotation processing
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 * tool implementing this interface, better enabling the tool to manage them.
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * Four kinds of files are distinguished:
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 * source files, class files, other text files, and other binary files.
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 * The latter two are collectively referred to as <i>auxiliary</i> files.
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 * <p> There are two distinguished locations (subtrees within the
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 * file system) where newly created files are placed:
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 * one for new source files, and one for new class files.
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * (These might be specified on a tool's command line, for example,
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 * using flags such as <tt>-s</tt> and <tt>-d</tt>.)
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 * Auxiliary files may be created in either location.
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 * <p> During each run of an annotation processing tool, a file
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 * with a given pathname may be created only once.  If that file already
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 * exists before the first attempt to create it, the old contents will
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 * be deleted.  Any subsequent attempt to create the same file during
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 * a run will fail.
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 * @author Joseph D. Darcy
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 * @author Scott Seligman
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
 * @since 1.5
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
public interface Filer {
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
     * Creates a new source file and returns a writer for it.
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
     * The file's name and path (relative to the root of all newly created
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
     * source files) is based on the type to be declared in that file.
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
     * If more than one type is being declared, the name of the principal
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
     * top-level type (the public one, for example) should be used.
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
     * <p> The {@linkplain java.nio.charset.Charset charset} used to
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
     * encode the file is determined by the implementation.
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
     * An annotation processing tool may have an <tt>-encoding</tt>
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
     * flag or the like for specifying this.  It will typically use
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
     * the platform's default encoding if none is specified.
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
     * @param name  canonical (fully qualified) name of the principal type
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
     *          being declared in this file
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
     * @return a writer for the new file
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
     * @throws IOException if the file cannot be created
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
    PrintWriter createSourceFile(String name) throws IOException;
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
     * Creates a new class file, and returns a stream for writing to it.
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
     * The file's name and path (relative to the root of all newly created
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
     * class files) is based on the name of the type being written.
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
     * @param name canonical (fully qualified) name of the type being written
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
     * @return a stream for writing to the new file
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
     * @throws IOException if the file cannot be created
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    OutputStream createClassFile(String name) throws IOException;
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
     * Creates a new text file, and returns a writer for it.
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
     * The file is located along with either the
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
     * newly created source or newly created binary files.  It may be
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
     * named relative to some package (as are source and binary files),
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
     * and from there by an arbitrary pathname.  In a loose sense, the
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
     * pathname of the new file will be the concatenation of
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
     * <tt>loc</tt>, <tt>pkg</tt>, and <tt>relPath</tt>.
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
     * <p> A {@linkplain java.nio.charset.Charset charset} for
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
     * encoding the file may be provided.  If none is given, the
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
     * charset used to encode source files
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
     * (see {@link #createSourceFile(String)}) will be used.
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
     * @param loc location of the new file
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
     * @param pkg package relative to which the file should be named,
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
     *          or the empty string if none
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
     * @param relPath final pathname components of the file
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
     * @param charsetName the name of the charset to use, or null if none
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
     *          is being explicitly specified
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
     * @return a writer for the new file
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
     * @throws IOException if the file cannot be created
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    PrintWriter createTextFile(Location loc,
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
                               String pkg,
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
                               File relPath,
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
                               String charsetName) throws IOException;
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
     * Creates a new binary file, and returns a stream for writing to it.
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
     * The file is located along with either the
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
     * newly created source or newly created binary files.  It may be
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
     * named relative to some package (as are source and binary files),
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
     * and from there by an arbitrary pathname.  In a loose sense, the
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
     * pathname of the new file will be the concatenation of
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
     * <tt>loc</tt>, <tt>pkg</tt>, and <tt>relPath</tt>.
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
     * @param loc location of the new file
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     * @param pkg package relative to which the file should be named,
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
     *          or the empty string if none
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
     * @param relPath final pathname components of the file
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
     * @return a stream for writing to the new file
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
     * @throws IOException if the file cannot be created
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
    OutputStream createBinaryFile(Location loc,
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
                                  String pkg,
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
                                  File relPath) throws IOException;
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
     * Locations (subtrees within the file system) where new files are created.
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    enum Location {
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
        /** The location of new source files. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
        SOURCE_TREE,
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
        /** The location of new class files. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
        CLASS_TREE
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
}