Example usage for org.eclipse.jdt.internal.compiler CompilationResult toString

List of usage examples for org.eclipse.jdt.internal.compiler CompilationResult toString

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler CompilationResult toString.

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:ch.uzh.ifi.seal.changedistiller.ast.java.JavaCompilationUtils.java

License:Apache License

/**
 * Returns the compiled source as a {@link JavaCompilation}.
 * //from   ww  w. j  a  v a 2  s .c o  m
 * @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;
}