开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
forked from Stefan/Java8Source
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (2)
master
develop
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
项目仓库所选许可证以仓库主分支所使用许可证为准
master
分支 (2)
master
develop
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (2)
master
develop
Java8Source
/
src
/
javax
/
tools
/
JavaCompiler.java
Java8Source
/
src
/
javax
/
tools
/
JavaCompiler.java
JavaCompiler.java 13.57 KB
一键复制 编辑 原始数据 按行查看 历史
Stefan 提交于 2020年08月11日 23:17 +08:00 . 初始化
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
/*
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package javax.tools;
import java.io.File;
import java.io.Writer;
import java.nio.charset.Charset;
import java.util.Locale;
import java.util.concurrent.Callable;
import javax.annotation.processing.Processor;
/**
* Interface to invoke Java™ programming language compilers from
* programs.
*
* <p>The compiler might generate diagnostics during compilation (for
* example, error messages). If a diagnostic listener is provided,
* the diagnostics will be supplied to the listener. If no listener
* is provided, the diagnostics will be formatted in an unspecified
* format and written to the default output, which is {@code
* System.err} unless otherwise specified. Even if a diagnostic
* listener is supplied, some diagnostics might not fit in a {@code
* Diagnostic} and will be written to the default output.
*
* <p>A compiler tool has an associated standard file manager, which
* is the file manager that is native to the tool (or built-in). The
* standard file manager can be obtained by calling {@linkplain
* #getStandardFileManager getStandardFileManager}.
*
* <p>A compiler tool must function with any file manager as long as
* any additional requirements as detailed in the methods below are
* met. If no file manager is provided, the compiler tool will use a
* standard file manager such as the one returned by {@linkplain
* #getStandardFileManager getStandardFileManager}.
*
* <p>An instance implementing this interface must conform to
* <cite>The Java&trade; Language Specification</cite>
* and generate class files conforming to
* <cite>The Java&trade; Virtual Machine Specification</cite>.
* The versions of these
* specifications are defined in the {@linkplain Tool} interface.
*
* Additionally, an instance of this interface supporting {@link
* javax.lang.model.SourceVersion#RELEASE_6 SourceVersion.RELEASE_6}
* or higher must also support {@linkplain javax.annotation.processing
* annotation processing}.
*
* <p>The compiler relies on two services: {@linkplain
* DiagnosticListener diagnostic listener} and {@linkplain
* JavaFileManager file manager}. Although most classes and
* interfaces in this package defines an API for compilers (and
* tools in general) the interfaces {@linkplain DiagnosticListener},
* {@linkplain JavaFileManager}, {@linkplain FileObject}, and
* {@linkplain JavaFileObject} are not intended to be used in
* applications. Instead these interfaces are intended to be
* implemented and used to provide customized services for a
* compiler and thus defines an SPI for compilers.
*
* <p>There are a number of classes and interfaces in this package
* which are designed to ease the implementation of the SPI to
* customize the behavior of a compiler:
*
* <dl>
* <dt>{@link StandardJavaFileManager}</dt>
* <dd>
*
* Every compiler which implements this interface provides a
* standard file manager for operating on regular {@linkplain
* java.io.File files}. The StandardJavaFileManager interface
* defines additional methods for creating file objects from
* regular files.
*
* <p>The standard file manager serves two purposes:
*
* <ul>
* <li>basic building block for customizing how a compiler reads
* and writes files</li>
* <li>sharing between multiple compilation tasks</li>
* </ul>
*
* <p>Reusing a file manager can potentially reduce overhead of
* scanning the file system and reading jar files. Although there
* might be no reduction in overhead, a standard file manager must
* work with multiple sequential compilations making the following
* example a recommended coding pattern:
*
* <pre>
* File[] files1 = ... ; // input for first compilation task
* File[] files2 = ... ; // input for second compilation task
*
* JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
* StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
*
* {@code Iterable<? extends JavaFileObject>} compilationUnits1 =
* fileManager.getJavaFileObjectsFromFiles({@linkplain java.util.Arrays#asList Arrays.asList}(files1));
* compiler.getTask(null, fileManager, null, null, null, compilationUnits1).call();
*
* {@code Iterable<? extends JavaFileObject>} compilationUnits2 =
* fileManager.getJavaFileObjects(files2); // use alternative method
* // reuse the same file manager to allow caching of jar files
* compiler.getTask(null, fileManager, null, null, null, compilationUnits2).call();
*
* fileManager.close();</pre>
*
* </dd>
*
* <dt>{@link DiagnosticCollector}</dt>
* <dd>
* Used to collect diagnostics in a list, for example:
* <pre>
* {@code Iterable<? extends JavaFileObject>} compilationUnits = ...;
* JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
* {@code DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();}
* StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
* compiler.getTask(null, fileManager, diagnostics, null, null, compilationUnits).call();
*
* for ({@code Diagnostic<? extends JavaFileObject>} diagnostic : diagnostics.getDiagnostics())
* System.out.format("Error on line %d in %s%n",
* diagnostic.getLineNumber(),
* diagnostic.getSource().toUri());
*
* fileManager.close();</pre>
* </dd>
*
* <dt>
* {@link ForwardingJavaFileManager}, {@link ForwardingFileObject}, and
* {@link ForwardingJavaFileObject}
* </dt>
* <dd>
*
* Subclassing is not available for overriding the behavior of a
* standard file manager as it is created by calling a method on a
* compiler, not by invoking a constructor. Instead forwarding
* (or delegation) should be used. These classes makes it easy to
* forward most calls to a given file manager or file object while
* allowing customizing behavior. For example, consider how to
* log all calls to {@linkplain JavaFileManager#flush}:
*
* <pre>
* final {@linkplain java.util.logging.Logger Logger} logger = ...;
* {@code Iterable<? extends JavaFileObject>} compilationUnits = ...;
* JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
* StandardJavaFileManager stdFileManager = compiler.getStandardFileManager(null, null, null);
* JavaFileManager fileManager = new ForwardingJavaFileManager(stdFileManager) {
* public void flush() throws IOException {
* logger.entering(StandardJavaFileManager.class.getName(), "flush");
* super.flush();
* logger.exiting(StandardJavaFileManager.class.getName(), "flush");
* }
* };
* compiler.getTask(null, fileManager, null, null, null, compilationUnits).call();</pre>
* </dd>
*
* <dt>{@link SimpleJavaFileObject}</dt>
* <dd>
*
* This class provides a basic file object implementation which
* can be used as building block for creating file objects. For
* example, here is how to define a file object which represent
* source code stored in a string:
*
* <pre>
* /**
* * A file object used to represent source coming from a string.
* {@code *}/
* public class JavaSourceFromString extends SimpleJavaFileObject {
* /**
* * The source code of this "file".
* {@code *}/
* final String code;
*
* /**
* * Constructs a new JavaSourceFromString.
* * {@code @}param name the name of the compilation unit represented by this file object
* * {@code @}param code the source code for the compilation unit represented by this file object
* {@code *}/
* JavaSourceFromString(String name, String code) {
* super({@linkplain java.net.URI#create URI.create}("string:///" + name.replace('.','/') + Kind.SOURCE.extension),
* Kind.SOURCE);
* this.code = code;
* }
*
* {@code @}Override
* public CharSequence getCharContent(boolean ignoreEncodingErrors) {
* return code;
* }
* }</pre>
* </dd>
* </dl>
*
* @author Peter von der Ah&eacute;
* @author Jonathan Gibbons
* @see DiagnosticListener
* @see Diagnostic
* @see JavaFileManager
* @since 1.6
*/
public interface JavaCompiler extends Tool, OptionChecker {
/**
* Creates a future for a compilation task with the given
* components and arguments. The compilation might not have
* completed as described in the CompilationTask interface.
*
* <p>If a file manager is provided, it must be able to handle all
* locations defined in {@link StandardLocation}.
*
* <p>Note that annotation processing can process both the
* compilation units of source code to be compiled, passed with
* the {@code compilationUnits} parameter, as well as class
* files, whose names are passed with the {@code classes}
* parameter.
*
* @param out a Writer for additional output from the compiler;
* use {@code System.err} if {@code null}
* @param fileManager a file manager; if {@code null} use the
* compiler's standard filemanager
* @param diagnosticListener a diagnostic listener; if {@code
* null} use the compiler's default method for reporting
* diagnostics
* @param options compiler options, {@code null} means no options
* @param classes names of classes to be processed by annotation
* processing, {@code null} means no class names
* @param compilationUnits the compilation units to compile, {@code
* null} means no compilation units
* @return an object representing the compilation
* @throws RuntimeException if an unrecoverable error
* occurred in a user supplied component. The
* {@linkplain Throwable#getCause() cause} will be the error in
* user code.
* @throws IllegalArgumentException if any of the options are invalid,
* or if any of the given compilation units are of other kind than
* {@linkplain JavaFileObject.Kind#SOURCE source}
*/
CompilationTask getTask(Writer out,
JavaFileManager fileManager,
DiagnosticListener<? super JavaFileObject> diagnosticListener,
Iterable<String> options,
Iterable<String> classes,
Iterable<? extends JavaFileObject> compilationUnits);
/**
* Gets a new instance of the standard file manager implementation
* for this tool. The file manager will use the given diagnostic
* listener for producing any non-fatal diagnostics. Fatal errors
* will be signaled with the appropriate exceptions.
*
* <p>The standard file manager will be automatically reopened if
* it is accessed after calls to {@code flush} or {@code close}.
* The standard file manager must be usable with other tools.
*
* @param diagnosticListener a diagnostic listener for non-fatal
* diagnostics; if {@code null} use the compiler's default method
* for reporting diagnostics
* @param locale the locale to apply when formatting diagnostics;
* {@code null} means the {@linkplain Locale#getDefault() default locale}.
* @param charset the character set used for decoding bytes; if
* {@code null} use the platform default
* @return the standard file manager
*/
StandardJavaFileManager getStandardFileManager(
DiagnosticListener<? super JavaFileObject> diagnosticListener,
Locale locale,
Charset charset);
/**
* Interface representing a future for a compilation task. The
* compilation task has not yet started. To start the task, call
* the {@linkplain #call call} method.
*
* <p>Before calling the call method, additional aspects of the
* task can be configured, for example, by calling the
* {@linkplain #setProcessors setProcessors} method.
*/
interface CompilationTask extends Callable<Boolean> {
/**
* Sets processors (for annotation processing). This will
* bypass the normal discovery mechanism.
*
* @param processors processors (for annotation processing)
* @throws IllegalStateException if the task has started
*/
void setProcessors(Iterable<? extends Processor> processors);
/**
* Set the locale to be applied when formatting diagnostics and
* other localized data.
*
* @param locale the locale to apply; {@code null} means apply no
* locale
* @throws IllegalStateException if the task has started
*/
void setLocale(Locale locale);
/**
* Performs this compilation task. The compilation may only
* be performed once. Subsequent calls to this method throw
* IllegalStateException.
*
* @return true if and only all the files compiled without errors;
* false otherwise
*
* @throws RuntimeException if an unrecoverable error occurred
* in a user-supplied component. The
* {@linkplain Throwable#getCause() cause} will be the error
* in user code.
* @throws IllegalStateException if called more than once
*/
Boolean call();
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/yxljava/Java8Source.git
git@gitee.com:yxljava/Java8Source.git
yxljava
Java8Source
Java8Source
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /