List of usage examples for org.eclipse.jdt.internal.compiler.parser Parser parse
public void parse(MethodDeclaration md, CompilationUnitDeclaration unit)
From source file:ch.uzh.ifi.seal.changedistiller.ast.java.JavaCompilationUtils.java
License:Apache License
/** * Returns the compiled source as a {@link JavaCompilation}. * /*from w w w.java 2s .c om*/ * @param Java source * to compile * @return the compilation of the Java source * @throws InvalidSyntaxException if the file has syntax errors. */ public static JavaCompilation compile(String source, String fileName) { CompilerOptions options = getDefaultCompilerOptions(); Parser parser = createCommentRecorderParser(options); ICompilationUnit cu = createCompilationUnit(source, fileName); CompilationResult compilationResult = createDefaultCompilationResult(cu, options); JavaCompilation javaCompilation = new JavaCompilation(parser.parse(cu, compilationResult), parser.scanner); if (compilationResult.hasSyntaxError) { throw new InvalidSyntaxException(new String(compilationResult.getFileName()), compilationResult.toString()); } return javaCompilation; }
From source file:ch.uzh.ifi.seal.changedistiller.ast.java.JavaCompilationUtils.java
License:Apache License
/** * Returns the compiled file as a {@link JavaCompilation}. * /*from w ww . j a v a2 s . c o m*/ * @param file * to compile * @param version * of Java used in the file * @return the compilation of the file * @throws InvalidSyntaxException if the file has syntax errors. */ public static JavaCompilation compile(File file, long version) { CompilerOptions options = getDefaultCompilerOptions(version); Parser parser = createCommentRecorderParser(options); ICompilationUnit cu = createCompilationUnit(FileUtils.getContent(file), file.getName()); CompilationResult compilationResult = createDefaultCompilationResult(cu, options); return new JavaCompilation(parser.parse(cu, compilationResult), parser.scanner); }
From source file:ch.uzh.ifi.seal.changedistiller.util.CompilationUtils.java
License:Apache License
public static JavaCompilation compileSource(String source) { CompilerOptions options = getDefaultCompilerOptions(); Parser parser = createCommentRecorderParser(options); ICompilationUnit cu = createCompilationunit(source, ""); CompilationResult compilationResult = createDefaultCompilationResult(cu, options); return new JavaCompilation(parser.parse(cu, compilationResult), parser.scanner); }
From source file:ch.uzh.ifi.seal.changedistiller.util.CompilationUtils.java
License:Apache License
/** * Returns the generated {@link JavaCompilation} from the file identified by the given filename. This method assumes * that the filename is relative to <code>{@value #TEST_DATA_BASE_DIR}</code>. * // w ww . ja v a 2 s . c om * @param filename * of the file to compile (relative to {@value #TEST_DATA_BASE_DIR}). * @return the compilation of the file */ public static JavaCompilation compileFile(String filename) { CompilerOptions options = getDefaultCompilerOptions(); Parser parser = createCommentRecorderParser(options); ICompilationUnit cu = createCompilationunit(getContentOfFile(TEST_DATA_BASE_DIR + filename), filename); CompilationResult compilationResult = createDefaultCompilationResult(cu, options); return new JavaCompilation(parser.parse(cu, compilationResult), parser.scanner); }
From source file:com.android.tools.idea.lint.LombokPsiConverterTest.java
License:Apache License
@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; }//from w w w . j a va 2s. co m 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; }
From source file:lombok.ast.grammar.EcjTreeBuilderTest.java
License:Open Source License
@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;// w w w . ja v a 2 s .c o m }
From source file:lombok.ast.grammar.EcjTreeConverterType1Test.java
License:Open Source License
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(); }
From source file:lombok.ast.grammar.EcjTreeConverterType2Test.java
License:Open Source License
@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);/*from ww w . jav a 2s. c o m*/ return builder.get(); }
From source file:lombok.ast.grammar.EcjTreeConverterType2Test.java
License:Open Source License
@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;// w ww .j a v a 2 s .co m }
From source file:lombok.ast.grammar.PerformanceTest.java
License:Open Source License
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); }//w ww .j a v a2 s .c o m }