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