本文整理了Java中com.sun.tools.javac.main.JavaCompiler.parse()
方法的一些代码示例,展示了JavaCompiler.parse()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JavaCompiler.parse()
方法的具体详情如下:
包路径:com.sun.tools.javac.main.JavaCompiler
类名称:JavaCompiler
方法名:parse
[英]Parse contents of file.
[中]解析文件的内容。
代码示例来源:origin: konsoletyper/teavm-javac
/** Parse contents of file.
* @param filename The name of the file to be parsed.
*/
@Deprecated
public JCTree.JCCompilationUnit parse(String filename) {
JavacFileManager fm = (JavacFileManager)fileManager;
return parse(fm.getJavaFileObjectsFromStrings(List.of(filename)).iterator().next());
}
代码示例来源: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());
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
/** Parse contents of file.
* @param filename The name of the file to be parsed.
*/
@Deprecated
public JCTree.JCCompilationUnit parse(String filename) {
JavacFileManager fm = (JavacFileManager)fileManager;
return parse(fm.getJavaFileObjectsFromStrings(List.of(filename)).iterator().next());
}
代码示例来源:origin: sc.fiji/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());
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
/**
* Parses a list of files.
*/
public List<JCCompilationUnit> parseFiles(Iterable<JavaFileObject> fileObjects) {
if (shouldStop(CompileState.PARSE))
return List.nil();
//parse all files
ListBuffer<JCCompilationUnit> trees = new ListBuffer<>();
Set<JavaFileObject> filesSoFar = new HashSet<JavaFileObject>();
for (JavaFileObject fileObject : fileObjects) {
if (!filesSoFar.contains(fileObject)) {
filesSoFar.add(fileObject);
trees.append(parse(fileObject));
}
}
return trees.toList();
}
代码示例来源:origin: konsoletyper/teavm-javac
/**
* Parses a list of files.
*/
public List<JCCompilationUnit> parseFiles(Iterable<JavaFileObject> fileObjects) {
if (shouldStop(CompileState.PARSE))
return List.nil();
//parse all files
ListBuffer<JCCompilationUnit> trees = new ListBuffer<>();
Set<JavaFileObject> filesSoFar = new HashSet<JavaFileObject>();
for (JavaFileObject fileObject : fileObjects) {
if (!filesSoFar.contains(fileObject)) {
filesSoFar.add(fileObject);
trees.append(parse(fileObject));
}
}
return trees.toList();
}
代码示例来源:origin: me.tatarka.retrolambda.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: 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: com.android.tools.external.lombok/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: sc.fiji/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
/** 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.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: konsoletyper/teavm-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.jvnet.sorcerer/sorcerer-javac
/**
* Parses a list of files.
*/
public List<JCCompilationUnit> parseFiles(List<JavaFileObject> fileObjects) throws IOException {
if (errorCount() > 0)
return List.nil();
//parse all files
ListBuffer<JCCompilationUnit> trees = lb();
for (JavaFileObject fileObject : fileObjects)
trees.append(parse(fileObject));
return trees.toList();
}
代码示例来源:origin: org.projectlombok/lombok.ast
@Override public JCCompilationUnit process(Source in, Void irrelevant) throws ConversionProblem {
Context context = new Context();
Options.instance(context).put(OptionName.ENCODING, charset.name());
JavaCompiler compiler = new JavaCompiler(context);
compiler.genEndPos = true;
compiler.keepComments = true;
JCCompilationUnit cu = compiler.parse(new ContentBasedJavaFileObject(in.getName(), in.getRawInput()));
return cu;
}
};
代码示例来源:origin: com.android.tools.external.lombok/lombok-ast
@Override public JCCompilationUnit process(Source in, Void irrelevant) throws ConversionProblem {
Context context = new Context();
Options.instance(context).put(OptionName.ENCODING, charset.name());
JavaCompiler compiler = new JavaCompiler(context);
compiler.genEndPos = true;
compiler.keepComments = true;
JCCompilationUnit cu = compiler.parse(new ContentBasedJavaFileObject(in.getName(), in.getRawInput()));
return cu;
}
};
代码示例来源:origin: me.tatarka.retrolambda.projectlombok/lombok.ast
@Override public JCCompilationUnit process(Source in, Void irrelevant) throws ConversionProblem {
Context context = new Context();
Options.instance(context).put(OptionName.ENCODING, charset.name());
JavaCompiler compiler = new JavaCompiler(context);
compiler.genEndPos = true;
compiler.keepComments = true;
JCCompilationUnit cu = compiler.parse(new ContentBasedJavaFileObject(in.getName(), in.getRawInput()));
return cu;
}
};
代码示例来源:origin: sc.fiji/javac
/**
* Parses a list of files.
*/
public List<JCCompilationUnit> parseFiles(List<JavaFileObject> fileObjects) throws IOException {
if (shouldStop(CompileState.PARSE))
return List.nil();
//parse all files
ListBuffer<JCCompilationUnit> trees = lb();
for (JavaFileObject fileObject : fileObjects)
trees.append(parse(fileObject));
return trees.toList();
}
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
tree = parse(filename, filename.getCharContent(false));
} catch (IOException e) {
log.error("error.reading.file", filename, e);
代码示例来源:origin: sc.fiji/javac
tree = parse(filename, filename.getCharContent(false));
} catch (IOException e) {
log.error("error.reading.file", filename, JavacFileManager.getMessage(e));
内容来源于网络,如有侵权,请联系作者删除!