Example usage for org.eclipse.jdt.internal.compiler Compiler resolve

List of usage examples for org.eclipse.jdt.internal.compiler Compiler resolve

Introduction

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

Prototype

public CompilationUnitDeclaration resolve(ICompilationUnit sourceUnit, boolean verifyMethods,
        boolean analyzeCode, boolean generateCode) 

Source Link

Document

Internal API used to resolve a given compilation unit.

Usage

From source file:org.codehaus.groovy.eclipse.core.compiler.GroovySnippetCompiler.java

License:Open Source License

@SuppressWarnings({ "unchecked" })
private GroovyCompilationUnitDeclaration internalCompile(String source, String sourcePath) {
    if (sourcePath == null) {
        sourcePath = "Nothing.groovy";
    } else if (!ContentTypeUtils.isGroovyLikeFileName(sourcePath)) {
        sourcePath = sourcePath.concat(".groovy");
    }/*  w w  w  .  jav a  2 s  . co m*/

    Map options = JavaCore.getOptions();
    options.put(CompilerOptions.OPTIONG_BuildGroovyFiles, CompilerOptions.ENABLED);
    Compiler compiler = new CompilationUnitResolver(nameEnvironment,
            DefaultErrorHandlingPolicies.proceedWithAllProblems(), new CompilerOptions(options),
            new Requestor(), new DefaultProblemFactory(), null, true);
    GroovyCompilationUnitDeclaration decl = (GroovyCompilationUnitDeclaration) compiler.resolve(
            new MockCompilationUnit(source.toCharArray(), sourcePath.toCharArray()), true, false, false);
    return decl;
}