Example usage for org.eclipse.jdt.internal.core JavaElementDeltaBuilder buildDeltas

List of usage examples for org.eclipse.jdt.internal.core JavaElementDeltaBuilder buildDeltas

Introduction

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

Prototype

public void buildDeltas() 

Source Link

Document

Builds the java element deltas between the old content of the compilation unit and its new content.

Usage

From source file:org.eclipse.jdt.internal.core.JavaModelManager.java

License:Open Source License

public int discardPerWorkingCopyInfo(CompilationUnit workingCopy) throws JavaModelException {

    // create the delta builder (this remembers the current content of the working copy)
    // outside the perWorkingCopyInfos lock (see bug 50667)
    JavaElementDeltaBuilder deltaBuilder = null;
    if (workingCopy.isPrimary() && workingCopy.hasUnsavedChanges()) {
        deltaBuilder = new JavaElementDeltaBuilder(workingCopy);
    }/*from ww w .  ja  v a2s .com*/
    PerWorkingCopyInfo info = null;
    synchronized (this.perWorkingCopyInfos) {
        WorkingCopyOwner owner = workingCopy.owner;
        Map workingCopyToInfos = (Map) this.perWorkingCopyInfos.get(owner);
        if (workingCopyToInfos == null)
            return -1;

        info = (PerWorkingCopyInfo) workingCopyToInfos.get(workingCopy);
        if (info == null)
            return -1;

        if (--info.useCount == 0) {
            // remove per working copy info
            workingCopyToInfos.remove(workingCopy);
            if (workingCopyToInfos.isEmpty()) {
                this.perWorkingCopyInfos.remove(owner);
            }
        }
    }
    if (info.useCount == 0) { // info cannot be null here (check was done above)
        // remove infos + close buffer (since no longer working copy)
        // outside the perWorkingCopyInfos lock (see bug 50667)
        removeInfoAndChildren(workingCopy);
        workingCopy.closeBuffer();

        // compute the delta if needed and register it if there are changes
        if (deltaBuilder != null) {
            deltaBuilder.buildDeltas();
            if (deltaBuilder.delta != null) {
                getDeltaProcessor().registerJavaModelDelta(deltaBuilder.delta);
            }
        }
    }
    return info.useCount;
}