mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 02:06:01 +02:00
Fixes bug 112366; adds CModel notifications during rename refactoring.
This commit is contained in:
parent
7af727a38e
commit
af6000c0e0
1 changed files with 78 additions and 40 deletions
|
@ -6,7 +6,8 @@
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Rational Software - Initial API and implementation
|
* Rational Software - Initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.model;
|
package org.eclipse.cdt.internal.core.model;
|
||||||
|
|
||||||
|
@ -18,8 +19,11 @@ import org.eclipse.cdt.core.model.ICModelStatus;
|
||||||
import org.eclipse.cdt.core.model.ICModelStatusConstants;
|
import org.eclipse.cdt.core.model.ICModelStatusConstants;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||||
|
import org.eclipse.core.filebuffers.ITextFileBuffer;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.resources.IWorkspace;
|
import org.eclipse.core.resources.IWorkspace;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.IAdaptable;
|
||||||
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,52 +76,86 @@ public class CommitWorkingCopyOperation extends CModelOperation {
|
||||||
protected void executeOperation() throws CModelException {
|
protected void executeOperation() throws CModelException {
|
||||||
try {
|
try {
|
||||||
beginTask("workingCopy.commit", 2); //$NON-NLS-1$
|
beginTask("workingCopy.commit", 2); //$NON-NLS-1$
|
||||||
WorkingCopy copy = (WorkingCopy)getElementToProcess();
|
WorkingCopy wc = (WorkingCopy)getElementToProcess();
|
||||||
ITranslationUnit original = copy.getOriginalElement();
|
ITranslationUnit tu = wc.getOriginalElement();
|
||||||
|
|
||||||
|
|
||||||
// creates the delta builder (this remembers the content of the cu)
|
// creates the delta builder (this remembers the content of the cu)
|
||||||
if (!original.isOpen()) {
|
if (!tu.isOpen()) {
|
||||||
// force opening so that the delta builder can get the old info
|
// force opening so that the delta builder can get the old info
|
||||||
original.open(null);
|
tu.open(null);
|
||||||
}
|
}
|
||||||
CElementDeltaBuilder deltaBuilder = new CElementDeltaBuilder(original);
|
CElementDeltaBuilder deltaBuilder = new CElementDeltaBuilder(tu);
|
||||||
|
|
||||||
// save the cu
|
// save the translation unit
|
||||||
IBuffer originalBuffer = original.getBuffer();
|
boolean hasSaved = false;
|
||||||
if (originalBuffer == null) return;
|
IBuffer tuBuffer = tu.getBuffer();
|
||||||
char[] originalContents = originalBuffer.getCharacters();
|
IBuffer wcBuffer = wc.getBuffer();
|
||||||
boolean hasSaved = false;
|
if (wcBuffer == null || tuBuffer == null) {
|
||||||
try {
|
return;
|
||||||
IBuffer copyBuffer = copy.getBuffer();
|
}
|
||||||
if (copyBuffer == null) return;
|
ITextFileBuffer tuFileBuffer= null;
|
||||||
originalBuffer.setContents(copyBuffer.getCharacters());
|
ITextFileBuffer wcFileBuffer= null;
|
||||||
original.save(fMonitor, fForce);
|
if (tuBuffer instanceof IAdaptable) {
|
||||||
this.hasModifiedResource = true;
|
tuFileBuffer= (ITextFileBuffer) ((IAdaptable) tuBuffer).getAdapter(ITextFileBuffer.class);
|
||||||
hasSaved = true;
|
}
|
||||||
} finally {
|
if (wcBuffer instanceof IAdaptable) {
|
||||||
if (!hasSaved){
|
wcFileBuffer= (ITextFileBuffer) ((IAdaptable) wcBuffer).getAdapter(ITextFileBuffer.class);
|
||||||
// restore original buffer contents since something went wrong
|
}
|
||||||
originalBuffer.setContents(originalContents);
|
|
||||||
}
|
if (wcFileBuffer != null) {
|
||||||
}
|
if (wcFileBuffer.equals(tuFileBuffer)) {
|
||||||
// make sure working copy is in sync
|
// working on the same buffer, saving the translation unit does the trick.
|
||||||
copy.updateTimeStamp((TranslationUnit)original);
|
tu.save(fMonitor, fForce);
|
||||||
copy.makeConsistent(this);
|
hasSaved= true;
|
||||||
worked(1);
|
}
|
||||||
|
else {
|
||||||
if (deltaBuilder != null) {
|
if (wcFileBuffer.getLocation().equals(tu.getPath())) {
|
||||||
// build the deltas
|
char[] originalContents = tuBuffer.getCharacters();
|
||||||
deltaBuilder.buildDeltas();
|
try {
|
||||||
|
// save the file buffer of the working copy.
|
||||||
// add the deltas to the list of deltas created during this operation
|
wcFileBuffer.commit(fMonitor, fForce);
|
||||||
if (deltaBuilder.delta != null) {
|
// change the buffer of the translation unit.
|
||||||
addDelta(deltaBuilder.delta);
|
tuBuffer.setContents(wcBuffer.getCharacters());
|
||||||
}
|
tu.makeConsistent(null);
|
||||||
}
|
hasSaved= true;
|
||||||
worked(1);
|
} catch (CoreException e) {
|
||||||
|
tuBuffer.setContents(originalContents);
|
||||||
|
throw new CModelException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasSaved) {
|
||||||
|
char[] originalContents = tuBuffer.getCharacters();
|
||||||
|
try {
|
||||||
|
tuBuffer.setContents(wcBuffer.getCharacters());
|
||||||
|
tu.save(fMonitor, fForce);
|
||||||
|
} catch (CModelException e) {
|
||||||
|
tuBuffer.setContents(originalContents);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.hasModifiedResource = true;
|
||||||
|
// make sure working copy is in sync
|
||||||
|
wc.updateTimeStamp((TranslationUnit)tu);
|
||||||
|
wc.makeConsistent(this);
|
||||||
|
|
||||||
|
worked(1);
|
||||||
|
|
||||||
|
if (deltaBuilder != null) {
|
||||||
|
// build the deltas
|
||||||
|
deltaBuilder.buildDeltas();
|
||||||
|
|
||||||
|
// add the deltas to the list of deltas created during this operation
|
||||||
|
if (deltaBuilder.delta != null) {
|
||||||
|
addDelta(deltaBuilder.delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
worked(1);
|
||||||
} finally {
|
} finally {
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue