本文整理汇总了Java中com.sun.tools.javac.main.JavaCompiler.parse方法的典型用法代码示例。如果您正苦于以下问题:Java JavaCompiler.parse方法的具体用法?Java JavaCompiler.parse怎么用?Java JavaCompiler.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.tools.javac.main.JavaCompiler
的用法示例。
在下文中一共展示了JavaCompiler.parse方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.sun.tools.javac.main.JavaCompiler; //导入方法依赖的package包/类
public static void main(String... args) {
JavaCompiler compiler = JavaCompiler.instance(new Context());
compiler.keepComments = true;
String testSrc = System.getProperty("test.src");
JavacFileManager fm = new JavacFileManager(new Context(), false, null);
JavaFileObject f = fm.getJavaFileObject(testSrc + File.separatorChar + "T4910483.java");
JCTree.JCCompilationUnit cu = compiler.parse(f);
JCTree classDef = cu.getTypeDecls().head;
String commentText = cu.docComments.getCommentText(classDef);
String expected = "Test comment abc*\\\\def"; // 4 '\' escapes to 2 in a string literal
if (!expected.equals(commentText)) {
throw new AssertionError("Incorrect comment text: [" + commentText + "], expected [" + expected + "]");
}
}
示例2: main
import com.sun.tools.javac.main.JavaCompiler; //导入方法依赖的package包/类
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);
}
示例3: parseWithLombok
import com.sun.tools.javac.main.JavaCompiler; //导入方法依赖的package包/类
protected JCTree parseWithLombok(Source source) {
Context context = new Context();
Options.instance(context).put(OptionName.ENCODING, "UTF-8");
JavaCompiler compiler = new JavaCompiler(context);
compiler.genEndPos = true;
compiler.keepComments = true;
JCCompilationUnit cu = compiler.parse(new ContentBasedJavaFileObject(source.getName(), source.getRawInput()));
JcTreeConverter converter = new JcTreeConverter();
JcTreeBuilder builder = new JcTreeBuilder();
converter.visit(cu);
builder.visit(converter.getResult());
return builder.get();
}
示例4: parseWithTargetCompiler
import com.sun.tools.javac.main.JavaCompiler; //导入方法依赖的package包/类
protected JCTree parseWithTargetCompiler(Source source) throws Exception {
Context context = new Context();
JavaCompiler compiler = new JavaCompiler(context);
compiler.genEndPos = true;
JCTree result = compiler.parse(new ContentBasedJavaFileObject(source.getName(), source.getRawInput()));
return compiler.errorCount() > 0 ? null : result;
}
示例5: parseWithTargetCompiler
import com.sun.tools.javac.main.JavaCompiler; //导入方法依赖的package包/类
protected JCTree parseWithTargetCompiler(Source source) {
Context context = new Context();
Options.instance(context).put(OptionName.ENCODING, "UTF-8");
JavaCompiler compiler = new JavaCompiler(context);
compiler.genEndPos = true;
compiler.keepComments = true;
JCCompilationUnit cu = compiler.parse(new ContentBasedJavaFileObject(source.getName(), source.getRawInput()));
return cu;
}
示例6: parseWithTargetCompiler
import com.sun.tools.javac.main.JavaCompiler; //导入方法依赖的package包/类
protected Node parseWithTargetCompiler(Source source) {
Context context = new Context();
Options.instance(context).put(OptionName.ENCODING, "UTF-8");
CommentCatcher catcher = CommentCatcher.create(context);
JavaCompiler compiler = catcher.getCompiler();
JCCompilationUnit cu = compiler.parse(new ContentBasedJavaFileObject(source.getName(), source.getRawInput()));
JcTreeConverter converter = new JcTreeConverter();
converter.visit(cu);
return converter.getResultWithJavadoc(catcher.getComments(cu));
}
示例7: parse
import com.sun.tools.javac.main.JavaCompiler; //导入方法依赖的package包/类
public JCCompilationUnit parse(String filename) {
ctx = new Context();
manager = new JavacFileManager(ctx, true, null);
JavaCompiler c = com.sun.tools.javac.main.JavaCompiler.instance(ctx);
JCCompilationUnit cu = c.parse(manager.getFileForInput(filename));
return cu;
}
示例8: parseWithJavac
import com.sun.tools.javac.main.JavaCompiler; //导入方法依赖的package包/类
private void parseWithJavac(Source source) {
Context context = new Context();
JavaCompiler compiler = new JavaCompiler(context);
compiler.genEndPos = true;
compiler.parse(new ContentBasedJavaFileObject(source.getName(), source.getRawInput()));
}
示例9: process
import com.sun.tools.javac.main.JavaCompiler; //导入方法依赖的package包/类
@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;
}