本文整理了Java中com.sun.tools.javac.main.JavaCompiler
类的一些代码示例,展示了JavaCompiler
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JavaCompiler
类的具体详情如下:
包路径:com.sun.tools.javac.main.JavaCompiler
类名称:JavaCompiler
[英]This class could be the main entry point for GJC when GJC is used as a component in a larger software system. It provides operations to construct a new compiler, and to run a new compiler on a set of source files.
This is NOT part of any supported API. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.
[中]当GJC被用作更大软件系统中的组件时,该类可能是GJC的主要入口点。它提供了构造新编译器以及在一组源文件上运行新编译器的操作。
这不是任何受支持的API的一部分。如果您编写的代码依赖于此,那么您将自担风险。本代码及其内部接口如有更改或删除,恕不另行通知。
代码示例来源:origin: google/error-prone
return;
if (JavaCompiler.instance(context).errorCount() > 0) {
return;
代码示例来源:origin: cincheo/jsweet
transpilationHandler.setDisabled(isIgnoreJavaErrors());
List<JCCompilationUnit> compilationUnits = compiler.enterTrees(compiler.parseFiles(fileObjects));
if (transpilationHandler.getErrorCount() > 0) {
logger.warn("errors during parse tree");
Queue<Env<AttrContext>> todo = compiler.attribute(compiler.todo);
todo = compiler.flow(todo);
compiler.reportDeferredDiagnostics();
代码示例来源:origin: google/error-prone
public ClassSymbol resolveClass(CharSequence qualifiedClass)
throws CouldNotResolveImportException {
try {
Symbol symbol =
JavaCompiler.instance(context)
.resolveIdent(symtab().java_base, qualifiedClass.toString());
if (symbol.equals(symtab().errSymbol) || !(symbol instanceof ClassSymbol)) {
throw new CouldNotResolveImportException(qualifiedClass);
} else {
return (ClassSymbol) symbol;
}
} catch (NullPointerException e) {
throw new CouldNotResolveImportException(qualifiedClass);
}
}
代码示例来源:origin: cincheo/jsweet
/**
* Parses and attributes the given files within this compilation
* environment.
*/
public List<JCCompilationUnit> parseAndAttributeJavaFiles(List<File> javaFiles) throws IOException {
List<JavaFileObject> sources = toJavaFileObjects(fileManager, javaFiles);
List<JCCompilationUnit> compilationUnits = compiler.enterTrees(compiler.parseFiles(sources));
compiler.attribute(compiler.todo);
return compilationUnits;
}
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
switch (compilePolicy) {
case ATTR_ONLY:
attribute(todo);
break;
flow(attribute(todo));
break;
generate(desugar(flow(attribute(todo))));
break;
for (List<Env<AttrContext>> list : groupByFile(flow(attribute(todo))).values())
generate(desugar(list));
break;
generate(desugar(flow(attribute(todo.next()))));
break;
elapsed_msec = elapsed(start_msec);;
printVerbose("total", Long.toString(elapsed_msec));
reportDeferredDiagnostics();
printCount("error", errorCount());
printCount("warn", warningCount());
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
hasBeenUsed = true;
start_msec = now();
try {
initProcessAnnotations(processors);
delegateCompiler = processAnnotations(enterTrees(stopIfError(parseFiles(sourceFileObjects))),
classnames);
delegateCompiler.compile2();
delegateCompiler.close();
elapsed_msec = delegateCompiler.elapsed_msec;
} catch (Abort ex) {
代码示例来源:origin: konsoletyper/teavm-javac
|| options.isSet(FULLVERSION))
return Result.OK;
if (JavaCompiler.explicitAnnotationProcessingRequested(options)) {
error("err.no.source.files.classes");
} else {
comp = JavaCompiler.instance(context);
comp = JavaCompiler.instance(context);
List<JavaFileObject> otherFiles = List.nil();
JavacFileManager dfm = (JavacFileManager)fileManager;
comp.compile(fileObjects,
classnames.toList(),
processors);
if (comp.errorCount() != 0)
return Result.ERROR;
} catch (IOException ex) {
if (comp == null || comp.errorCount() == 0 ||
options == null || options.isSet("dev"))
bugMessage(ex);
if (comp != null) {
try {
comp.close();
} catch (ClientCodeException ex) {
throw new RuntimeException(ex.getCause());
代码示例来源:origin: org.projectlombok/lombok.ast
public static void main(String[] args) throws IOException {
if (args.length == 0) {
System.out.println("Usage: Supply a file name to print.");
return;
}
Context context = new Context();
Options.instance(context).put(OptionName.ENCODING, "UTF-8");
JavaCompiler compiler = new JavaCompiler(context);
compiler.genEndPos = true;
compiler.keepComments = true;
@SuppressWarnings("deprecation") JCCompilationUnit cu = compiler.parse(args[0]);
JcTreePrinter printer = new JcTreePrinter(true);
printer.visit(cu);
System.out.println(printer);
}
代码示例来源:origin: cincheo/jsweet
JavacFileManager.preRegister(context);
fileManager = context.get(JavaFileManager.class);
compiler = JavaCompiler.instance(context);
compiler.attrParseOnly = true;
compiler.verbose = false;
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
public void process(Env<AttrContext> env) {
handleFlowResults(compiler.flow(compiler.attribute(env)), results);
}
};
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
compiler.generate(compiler.desugar(genList), results);
genList.clear();
compiler.reportDeferredDiagnostics();
cleanup();
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
/**
* Perform dataflow checks on an attributed parse tree.
*/
public List<Env<AttrContext>> flow(Env<AttrContext> env) {
ListBuffer<Env<AttrContext>> results = lb();
flow(env, results);
return stopIfError(results);
}
代码示例来源:origin: cincheo/jsweet
Arrays.asList(SourceFile.toFiles(sourceFiles)));
JavaCompiler compiler = JavaCompiler.instance(context);
compiler.attrParseOnly = true;
compiler.verbose = true;
List<JCCompilationUnit> compilationUnits = compiler.enterTrees(compiler.parseFiles(fileObjects));
MainMethodFinder mainMethodFinder = new MainMethodFinder();
try {
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
/** Create the compiler to be used for the final compilation. */
JavaCompiler finalCompiler() {
try {
Context nextCtx = nextContext();
JavacProcessingEnvironment.this.context = nextCtx;
JavaCompiler c = JavaCompiler.instance(nextCtx);
c.log.initRound(compiler.log);
return c;
} finally {
compiler.close(false);
}
}
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
/** Get the JavaCompiler instance for this context. */
public static JavaCompiler instance(Context context) {
JavaCompiler instance = context.get(compilerKey);
if (instance == null)
instance = new JavaCompiler(context);
return instance;
}
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
/** Parse contents of file.
* @param filename The name of the file to be parsed.
*/
public JCTree.JCCompilationUnit parse(JavaFileObject filename) {
JavaFileObject prev = log.useSource(filename);
try {
JCTree.JCCompilationUnit t = parse(filename, readSource(filename));
if (t.endPositions != null)
log.setEndPosTable(filename, t.endPositions);
return t;
} finally {
log.useSource(prev);
}
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
/** Return the number of errors found so far in this round.
* This may include uncoverable errors, such as parse errors,
* and transient errors, such as missing symbols. */
int errorCount() {
return compiler.errorCount();
}
代码示例来源:origin: konsoletyper/teavm-javac
/**
* Attribute a list of parse trees, such as found on the "todo" list.
* Note that attributing classes may cause additional files to be
* parsed and entered via the SourceCompleter.
* Attribution of the entries in the list does not stop if any errors occur.
* @returns a list of environments for attributd classes.
*/
public Queue<Env<AttrContext>> attribute(Queue<Env<AttrContext>> envs) {
ListBuffer<Env<AttrContext>> results = new ListBuffer<>();
while (!envs.isEmpty())
results.append(attribute(envs.remove()));
return stopIfError(CompileState.ATTR, results);
}
代码示例来源:origin: org.checkerframework/dataflow
JavaCompiler javac = new JavaCompiler(context);
JavacFileManager fileManager = (JavacFileManager) context.get(JavaFileManager.class);
public void write(int b) throws IOException {}
}));
javac.compile(List.of(l), List.of(clas), List.of(typeProcessor));
} catch (Throwable e) {
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
/** Parse contents of file.
* @param filename The name of the file to be parsed.
*/
@Deprecated
public JCTree.JCCompilationUnit parse(String filename) throws IOException {
JavacFileManager fm = (JavacFileManager)fileManager;
return parse(fm.getJavaFileObjectsFromStrings(List.of(filename)).iterator().next());
}
内容来源于网络,如有侵权,请联系作者删除!