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

2004-09-02 Alain Magloire

Fix to TranslationUnit.getElement(String).
	* model/org/eclipse/cdt/internal/core/model/TranslationUnit.java
	* model/org/eclipse/cdt/internal/core/model/WorkingCopy.java
This commit is contained in:
Alain Magloire 2004-09-02 17:05:39 +00:00
parent 69ecf16572
commit 043f79d100
3 changed files with 42 additions and 23 deletions

View file

@ -1,3 +1,9 @@
2004-09-02 Alain Magloire
Fix to TranslationUnit.getElement(String).
* model/org/eclipse/cdt/internal/core/model/TranslationUnit.java
* model/org/eclipse/cdt/internal/core/model/WorkingCopy.java
2004-09-01 Alain Magloire 2004-09-01 Alain Magloire
Provide IWorkingCopy.getOriginal(ICElement) Provide IWorkingCopy.getOriginal(ICElement)

View file

@ -101,16 +101,30 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
} }
public ICElement getElement(String name ) { public ICElement getElement(String name ) {
if (name == null || name.length() == 0) {
return null;
}
String[] names = name.split("::");
ICElement current = this;
for (int j = 0; j < names.length; ++j) {
if (current instanceof IParent) {
try { try {
ICElement[] celements = getChildren(); ICElement[] celements = ((IParent)current).getChildren();
current = null;
for (int i = 0; i < celements.length; i++) { for (int i = 0; i < celements.length; i++) {
if (name.equals(celements[i].getElementName())) { if (names[j].equals(celements[i].getElementName())) {
return celements[i]; current = celements[i];
break;
} }
} }
} catch (CModelException e) { } catch (CModelException e) {
current = null;
} }
return null; } else {
current = null;
}
}
return current;
} }
public IInclude getInclude(String name) { public IInclude getInclude(String name) {
@ -377,13 +391,11 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
if (workingCopy != null) { if (workingCopy != null) {
workingCopy.useCount++; workingCopy.useCount++;
return workingCopy; return workingCopy;
}
} else {
CreateWorkingCopyOperation op = new CreateWorkingCopyOperation(this, perFactoryWorkingCopies, factory, requestor); CreateWorkingCopyOperation op = new CreateWorkingCopyOperation(this, perFactoryWorkingCopies, factory, requestor);
runOperation(op, monitor); runOperation(op, monitor);
return (IWorkingCopy)op.getResultElements()[0]; return (IWorkingCopy)op.getResultElements()[0];
} }
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ITranslationUnit#getWorkingCopy() * @see org.eclipse.cdt.core.model.ITranslationUnit#getWorkingCopy()

View file

@ -212,6 +212,8 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
} catch (CModelException e) { } catch (CModelException e) {
current = null; current = null;
} }
} else {
current = null;
} }
} }
return current; return current;
@ -282,7 +284,7 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
public void open(IProgressMonitor monitor) throws CModelException { public void open(IProgressMonitor monitor) throws CModelException {
if (this.useCount == 0) { // was destroyed if (this.useCount == 0) { // was destroyed
throw newNotPresentException(); throw newNotPresentException();
} else { }
super.open(monitor); super.open(monitor);
//if (monitor != null && monitor.isCanceled()) return; //if (monitor != null && monitor.isCanceled()) return;
//if (this.problemRequestor != null && this.problemRequestor.isActive()){ //if (this.problemRequestor != null && this.problemRequestor.isActive()){
@ -291,7 +293,6 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
// this.problemRequestor.endReporting(); // this.problemRequestor.endReporting();
//} //}
} }
}
/** /**
* @see org.eclipse.cdt.internal.core.model.CFile#openBuffer(IProgressMonitor) * @see org.eclipse.cdt.internal.core.model.CFile#openBuffer(IProgressMonitor)
*/ */