mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
new method getElementAtOffset()
This commit is contained in:
parent
c4af8be231
commit
61416ad865
2 changed files with 30 additions and 1 deletions
|
@ -93,7 +93,7 @@ public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISource
|
||||||
* unit itself at the given position, or if the given position is not
|
* unit itself at the given position, or if the given position is not
|
||||||
* within the source range of this translation unit.
|
* within the source range of this translation unit.
|
||||||
*
|
*
|
||||||
* @param position a source position inside the translation unit
|
* @param line a position inside the translation unit
|
||||||
* @return the innermost C element enclosing a given source position or <code>null</code>
|
* @return the innermost C element enclosing a given source position or <code>null</code>
|
||||||
* if none (excluding the translation unit).
|
* if none (excluding the translation unit).
|
||||||
* @exception CModelException if the translation unit does not exist or if an
|
* @exception CModelException if the translation unit does not exist or if an
|
||||||
|
@ -101,6 +101,21 @@ public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISource
|
||||||
*/
|
*/
|
||||||
ICElement getElementAtLine(int line) throws CModelException;
|
ICElement getElementAtLine(int line) throws CModelException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the smallest element within this translation unit that
|
||||||
|
* includes the given source position (that is, a method, field, etc.), or
|
||||||
|
* <code>null</code> if there is no element other than the translation
|
||||||
|
* unit itself at the given position, or if the given position is not
|
||||||
|
* within the source range of this translation unit.
|
||||||
|
*
|
||||||
|
* @param position a source position inside the translation unit
|
||||||
|
* @return the innermost C element enclosing a given source position or <code>null</code>
|
||||||
|
* if none (excluding the translation unit).
|
||||||
|
* @exception CModelException if the translation unit does not exist or if an
|
||||||
|
* exception occurs while accessing its corresponding resource
|
||||||
|
*/
|
||||||
|
ICElement getElementAtOffset(int offset) throws CModelException;
|
||||||
|
|
||||||
ICElement getElement(String name) throws CModelException;
|
ICElement getElement(String name) throws CModelException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -69,6 +69,19 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ICElement getElementAtOffset(int pos) throws CModelException {
|
||||||
|
ICElement[] celements = getChildren();
|
||||||
|
for (int i = 0; i < celements.length; i++) {
|
||||||
|
ISourceRange range = ((ISourceReference)celements[i]).getSourceRange();
|
||||||
|
int startPos = range.getStartPos();
|
||||||
|
int endPos = startPos + range.getLength();
|
||||||
|
if (pos >= startPos && pos <= endPos) {
|
||||||
|
return celements[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public ICElement getElement(String name ) {
|
public ICElement getElement(String name ) {
|
||||||
ICElement[] celements = getChildren();
|
ICElement[] celements = getChildren();
|
||||||
for (int i = 0; i < celements.length; i++) {
|
for (int i = 0; i < celements.length; i++) {
|
||||||
|
@ -250,6 +263,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
|
||||||
* @see Object#equals(java.lang.Object)
|
* @see Object#equals(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
|
if (!(o instanceof ITranslationUnit)) return false;
|
||||||
return super.equals(o) && !((ITranslationUnit)o).isWorkingCopy();
|
return super.equals(o) && !((ITranslationUnit)o).isWorkingCopy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue