langtools/src/share/classes/javax/tools/JavaCompiler.java
author jjg
Thu, 13 Sep 2012 14:29:36 -0700
changeset 13844 56339cf983a3
parent 10454 9d5584396849
child 14545 2e7bab0639b8
permissions -rw-r--r--
7177970: fix issues in langtools doc comments Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 10454
diff changeset
     2
 * Copyright (c) 2005, 2012, 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: 3659
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: 3659
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: 3659
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3659
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3659
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package javax.tools;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.io.File;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import java.io.Writer;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import java.nio.charset.Charset;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import java.util.Locale;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import java.util.concurrent.Callable;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import javax.annotation.processing.Processor;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 * Interface to invoke Java™ programming language compilers from
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 * programs.
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 * <p>The compiler might generate diagnostics during compilation (for
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 * example, error messages).  If a diagnostic listener is provided,
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 * the diagnostics will be supplied to the listener.  If no listener
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 * is provided, the diagnostics will be formatted in an unspecified
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 * format and written to the default output, which is {@code
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 * System.err} unless otherwise specified.  Even if a diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 * listener is supplied, some diagnostics might not fit in a {@code
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 * Diagnostic} and will be written to the default output.
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 * <p>A compiler tool has an associated standard file manager, which
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 * is the file manager that is native to the tool (or built-in).  The
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
 * standard file manager can be obtained by calling {@linkplain
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
 * #getStandardFileManager getStandardFileManager}.
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
 * <p>A compiler tool must function with any file manager as long as
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
 * any additional requirements as detailed in the methods below are
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
 * met.  If no file manager is provided, the compiler tool will use a
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
 * standard file manager such as the one returned by {@linkplain
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
 * #getStandardFileManager getStandardFileManager}.
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
 *
9303
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 8040
diff changeset
    59
 * <p>An instance implementing this interface must conform to
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 8040
diff changeset
    60
 * <cite>The Java&trade; Language Specification</cite>
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 8040
diff changeset
    61
 * and generate class files conforming to
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 8040
diff changeset
    62
 * <cite>The Java&trade; Virtual Machine Specification</cite>.
eae35c201e19 7032975: API files in javax.annotation.processing need to be updated for references to JLS
jjh
parents: 8040
diff changeset
    63
 * The versions of these
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
 * specifications are defined in the {@linkplain Tool} interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
 * Additionally, an instance of this interface supporting {@link
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
 * javax.lang.model.SourceVersion#RELEASE_6 SourceVersion.RELEASE_6}
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
 * or higher must also support {@linkplain javax.annotation.processing
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
 * annotation processing}.
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
 * <p>The compiler relies on two services: {@linkplain
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
 * DiagnosticListener diagnostic listener} and {@linkplain
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
 * JavaFileManager file manager}.  Although most classes and
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
 * interfaces in this package defines an API for compilers (and
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
 * tools in general) the interfaces {@linkplain DiagnosticListener},
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
 * {@linkplain JavaFileManager}, {@linkplain FileObject}, and
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
 * {@linkplain JavaFileObject} are not intended to be used in
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
 * applications.  Instead these interfaces are intended to be
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
 * implemented and used to provide customized services for a
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
 * compiler and thus defines an SPI for compilers.
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
 * <p>There are a number of classes and interfaces in this package
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
 * which are designed to ease the implementation of the SPI to
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
 * customize the behavior of a compiler:
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
 * <dl>
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
 *   <dt>{@link StandardJavaFileManager}</dt>
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
 *   <dd>
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
 *     Every compiler which implements this interface provides a
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
 *     standard file manager for operating on regular {@linkplain
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
 *     java.io.File files}.  The StandardJavaFileManager interface
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
 *     defines additional methods for creating file objects from
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
 *     regular files.
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
 *     <p>The standard file manager serves two purposes:
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
 *     <ul>
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
 *       <li>basic building block for customizing how a compiler reads
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
 *       and writes files</li>
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
 *       <li>sharing between multiple compilation tasks</li>
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
 *     </ul>
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
 *     <p>Reusing a file manager can potentially reduce overhead of
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
 *     scanning the file system and reading jar files.  Although there
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
 *     might be no reduction in overhead, a standard file manager must
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
 *     work with multiple sequential compilations making the following
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
 *     example a recommended coding pattern:
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
 *     <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
 *       Files[] files1 = ... ; // input for first compilation task
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
 *       Files[] files2 = ... ; // input for second compilation task
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
 *       JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
 *       StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
 *       {@code Iterable<? extends JavaFileObject>} compilationUnits1 =
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
 *           fileManager.getJavaFileObjectsFromFiles({@linkplain java.util.Arrays#asList Arrays.asList}(files1));
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
 *       compiler.getTask(null, fileManager, null, null, null, compilationUnits1).call();
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
 *       {@code Iterable<? extends JavaFileObject>} compilationUnits2 =
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
 *           fileManager.getJavaFileObjects(files2); // use alternative method
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
 *       // reuse the same file manager to allow caching of jar files
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
 *       compiler.getTask(null, fileManager, null, null, null, compilationUnits2).call();
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
 *       fileManager.close();</pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
 *   </dd>
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
 *   <dt>{@link DiagnosticCollector}</dt>
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
 *   <dd>
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
 *     Used to collect diagnostics in a list, for example:
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
 *     <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
 *       {@code Iterable<? extends JavaFileObject>} compilationUnits = ...;
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
 *       JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
 *       {@code DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();}
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
 *       StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
 *       compiler.getTask(null, fileManager, diagnostics, null, null, compilationUnits).call();
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
 *
13844
56339cf983a3 7177970: fix issues in langtools doc comments
jjg
parents: 10454
diff changeset
   140
 *       for ({@code Diagnostic<? extends JavaFileObject>} diagnostic : diagnostics.getDiagnostics())
8040
077371a998dd 6571165: Minor doc bugs in JavaCompiler.java
jjg
parents: 5520
diff changeset
   141
 *           System.out.format("Error on line %d in %s%n",
077371a998dd 6571165: Minor doc bugs in JavaCompiler.java
jjg
parents: 5520
diff changeset
   142
 *                             diagnostic.getLineNumber(),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
 *                             diagnostic.getSource().toUri());
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
 *       fileManager.close();</pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
 *   </dd>
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
 *   <dt>
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
 *     {@link ForwardingJavaFileManager}, {@link ForwardingFileObject}, and
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
 *     {@link ForwardingJavaFileObject}
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
 *   </dt>
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
 *   <dd>
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
 *     Subclassing is not available for overriding the behavior of a
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
 *     standard file manager as it is created by calling a method on a
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
 *     compiler, not by invoking a constructor.  Instead forwarding
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
 *     (or delegation) should be used.  These classes makes it easy to
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
 *     forward most calls to a given file manager or file object while
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
 *     allowing customizing behavior.  For example, consider how to
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
 *     log all calls to {@linkplain JavaFileManager#flush}:
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
 *     <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
 *       final {@linkplain java.util.logging.Logger Logger} logger = ...;
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
 *       {@code Iterable<? extends JavaFileObject>} compilationUnits = ...;
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
 *       JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
 *       StandardJavaFileManager stdFileManager = compiler.getStandardFileManager(null, null, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
 *       JavaFileManager fileManager = new ForwardingJavaFileManager(stdFileManager) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
 *           public void flush() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
 *               logger.entering(StandardJavaFileManager.class.getName(), "flush");
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
 *               super.flush();
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
 *               logger.exiting(StandardJavaFileManager.class.getName(), "flush");
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
 *           }
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
 *       };
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
 *       compiler.getTask(null, fileManager, null, null, null, compilationUnits).call();</pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
 *   </dd>
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
 *   <dt>{@link SimpleJavaFileObject}</dt>
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
 *   <dd>
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
 *     This class provides a basic file object implementation which
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
 *     can be used as building block for creating file objects.  For
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
 *     example, here is how to define a file object which represent
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
 *     source code stored in a string:
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
 *     <pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
 *       /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
 *        * A file object used to represent source coming from a string.
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
 *        {@code *}/
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
 *       public class JavaSourceFromString extends SimpleJavaFileObject {
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
 *           /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
 *            * The source code of this "file".
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
 *            {@code *}/
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
 *           final String code;
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
 *           /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
 *            * Constructs a new JavaSourceFromString.
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
 *            * {@code @}param name the name of the compilation unit represented by this file object
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
 *            * {@code @}param code the source code for the compilation unit represented by this file object
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
 *            {@code *}/
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
 *           JavaSourceFromString(String name, String code) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
 *               super({@linkplain java.net.URI#create URI.create}("string:///" + name.replace('.','/') + Kind.SOURCE.extension),
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
 *                     Kind.SOURCE);
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
 *               this.code = code;
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
 *           }
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
 *           {@code @}Override
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
 *           public CharSequence getCharContent(boolean ignoreEncodingErrors) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
 *               return code;
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
 *           }
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
 *       }</pre>
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
 *   </dd>
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
 * </dl>
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
 * @author Peter von der Ah&eacute;
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
 * @author Jonathan Gibbons
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
 * @see DiagnosticListener
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
 * @see Diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
 * @see JavaFileManager
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
 * @since 1.6
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
public interface JavaCompiler extends Tool, OptionChecker {
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
     * Creates a future for a compilation task with the given
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
     * components and arguments.  The compilation might not have
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
     * completed as described in the CompilationTask interface.
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
     * <p>If a file manager is provided, it must be able to handle all
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
     * locations defined in {@link StandardLocation}.
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
     *
3659
7c9f033e5232 6871291: Please clarify javax.tools.JavaCompiler.getTask() "classes" parameter
darcy
parents: 10
diff changeset
   231
     * <p>Note that annotation processing can process both the
7c9f033e5232 6871291: Please clarify javax.tools.JavaCompiler.getTask() "classes" parameter
darcy
parents: 10
diff changeset
   232
     * compilation units of source code to be compiled, passed with
7c9f033e5232 6871291: Please clarify javax.tools.JavaCompiler.getTask() "classes" parameter
darcy
parents: 10
diff changeset
   233
     * the {@code compilationUnits} parameter, as well as class
7c9f033e5232 6871291: Please clarify javax.tools.JavaCompiler.getTask() "classes" parameter
darcy
parents: 10
diff changeset
   234
     * files, whose names are passed with the {@code classes}
7c9f033e5232 6871291: Please clarify javax.tools.JavaCompiler.getTask() "classes" parameter
darcy
parents: 10
diff changeset
   235
     * parameter.
7c9f033e5232 6871291: Please clarify javax.tools.JavaCompiler.getTask() "classes" parameter
darcy
parents: 10
diff changeset
   236
     *
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
     * @param out a Writer for additional output from the compiler;
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
     * use {@code System.err} if {@code null}
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
     * @param fileManager a file manager; if {@code null} use the
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
     * compiler's standard filemanager
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
     * @param diagnosticListener a diagnostic listener; if {@code
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
     * null} use the compiler's default method for reporting
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
     * diagnostics
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
     * @param options compiler options, {@code null} means no options
3659
7c9f033e5232 6871291: Please clarify javax.tools.JavaCompiler.getTask() "classes" parameter
darcy
parents: 10
diff changeset
   245
     * @param classes names of classes to be processed by annotation
7c9f033e5232 6871291: Please clarify javax.tools.JavaCompiler.getTask() "classes" parameter
darcy
parents: 10
diff changeset
   246
     * processing, {@code null} means no class names
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
     * @param compilationUnits the compilation units to compile, {@code
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
     * null} means no compilation units
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
     * @return an object representing the compilation
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
     * @throws RuntimeException if an unrecoverable error
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
     * occurred in a user supplied component.  The
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
     * {@linkplain Throwable#getCause() cause} will be the error in
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
     * user code.
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
     * @throws IllegalArgumentException if any of the given
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
     * compilation units are of other kind than
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
     * {@linkplain JavaFileObject.Kind#SOURCE source}
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
    CompilationTask getTask(Writer out,
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
                            JavaFileManager fileManager,
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
                            DiagnosticListener<? super JavaFileObject> diagnosticListener,
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
                            Iterable<String> options,
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
                            Iterable<String> classes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
                            Iterable<? extends JavaFileObject> compilationUnits);
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
     * Gets a new instance of the standard file manager implementation
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
     * for this tool.  The file manager will use the given diagnostic
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
     * listener for producing any non-fatal diagnostics.  Fatal errors
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
     * will be signalled with the appropriate exceptions.
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
     * <p>The standard file manager will be automatically reopened if
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
     * it is accessed after calls to {@code flush} or {@code close}.
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
     * The standard file manager must be usable with other tools.
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
     * @param diagnosticListener a diagnostic listener for non-fatal
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
     * diagnostics; if {@code null} use the compiler's default method
06bc494ca11e Initial load
duke
parents:
diff changeset
   277
     * for reporting diagnostics
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
     * @param locale the locale to apply when formatting diagnostics;
06bc494ca11e Initial load
duke
parents:
diff changeset
   279
     * {@code null} means the {@linkplain Locale#getDefault() default locale}.
06bc494ca11e Initial load
duke
parents:
diff changeset
   280
     * @param charset the character set used for decoding bytes; if
06bc494ca11e Initial load
duke
parents:
diff changeset
   281
     * {@code null} use the platform default
06bc494ca11e Initial load
duke
parents:
diff changeset
   282
     * @return the standard file manager
06bc494ca11e Initial load
duke
parents:
diff changeset
   283
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   284
    StandardJavaFileManager getStandardFileManager(
06bc494ca11e Initial load
duke
parents:
diff changeset
   285
        DiagnosticListener<? super JavaFileObject> diagnosticListener,
06bc494ca11e Initial load
duke
parents:
diff changeset
   286
        Locale locale,
06bc494ca11e Initial load
duke
parents:
diff changeset
   287
        Charset charset);
06bc494ca11e Initial load
duke
parents:
diff changeset
   288
06bc494ca11e Initial load
duke
parents:
diff changeset
   289
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   290
     * Interface representing a future for a compilation task.  The
06bc494ca11e Initial load
duke
parents:
diff changeset
   291
     * compilation task has not yet started.  To start the task, call
06bc494ca11e Initial load
duke
parents:
diff changeset
   292
     * the {@linkplain #call call} method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
     *
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
     * <p>Before calling the call method, additional aspects of the
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
     * task can be configured, for example, by calling the
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
     * {@linkplain #setProcessors setProcessors} method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   298
    interface CompilationTask extends Callable<Boolean> {
06bc494ca11e Initial load
duke
parents:
diff changeset
   299
06bc494ca11e Initial load
duke
parents:
diff changeset
   300
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   301
         * Sets processors (for annotation processing).  This will
06bc494ca11e Initial load
duke
parents:
diff changeset
   302
         * bypass the normal discovery mechanism.
06bc494ca11e Initial load
duke
parents:
diff changeset
   303
         *
06bc494ca11e Initial load
duke
parents:
diff changeset
   304
         * @param processors processors (for annotation processing)
06bc494ca11e Initial load
duke
parents:
diff changeset
   305
         * @throws IllegalStateException if the task has started
06bc494ca11e Initial load
duke
parents:
diff changeset
   306
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   307
        void setProcessors(Iterable<? extends Processor> processors);
06bc494ca11e Initial load
duke
parents:
diff changeset
   308
06bc494ca11e Initial load
duke
parents:
diff changeset
   309
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   310
         * Set the locale to be applied when formatting diagnostics and
06bc494ca11e Initial load
duke
parents:
diff changeset
   311
         * other localized data.
06bc494ca11e Initial load
duke
parents:
diff changeset
   312
         *
06bc494ca11e Initial load
duke
parents:
diff changeset
   313
         * @param locale the locale to apply; {@code null} means apply no
06bc494ca11e Initial load
duke
parents:
diff changeset
   314
         * locale
06bc494ca11e Initial load
duke
parents:
diff changeset
   315
         * @throws IllegalStateException if the task has started
06bc494ca11e Initial load
duke
parents:
diff changeset
   316
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   317
        void setLocale(Locale locale);
06bc494ca11e Initial load
duke
parents:
diff changeset
   318
06bc494ca11e Initial load
duke
parents:
diff changeset
   319
        /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   320
         * Performs this compilation task.  The compilation may only
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
         * be performed once.  Subsequent calls to this method throw
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
         * IllegalStateException.
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
         *
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
         * @return true if and only all the files compiled without errors;
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
         * false otherwise
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
         *
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
         * @throws RuntimeException if an unrecoverable error occurred
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
         * in a user-supplied component.  The
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
         * {@linkplain Throwable#getCause() cause} will be the error
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
         * in user code.
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
         * @throws IllegalStateException if called more than once
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
         */
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
        Boolean call();
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
}