本文整理汇总了Java中org.eclipse.jdt.internal.compiler.parser.Parser.parse方法的典型用法代码示例。如果您正苦于以下问题:Java Parser.parse方法的具体用法?Java Parser.parse怎么用?Java Parser.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.internal.compiler.parser.Parser
的用法示例。
在下文中一共展示了Parser.parse方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import org.eclipse.jdt.internal.compiler.parser.Parser; //导入方法依赖的package包/类
@Nullable
private static Node parse(String code) {
CompilerOptions options = new CompilerOptions();
options.complianceLevel = options.sourceLevel = options.targetJDK = ClassFileConstants.JDK1_7;
options.parseLiteralExpressionsAsConstants = true;
ProblemReporter problemReporter = new ProblemReporter(
DefaultErrorHandlingPolicies.exitOnFirstError(), options, new DefaultProblemFactory());
Parser parser = new Parser(problemReporter, options.parseLiteralExpressionsAsConstants);
parser.javadocParser.checkDocComment = false;
EcjTreeConverter converter = new EcjTreeConverter();
org.eclipse.jdt.internal.compiler.batch.CompilationUnit sourceUnit =
new org.eclipse.jdt.internal.compiler.batch.CompilationUnit(code.toCharArray(), "unitTest", "UTF-8");
CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
CompilationUnitDeclaration unit = parser.parse(sourceUnit, compilationResult);
if (unit == null) {
return null;
}
converter.visit(code, unit);
List<? extends Node> nodes = converter.getAll();
for (lombok.ast.Node node : nodes) {
if (node instanceof lombok.ast.CompilationUnit) {
return node;
}
}
return null;
}
示例2: process
import org.eclipse.jdt.internal.compiler.parser.Parser; //导入方法依赖的package包/类
@Override public ASTNode process(Source in, Void irrelevant) throws ConversionProblem {
CompilerOptions compilerOptions = ecjCompilerOptions();
Parser parser = new Parser(new ProblemReporter(
DefaultErrorHandlingPolicies.proceedWithAllProblems(),
compilerOptions,
new DefaultProblemFactory()
), compilerOptions.parseLiteralExpressionsAsConstants);
parser.javadocParser.checkDocComment = true;
CompilationUnit sourceUnit = new CompilationUnit(in.getRawInput().toCharArray(), in.getName(), charset.name());
CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
CompilationUnitDeclaration cud = parser.parse(sourceUnit, compilationResult);
if (cud.hasErrors()) {
throw new ConversionProblem(String.format("Can't read file %s due to parse error: %s", in.getName(), compilationResult.getErrors()[0]));
}
return cud;
}
示例3: parseWithLombok
import org.eclipse.jdt.internal.compiler.parser.Parser; //导入方法依赖的package包/类
@Override
protected ASTNode parseWithLombok(Source source) {
CompilerOptions compilerOptions = ecjCompilerOptions();
Parser parser = new Parser(new ProblemReporter(
DefaultErrorHandlingPolicies.proceedWithAllProblems(),
compilerOptions,
new DefaultProblemFactory()
), compilerOptions.parseLiteralExpressionsAsConstants);
parser.javadocParser.checkDocComment = true;
CompilationUnit sourceUnit = new CompilationUnit(source.getRawInput().toCharArray(), source.getName(), "UTF-8");
CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
CompilationUnitDeclaration cud = parser.parse(sourceUnit, compilationResult);
if (cud.hasErrors()) return null;
EcjTreeConverter converter = new EcjTreeConverter();
converter.visit(source.getRawInput(), cud);
Node lombokized = converter.get();
EcjTreeBuilder builder = new EcjTreeBuilder(source.getRawInput(), source.getName(), ecjCompilerOptions());
builder.visit(lombokized);
return builder.get();
}
示例4: parseWithTargetCompiler
import org.eclipse.jdt.internal.compiler.parser.Parser; //导入方法依赖的package包/类
@Override
protected ASTNode parseWithTargetCompiler(Source source) {
CompilerOptions compilerOptions = ecjCompilerOptions();
Parser parser = new Parser(new ProblemReporter(
DefaultErrorHandlingPolicies.proceedWithAllProblems(),
compilerOptions,
new DefaultProblemFactory()
), compilerOptions.parseLiteralExpressionsAsConstants);
parser.javadocParser.checkDocComment = true;
CompilationUnit sourceUnit = new CompilationUnit(source.getRawInput().toCharArray(), source.getName(), "UTF-8");
CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
CompilationUnitDeclaration cud = parser.parse(sourceUnit, compilationResult);
if (cud.hasErrors()) return null;
return cud;
}
示例5: parseWithTargetCompiler
import org.eclipse.jdt.internal.compiler.parser.Parser; //导入方法依赖的package包/类
@Override
protected ASTNode parseWithTargetCompiler(Source source) {
CompilerOptions compilerOptions = ecjCompilerOptions();
Parser parser = new Parser(new ProblemReporter(
DefaultErrorHandlingPolicies.proceedWithAllProblems(),
compilerOptions,
new DefaultProblemFactory()
), compilerOptions.parseLiteralExpressionsAsConstants);
parser.javadocParser.checkDocComment = true;
CompilationUnit sourceUnit = new CompilationUnit(source.getRawInput().toCharArray(), source.getName(), "UTF-8");
CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
CompilationUnitDeclaration cud = parser.parse(sourceUnit, compilationResult);
if (cud.hasErrors()) return null;
return cud;
}
示例6: parseWithTargetCompiler
import org.eclipse.jdt.internal.compiler.parser.Parser; //导入方法依赖的package包/类
protected Node parseWithTargetCompiler(Source source) {
CompilerOptions compilerOptions = ecjCompilerOptions();
Parser parser = new Parser(new ProblemReporter(
DefaultErrorHandlingPolicies.proceedWithAllProblems(),
compilerOptions,
new DefaultProblemFactory()
), compilerOptions.parseLiteralExpressionsAsConstants);
parser.javadocParser.checkDocComment = true;
CompilationUnit sourceUnit = new CompilationUnit(source.getRawInput().toCharArray(), source.getName(), "UTF-8");
CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
CompilationUnitDeclaration cud = parser.parse(sourceUnit, compilationResult);
if (cud.hasErrors()) return null;
EcjTreeConverter converter = new EcjTreeConverter();
converter.visit(source.getRawInput(), cud);
return converter.get();
}
示例7: parseWithEcj
import org.eclipse.jdt.internal.compiler.parser.Parser; //导入方法依赖的package包/类
private void parseWithEcj(Source source) {
if (VERBOSE) {
CompilerOptions compilerOptions = ecjCompilerOptions();
Parser parser = new Parser(new ProblemReporter(
DefaultErrorHandlingPolicies.proceedWithAllProblems(),
compilerOptions,
new DefaultProblemFactory()
), compilerOptions.parseLiteralExpressionsAsConstants);
parser.javadocParser.checkDocComment = true;
CompilationUnit sourceUnit = new CompilationUnit(source.getRawInput().toCharArray(), source.getName(), "UTF-8");
CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
parser.parse(sourceUnit, compilationResult);
}
}
示例8: parseStatements
import org.eclipse.jdt.internal.compiler.parser.Parser; //导入方法依赖的package包/类
public void parseStatements(Parser parser, CompilationUnitDeclaration unit) {
//fill up the method body with statement
parser.parse(this, unit);
}