1 /*
  2  * Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.  Oracle designates this
  8  * particular file as subject to the "Classpath" exception as provided
  9  * by Oracle in the LICENSE file that accompanied this code.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  */
 25 
 26 import com.sun.tools.javac.comp.CodeReflectionTransformer;
 27 
 28 /**
 29  * Defines the implementation of the
 30  * {@linkplain javax.tools.ToolProvider#getSystemJavaCompiler system Java compiler}
 31  * and its command line equivalent, <em>{@index javac javac tool}</em>.
 32  *
 33  * <p>The {@code com.sun.source.*} packages provide the {@index "Compiler Tree API"}:
 34  * an API for accessing the abstract trees (ASTs) representing Java source code
 35  * and documentation comments, used by <em>javac</em>, <em>javadoc</em> and related tools.
 36  *
 37  * <h2 style="font-family:'DejaVu Sans Mono', monospace; font-style:italic">javac</h2>
 38  *
 39  * <p>
 40  * This module provides the equivalent of command-line access to <em>javac</em>
 41  * via the {@link java.util.spi.ToolProvider ToolProvider} and
 42  * {@link javax.tools.Tool} service provider interfaces (SPIs),
 43  * and more flexible access via the {@link javax.tools.JavaCompiler JavaCompiler}
 44  * SPI.</p>
 45  *
 46  * <p> Instances of the tools can be obtained by calling
 47  * {@link java.util.spi.ToolProvider#findFirst ToolProvider.findFirst}
 48  * or the {@linkplain java.util.ServiceLoader service loader} with the name
 49  * {@code "javac"}.
 50  *
 51  * <p>
 52  * In addition, instances of {@link javax.tools.JavaCompiler.CompilationTask}
 53  * obtained from {@linkplain javax.tools.JavaCompiler JavaCompiler} can be
 54  * downcast to {@link com.sun.source.util.JavacTask JavacTask} for access to
 55  * lower level aspects of <em>javac</em>, such as the
 56  * {@link com.sun.source.tree Abstract Syntax Tree} (AST).</p>
 57  *
 58  * <p>This module uses the {@link java.nio.file.spi.FileSystemProvider
 59  * FileSystemProvider} API to locate file system providers. In particular,
 60  * this means that a jar file system provider, such as that in the
 61  * {@code jdk.zipfs} module, must be available if the compiler is to be able
 62  * to read JAR files.
 63  *
 64  * <h3>Options and Environment Variables</h3>
 65  *
 66  * The full set of options and environment variables supported by <em>javac</em>
 67  * is given in the <a href="../../specs/man/javac.html"><em>javac Tool Guide</em></a>.
 68  * However, there are some restrictions when the compiler is invoked through
 69  * its API.
 70  *
 71  * <ul>
 72  *     <li><p>The {@code -J} option is not supported.
 73  *          Any necessary VM options must be set in the VM used to invoke the API.
 74  *          {@code IllegalArgumentException} will be thrown if the option
 75  *          is used when invoking the tool through the {@code JavaCompiler} API;
 76  *          an error will be reported if the option is used when invoking
 77  *          <em>javac</em> through the {@link java.util.spi.ToolProvider ToolProvider}
 78  *          or legacy {@link com.sun.tools.javac.Main Main} API.
 79  *
 80  *     <li><p>The "classpath wildcard" feature is not supported.
 81  *          The feature is only supported by the native launcher.
 82  *          When invoking the tool through its API, all necessary jar
 83  *          files should be included directly in the {@code --class-path}
 84  *          option, or the {@code CLASSPATH} environment variable.
 85  *          When invoking the tool through its API, all components of the
 86  *          class path will be taken literally, and will be ignored if there
 87  *          is no matching directory or file. The {@code -Xlint:paths}
 88  *          option can be used to generate warnings about missing components.
 89  *
 90  * </ul>
 91  *
 92  * The following restrictions apply when invoking the compiler through
 93  * the {@link JavaCompiler} interface.
 94  *
 95  * <ul>
 96  *     <li><p>Argument files (so-called @-files) are not supported.
 97  *          The content of any such files should be included directly
 98  *          in the list of options provided when invoking the tool
 99  *          though this API.
100  *          {@code IllegalArgumentException} will be thrown if
101  *          the option is used when invoking the tool through this API.
102  *
103  *     <li><p>The environment variable {@code JDK_JAVAC_OPTIONS} is not supported.
104  *          Any options defined in the environment variable should be included
105  *          directly in the list of options provided when invoking the
106  *          API; any values in the environment variable will be ignored.
107  *
108  *     <li><p>Options that are just used to obtain information (such as
109  *          {@code --help}, {@code --help-extended}, {@code --version} and
110  *          {@code --full-version}) are not supported.
111  *          {@link IllegalArgumentException} will be thrown if any of
112  *          these options are used when invoking the tool through this API.
113  *
114  *      <li>Path-related options depend on the file manager being used
115  *          when calling {@link JavaCompiler#getTask}. The "standard"
116  *          options, such as {@code --class-path}, {@code --module-path},
117  *          and so on are available when using the default file manager,
118  *          or one derived from it. These options may not be available
119  *          and different options may be available, when using a different
120  *          file manager.
121  *          {@link IllegalArgumentException} will be thrown if any option
122  *          that is unknown to the tool or the file manager is used when
123  *          invoking the tool through this API.
124  * </ul>
125  *
126  * Note that the {@code CLASSPATH} environment variable <em>is</em> honored
127  * when invoking the compiler through its API, although such use is discouraged.
128  * An environment variable cannot be unset once a VM has been started,
129  * and so it is recommended to ensure that the environment variable is not set
130  * when starting a VM that will be used to invoke the compiler.
131  * However, if a value has been set, any such value can be overridden by
132  * using the {@code --class-path} option when invoking the compiler,
133  * or setting {@link StandardLocation#CLASS_PATH} in the file manager
134  * when invoking the compiler through the {@link JavaCompiler} interface.
135  *
136  * <h3>SuppressWarnings</h3>
137  *
138  * JLS {@jls 9.6.4.5} specifies a number of strings that can be used to
139  * suppress warnings that may be generated by a Java compiler.
140  *
141  * In addition, <em>javac</em> also supports other strings that can be used
142  * to suppress other kinds of warnings. The following table lists all the
143  * strings that can be used with {@code @SuppressWarnings}.
144  *
145  * <table class="striped">
146  *     <caption>Strings supported by {@code SuppressWarnings}</caption>
147  * <thead>
148  * <tr><th>String<th>Suppress Warnings About ...
149  * </thead>
150  * <tbody>
151  * <tr><th scope="row">{@code auxiliaryclass}       <td>an auxiliary class that is hidden in a source file, and is used
152  *                                                      from other files
153  * <tr><th scope="row">{@code cast}                 <td>use of unnecessary casts
154  * <tr><th scope="row">{@code classfile}            <td>issues related to classfile contents
155  * <tr><th scope="row">{@code dangling-doc-comments} <td>issues related to "dangling" documentation comments,
156  *                                                       not attached to a declaration
157  * <tr><th scope="row">{@code deprecation}          <td>use of deprecated items
158  * <tr><th scope="row">{@code dep-ann}              <td>items marked as deprecated in a documentation comment but not
159  *                                                      using the {@code @Deprecated} annotation
160  * <tr><th scope="row">{@code divzero}              <td>division by constant integer {@code 0}
161  * <tr><th scope="row">{@code empty}                <td>empty statement after {@code if}
162  * <tr><th scope="row">{@code exports}              <td>issues regarding module exports
163  * <tr><th scope="row">{@code fallthrough}          <td>falling through from one case of a {@code switch} statement to
164  *                                                      the next
165  * <tr><th scope="row">{@code finally}              <td>{@code finally} clauses that do not terminate normally
166  * <tr><th scope="row">{@code incubating}           <td>use of incubating modules
167  * <tr><th scope="row">{@code lossy-conversions}    <td>possible lossy conversions in compound assignment
168  * <tr><th scope="row">{@code missing-explicit-ctor} <td>missing explicit constructors in public and protected classes
169  *                                                      in exported packages
170  * <tr><th scope="row">{@code module}               <td>module system related issues
171  * <tr><th scope="row">{@code opens}                <td>issues regarding module opens
172  * <tr><th scope="row">{@code overloads}            <td>issues regarding method overloads
173  * <tr><th scope="row">{@code overrides}            <td>issues regarding method overrides
174  * <tr><th scope="row">{@code path}                 <td>invalid path elements on the command line
175  * <tr><th scope="row">{@code preview}              <td>use of preview language features
176  * <tr><th scope="row">{@code rawtypes}             <td>use of raw types
177  * <tr><th scope="row">{@code removal}              <td>use of API that has been marked for removal
178  * <tr><th scope="row">{@code restricted}           <td>use of restricted methods
179  * <tr><th scope="row">{@code requires-automatic}   <td>use of automatic modules in the {@code requires} clauses
180  * <tr><th scope="row">{@code requires-transitive-automatic} <td>automatic modules in {@code requires transitive}
181  * <tr><th scope="row">{@code serial}               <td>{@link java.base/java.io.Serializable Serializable} classes
182  *                                                      that do not have a {@code serialVersionUID} field, or other
183  *                                                      suspect declarations in {@code Serializable} and
184  *                                                      {@link java.base/java.io.Externalizable Externalizable} classes
185  *                                                      and interfaces
186  * <tr><th scope="row">{@code static}               <td>accessing a static member using an instance
187  * <tr><th scope="row">{@code strictfp}             <td>unnecessary use of the {@code strictfp} modifier
188  * <tr><th scope="row">{@code synchronization}      <td>synchronization attempts on instances of value-based classes
189  * <tr><th scope="row">{@code text-blocks}          <td>inconsistent white space characters in text block indentation
190  * <tr><th scope="row">{@code this-escape}          <td>superclass constructor leaking {@code this} before subclass initialized
191  * <tr><th scope="row">{@code try}                  <td>issues relating to use of {@code try} blocks
192  *                                                      (that is, try-with-resources)
193  * <tr><th scope="row">{@code unchecked}            <td>unchecked operations
194  * <tr><th scope="row">{@code varargs}              <td>potentially unsafe vararg methods
195  * <tr><th scope="row">{@code doclint:accessibility} <td>accessibility issues found in documentation comments
196  * <tr><th scope="row">{@code doclint:all}          <td>all issues found in documentation comments
197  * <tr><th scope="row">{@code doclint:html}         <td>HTML issues found in documentation comments
198  * <tr><th scope="row">{@code doclint:missing}      <td>missing items in documentation comments
199  * <tr><th scope="row">{@code doclint:reference}    <td>reference issues found in documentation comments
200  * <tr><th scope="row">{@code doclint:syntax}       <td>syntax issues found in documentation comments
201  * </tbody>
202  * </table>
203  *
204  * @toolGuide javac
205  *
206  * @provides java.util.spi.ToolProvider
207  *     Use {@link java.util.spi.ToolProvider#findFirst ToolProvider.findFirst("javac")}
208  *     to obtain an instance of a {@code ToolProvider} that provides the equivalent
209  *     of command-line access to the {@code javac} tool.
210  * @provides com.sun.tools.javac.platform.PlatformProvider
211  * @provides javax.tools.JavaCompiler
212  * @provides javax.tools.Tool
213  *
214  * @uses javax.annotation.processing.Processor
215  * @uses com.sun.source.util.Plugin
216  * @uses com.sun.tools.javac.platform.PlatformProvider
217  *
218  * @moduleGraph
219  * @since 9
220  */
221 module jdk.compiler {
222     requires transitive java.compiler;
223     requires jdk.internal.opt;
224     requires jdk.zipfs;
225 
226     exports com.sun.source.doctree;
227     exports com.sun.source.tree;
228     exports com.sun.source.util;
229     exports com.sun.tools.javac;
230 
231     exports com.sun.tools.doclint to
232         jdk.javadoc;
233     exports com.sun.tools.javac.api to
234         jdk.javadoc,
235         jdk.jshell,
236         jdk.internal.md,
237         jdk.incubator.code;
238     exports com.sun.tools.javac.resources to
239         jdk.jshell;
240     exports com.sun.tools.javac.code to
241         jdk.javadoc,
242         jdk.jshell,
243         jdk.incubator.code;
244     exports com.sun.tools.javac.comp to
245         jdk.javadoc,
246         jdk.jshell,
247         jdk.incubator.code;
248     exports com.sun.tools.javac.file to
249         jdk.jdeps,
250         jdk.javadoc;
251     exports com.sun.tools.javac.jvm to
252         jdk.javadoc,
253         jdk.incubator.code;
254     exports com.sun.tools.javac.main to
255         jdk.javadoc,
256         jdk.jshell,
257         jdk.incubator.code;
258     exports com.sun.tools.javac.model to
259         jdk.javadoc,
260         jdk.incubator.code;
261     exports com.sun.tools.javac.parser to
262         jdk.jshell,
263         jdk.internal.md;
264     exports com.sun.tools.javac.platform to
265         jdk.jdeps,
266         jdk.javadoc;
267     exports com.sun.tools.javac.tree to
268         jdk.javadoc,
269         jdk.jshell,
270         jdk.internal.md,
271         jdk.incubator.code;
272     exports com.sun.tools.javac.util to
273         jdk.jdeps,
274         jdk.javadoc,
275         jdk.jshell,
276         jdk.internal.md,
277         jdk.incubator.code;
278     exports com.sun.tools.javac.processing to
279         jdk.incubator.code;
280 
281     uses javax.annotation.processing.Processor;
282     uses com.sun.source.util.Plugin;
283     uses com.sun.tools.doclint.DocLint;
284     uses com.sun.tools.javac.platform.PlatformProvider;
285     uses com.sun.tools.javac.api.JavacTrees.DocCommentTreeTransformer;
286     uses CodeReflectionTransformer;
287 
288     provides java.util.spi.ToolProvider with
289         com.sun.tools.javac.main.JavacToolProvider;
290 
291     provides com.sun.tools.javac.platform.PlatformProvider with
292         com.sun.tools.javac.platform.JDKPlatformProvider;
293 
294     provides javax.tools.JavaCompiler with
295         com.sun.tools.javac.api.JavacTool;
296 
297     provides javax.tools.Tool with
298         com.sun.tools.javac.api.JavacTool;
299 }
300