当前位置: 首页>>代码示例>>Java>>正文


Java JavaCompiler.parse方法代码示例

本文整理汇总了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 + "]");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:T4910483.java

示例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);
}
 
开发者ID:evant,项目名称:android-retrolambda-lombok,代码行数:19,代码来源:JcTreePrinter.java

示例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();
}
 
开发者ID:evant,项目名称:android-retrolambda-lombok,代码行数:17,代码来源:JcTreeConverterType2Test.java

示例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;
}
 
开发者ID:evant,项目名称:android-retrolambda-lombok,代码行数:8,代码来源:JcTreeBuilderTest.java

示例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;
}
 
开发者ID:evant,项目名称:android-retrolambda-lombok,代码行数:13,代码来源:JcTreeConverterType2Test.java

示例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));
}
 
开发者ID:evant,项目名称:android-retrolambda-lombok,代码行数:14,代码来源:JcTreeConverterType1Test.java

示例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;
}
 
开发者ID:jesusc,项目名称:eclectic,代码行数:9,代码来源:NativeJavaParser.java

示例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()));
}
 
开发者ID:evant,项目名称:android-retrolambda-lombok,代码行数:7,代码来源:PerformanceTest.java

示例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;
}
 
开发者ID:evant,项目名称:android-retrolambda-lombok,代码行数:14,代码来源:Main.java


注:本文中的com.sun.tools.javac.main.JavaCompiler.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。