1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

2004-09-01 Alain Magloire

Provide IWorkingCopy.getOriginal(ICElement)
	* model/org/eclipse/cdt/core/model/IWorkingCopy.java
	* model/org/eclipse/cdt/internal/core/model/WorkinCopy.java
This commit is contained in:
Alain Magloire 2004-09-02 01:00:25 +00:00
parent 7aa7200573
commit bff7d6fe56
3 changed files with 73 additions and 2 deletions

View file

@ -1,3 +1,9 @@
2004-09-01 Alain Magloire
Provide IWorkingCopy.getOriginal(ICElement)
* model/org/eclipse/cdt/core/model/IWorkingCopy.java
* model/org/eclipse/cdt/internal/core/model/WorkinCopy.java
2004-08-31 Alain Magloire 2004-08-31 Alain Magloire
Fix for 72198 Fix for 72198

View file

@ -75,9 +75,18 @@ public interface IWorkingCopy extends ITranslationUnit{
* getSharedWorkingCopy(IProgressMonitor, IBufferFactory)</code>. * getSharedWorkingCopy(IProgressMonitor, IBufferFactory)</code>.
* A REMOVED CElementDelta is then reported on this working copy. * A REMOVED CElementDelta is then reported on this working copy.
*/ */
void destroy(); void destroy();
/**
* Returns the original element the specified working copy element was created from,
* or <code>null</code> if this is not a working copy element.
*
* @param workingCopyElement the specified working copy element
* @return the original element the specified working copy element was created from,
* or <code>null</code> if this is not a working copy element
*/
ICElement getOriginal(ICElement workingCopyElement);
/** /**
* Returns the original element this working copy was created from, * Returns the original element this working copy was created from,
* or <code>null</code> if this is not a working copy. * or <code>null</code> if this is not a working copy.

View file

@ -13,12 +13,15 @@ package org.eclipse.cdt.internal.core.model;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IBuffer; import org.eclipse.cdt.core.model.IBuffer;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICModelStatusConstants; import org.eclipse.cdt.core.model.ICModelStatusConstants;
import org.eclipse.cdt.core.model.IParent;
import org.eclipse.cdt.core.model.IProblemRequestor; import org.eclipse.cdt.core.model.IProblemRequestor;
import org.eclipse.cdt.core.model.ISourceReference;
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.resources.IFile; import org.eclipse.core.resources.IFile;
@ -162,6 +165,59 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
return this == o; return this == o;
} }
/**
* Returns the original element the specified working copy element was created from,
* or <code>null</code> if this is not a working copy element.
*
* @param workingCopyElement the specified working copy element
* @return the original element the specified working copy element was created from,
* or <code>null</code> if this is not a working copy element
*/
public ICElement getOriginal(ICElement workingCopyElement) {
// It has to come from the same workingCopy, meaning ours.
if (workingCopyElement instanceof ISourceReference) {
ITranslationUnit wunit = ((ISourceReference)workingCopyElement).getTranslationUnit();
if (!wunit.equals(this)) {
return null;
}
} else {
return null;
}
ITranslationUnit tu = getOriginalElement();
if (tu == null) {
return null; // oops !!
}
// look for it.
ICElement element = workingCopyElement;
ArrayList children = new ArrayList();
while (element != null && element.getElementType() != ICElement.C_UNIT) {
children.add(element);
element = element.getParent();
}
ICElement current = tu;
for (int i = children.size()-1; i >= 0; i--) {
ICElement child = (ICElement)children.get(i);
if (current instanceof IParent) {
try {
ICElement[] celems = ((IParent)current).getChildren();
current = null;
for (int j = 0; j < celems.length; ++j) {
if (celems[j].getElementName().equals(child.getElementName()) &&
celems[j].getElementType() == child.getElementType()) {
current = celems[j];
break;
}
}
} catch (CModelException e) {
current = null;
}
}
}
return current;
}
/** /**
* @see org.eclipse.cdt.core.model.IWorkingCopy#getOriginalElement() * @see org.eclipse.cdt.core.model.IWorkingCopy#getOriginalElement()
*/ */