Example usage for org.eclipse.jdt.internal.core CompilationUnit makeConsistent

List of usage examples for org.eclipse.jdt.internal.core CompilationUnit makeConsistent

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core CompilationUnit makeConsistent.

Prototype

public org.eclipse.jdt.core.dom.CompilationUnit makeConsistent(int astLevel, boolean resolveBindings,
            int reconcileFlags, HashMap problems, IProgressMonitor monitor) throws JavaModelException 

Source Link

Usage

From source file:org.codehaus.jdt.groovy.model.GroovyReconcileWorkingCopyOperation.java

License:Open Source License

public org.eclipse.jdt.core.dom.CompilationUnit makeConsistent(CompilationUnit workingCopy)
        throws JavaModelException {
    if (!workingCopy.isConsistent()) {
        // make working copy consistent
        if (this.problems == null)
            this.problems = new HashMap();
        this.resolveBindings = this.requestorIsActive;
        this.ast = workingCopy.makeConsistent(this.astLevel, this.resolveBindings, this.reconcileFlags,
                this.problems, this.progressMonitor);
        this.deltaBuilder.buildDeltas();
        if (this.ast != null && this.deltaBuilder.delta != null)
            this.deltaBuilder.delta.changedAST(this.ast);
        return this.ast;
    }//from   w  w w .  ja  va  2 s .  c o m
    if (this.ast != null)
        return this.ast; // no need to recompute AST if known already

    CompilationUnitDeclaration unit = null;
    try {
        JavaModelManager.getJavaModelManager().abortOnMissingSource.set(Boolean.TRUE);
        CompilationUnit source = workingCopy.cloneCachingContents();
        // find problems if needed
        if (JavaProject.hasJavaNature(workingCopy.getJavaProject().getProject())
                && (this.reconcileFlags & ICompilationUnit.FORCE_PROBLEM_DETECTION) != 0) {
            this.resolveBindings = this.requestorIsActive;
            if (this.problems == null)
                this.problems = new HashMap();
            unit = CompilationUnitProblemFinder.process(source, this.workingCopyOwner, this.problems,
                    this.astLevel != ICompilationUnit.NO_AST/* creating AST if level is not NO_AST */,
                    this.reconcileFlags, this.progressMonitor);
            // GROOVY cache the ModuleNode in the ModuleNodeMapper
            if (unit instanceof GroovyCompilationUnitDeclaration) {
                // should always be true
                ModuleNodeMapper.getInstance().maybeCacheModuleNode(workingCopy.getPerWorkingCopyInfo(),
                        (GroovyCompilationUnitDeclaration) unit);
            }
            // GROOVY end

            if (this.progressMonitor != null)
                this.progressMonitor.worked(1);
        }

        // create AST if needed
        if (this.astLevel != ICompilationUnit.NO_AST && unit != null/*
                                                                    * unit is null if working copy is consistent && (problem
                                                                    * detection not forced || non-Java project) -> don't create
                                                                    * AST as per API
                                                                    */) {
            Map options = workingCopy.getJavaProject().getOptions(true);
            // convert AST
            this.ast = AST.convertCompilationUnit(this.astLevel, unit, options, this.resolveBindings, source,
                    this.reconcileFlags, this.progressMonitor);
            if (this.ast != null) {
                if (this.deltaBuilder.delta == null) {
                    this.deltaBuilder.delta = new JavaElementDelta(workingCopy);
                }
                this.deltaBuilder.delta.changedAST(this.ast);
            }
            if (this.progressMonitor != null)
                this.progressMonitor.worked(1);
        }
    } catch (JavaModelException e) {
        if (JavaProject.hasJavaNature(workingCopy.getJavaProject().getProject()))
            throw e;
        // else JavaProject has lost its nature (or most likely was closed/deleted) while reconciling -> ignore
        // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=100919)
    } finally {
        JavaModelManager.getJavaModelManager().abortOnMissingSource.set(null);
        if (unit != null) {
            unit.cleanUp();
        }
    }
    return this.ast;
}

From source file:org.eclipse.ajdt.core.reconcile.AJReconcileWorkingCopyOperation.java

License:Open Source License

public org.eclipse.jdt.core.dom.CompilationUnit makeConsistent(CompilationUnit workingCopy)
        throws JavaModelException {
    if (!workingCopy.isConsistent()) {
        // make working copy consistent
        if (this.problems == null)
            this.problems = new HashMap();
        this.resolveBindings = this.requestorIsActive;
        this.ast = workingCopy.makeConsistent(this.astLevel, this.resolveBindings, reconcileFlags,
                this.problems, this.progressMonitor);
        this.deltaBuilder.buildDeltas();
        if (this.ast != null && this.deltaBuilder.delta != null)
            this.deltaBuilder.delta.changedAST(this.ast);
        return this.ast;
    }//from  w  w w . j a v  a  2 s.com
    if (this.ast != null)
        return this.ast; // no need to recompute AST if known already

    CompilationUnitDeclaration unit = null;
    try {
        JavaModelManager.getJavaModelManager().abortOnMissingSource.set(Boolean.TRUE);
        CompilationUnit source;
        if (workingCopy instanceof AJCompilationUnit) {
            source = ((AJCompilationUnit) workingCopy).ajCloneCachingContents();
        } else {
            source = workingCopy.cloneCachingContents();
        }
        // find problems if needed
        if (JavaProject.hasJavaNature(workingCopy.getJavaProject().getProject())
                && (this.reconcileFlags & ICompilationUnit.FORCE_PROBLEM_DETECTION) != 0) {
            this.resolveBindings = this.requestorIsActive;
            if (this.problems == null)
                this.problems = new HashMap();
            unit = AJCompilationUnitProblemFinder.processAJ(source, this.workingCopyOwner, this.problems,
                    this.astLevel != ICompilationUnit.NO_AST/*creating AST if level is not NO_AST */,
                    reconcileFlags, this.progressMonitor);
            if (this.progressMonitor != null)
                this.progressMonitor.worked(1);
        }

        // create AST if needed
        if (this.astLevel != ICompilationUnit.NO_AST
                && unit != null/*unit is null if working copy is consistent && (problem detection not forced || non-Java project) -> don't create AST as per API*/) {
            Map options = workingCopy.getJavaProject().getOptions(true);
            // convert AST
            this.ast = AST.convertCompilationUnit(this.astLevel, unit, options, this.resolveBindings, source,
                    reconcileFlags, this.progressMonitor);
            if (this.ast != null) {
                if (this.deltaBuilder.delta == null) {
                    this.deltaBuilder.delta = new JavaElementDelta(workingCopy);
                }
                this.deltaBuilder.delta.changedAST(this.ast);
            }
            if (this.progressMonitor != null)
                this.progressMonitor.worked(1);
        }
    } catch (JavaModelException e) {
        if (JavaProject.hasJavaNature(workingCopy.getJavaProject().getProject()))
            throw e;
        // else JavaProject has lost its nature (or most likely was closed/deleted) while reconciling -> ignore
        // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=100919)
    } finally {
        JavaModelManager.getJavaModelManager().abortOnMissingSource.set(null);
        if (unit != null) {
            unit.cleanUp();
        }
    }
    return this.ast;
}