Example usage for org.eclipse.jdt.core.dom CompilationUnitResolver resolve

List of usage examples for org.eclipse.jdt.core.dom CompilationUnitResolver resolve

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom CompilationUnitResolver resolve.

Prototype

private CompilationUnitDeclaration resolve(CompilationUnitDeclaration unit,
            org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit, NodeSearcher nodeSearcher,
            boolean verifyMethods, boolean analyzeCode, boolean generateCode) 

Source Link

Usage

From source file:org.eclipse.jdt.core.dom.CompilationUnitResolver.java

License:Open Source License

public static CompilationUnitDeclaration resolve(
        org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit, IJavaProject javaProject,
        List classpaths, NodeSearcher nodeSearcher, Map options, WorkingCopyOwner owner, int flags,
        IProgressMonitor monitor) throws JavaModelException {

    CompilationUnitDeclaration unit = null;
    INameEnvironmentWithProgress environment = null;
    CancelableProblemFactory problemFactory = null;
    CompilationUnitResolver resolver = null;
    try {/*from  w  w  w .j  a va 2s  .com*/
        if (javaProject == null) {
            Classpath[] allEntries = new Classpath[classpaths.size()];
            classpaths.toArray(allEntries);
            environment = new NameEnvironmentWithProgress(allEntries, null, monitor);
        } else {
            environment = new CancelableNameEnvironment((JavaProject) javaProject, owner, monitor);
        }
        problemFactory = new CancelableProblemFactory(monitor);
        CompilerOptions compilerOptions = getCompilerOptions(options,
                (flags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0);
        boolean ignoreMethodBodies = (flags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0;
        compilerOptions.ignoreMethodBodies = ignoreMethodBodies;
        // GROOVY start   
        CompilerUtils.configureOptionsBasedOnNature(compilerOptions, javaProject);
        // GROOVY end
        resolver = new CompilationUnitResolver(environment, getHandlingPolicy(), compilerOptions,
                getRequestor(), problemFactory, monitor, javaProject != null);
        boolean analyzeAndGenerateCode = !ignoreMethodBodies;
        unit = resolver.resolve(null, // no existing compilation unit declaration
                sourceUnit, nodeSearcher, true, // method verification
                analyzeAndGenerateCode, // analyze code
                analyzeAndGenerateCode); // generate code
        if (resolver.hasCompilationAborted) {
            // the bindings could not be resolved due to missing types in name environment
            // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=86541
            CompilationUnitDeclaration unitDeclaration = parse(sourceUnit, nodeSearcher, options, flags);
            final int problemCount = unit.compilationResult.problemCount;
            if (problemCount != 0) {
                unitDeclaration.compilationResult.problems = new CategorizedProblem[problemCount];
                System.arraycopy(unit.compilationResult.problems, 0, unitDeclaration.compilationResult.problems,
                        0, problemCount);
                unitDeclaration.compilationResult.problemCount = problemCount;
            }
            return unitDeclaration;
        }
        if (NameLookup.VERBOSE && environment instanceof CancelableNameEnvironment) {
            CancelableNameEnvironment cancelableNameEnvironment = (CancelableNameEnvironment) environment;
            System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInSourcePackage: " //$NON-NLS-1$
                    + cancelableNameEnvironment.nameLookup.timeSpentInSeekTypesInSourcePackage + "ms"); //$NON-NLS-1$
            System.out.println(Thread.currentThread() + " TIME SPENT in NameLoopkup#seekTypesInBinaryPackage: " //$NON-NLS-1$
                    + cancelableNameEnvironment.nameLookup.timeSpentInSeekTypesInBinaryPackage + "ms"); //$NON-NLS-1$
        }
        return unit;
    } finally {
        if (environment != null) {
            // don't hold a reference to this external object
            environment.setMonitor(null);
        }
        if (problemFactory != null) {
            problemFactory.monitor = null; // don't hold a reference to this external object
        }
    }
}