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

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

Introduction

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

Prototype

@Override
public boolean isConsistent() 

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  ww  .  j a  v  a  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

/**
 * @exception JavaModelException if setting the source
 *    of the original compilation unit fails
 *///ww  w  . ja va 2 s  .com
protected void executeOperation() throws JavaModelException {
    checkCanceled();

    try {
        beginTask(Messages.element_reconciling, 2);

        CompilationUnit workingCopy = getWorkingCopy();
        boolean wasConsistent = workingCopy.isConsistent();

        // check is problem requestor is active
        IProblemRequestor problemRequestor = workingCopy.getPerWorkingCopyInfo();
        if (problemRequestor != null)
            problemRequestor = ((JavaModelManager.PerWorkingCopyInfo) problemRequestor).getProblemRequestor();
        boolean defaultRequestorIsActive = problemRequestor != null && problemRequestor.isActive();
        IProblemRequestor ownerProblemRequestor = this.workingCopyOwner.getProblemRequestor(workingCopy);
        boolean ownerRequestorIsActive = ownerProblemRequestor != null
                && ownerProblemRequestor != problemRequestor && ownerProblemRequestor.isActive();
        this.requestorIsActive = defaultRequestorIsActive || ownerRequestorIsActive;

        // create the delta builder (this remembers the current content of the cu)
        this.deltaBuilder = new JavaElementDeltaBuilder(workingCopy);

        // make working copy consistent if needed and compute AST if needed
        makeConsistent(workingCopy);

        // notify reconcile participants only if working copy was not consistent or if forcing problem detection
        // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=177319)
        if (!wasConsistent || ((this.reconcileFlags & ICompilationUnit.FORCE_PROBLEM_DETECTION) != 0)) {
            notifyParticipants(workingCopy);

            // recreate ast if one participant reset it
            if (this.ast == null)
                makeConsistent(workingCopy);
        }

        // report problems
        if (this.problems != null && (((this.reconcileFlags & ICompilationUnit.FORCE_PROBLEM_DETECTION) != 0)
                || !wasConsistent)) {
            if (defaultRequestorIsActive) {
                reportProblems(workingCopy, problemRequestor);
            }
            if (ownerRequestorIsActive) {
                reportProblems(workingCopy, ownerProblemRequestor);
            }
        }

        // register the deltas
        // AspectJ Change Begin
        JavaElementDelta delta = getDelta(deltaBuilder);
        if (delta != null) {
            addReconcileDelta(workingCopy, delta);
        }
        // AspectJ Change End
    } finally {
        done();
    }
}

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;
    }/*  w  w  w .j av  a2  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;
        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;
}