mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Added getNodeAt method.
This commit is contained in:
parent
9baef31940
commit
3318cff1ea
1 changed files with 39 additions and 9 deletions
|
@ -8,6 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX - Initial API and implementation
|
* QNX - Initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
|
* Sergey Prigogin (Google)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.cdt.internal.core.pdom.db;
|
package org.eclipse.cdt.internal.core.pdom.db;
|
||||||
|
@ -55,16 +56,17 @@ public class PDOMNodeLinkedList {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void accept(IPDOMVisitor visitor) throws CoreException {
|
public void accept(IPDOMVisitor visitor) throws CoreException {
|
||||||
ListItem firstItem = getFirstMemberItem();
|
Database db = pdom.getDB();
|
||||||
if (firstItem == null)
|
int firstItem = db.getInt(offset + FIRST_MEMBER);
|
||||||
|
if (firstItem == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ListItem item = firstItem;
|
int item = firstItem;
|
||||||
do {
|
do {
|
||||||
PDOMNode node;
|
PDOMNode node;
|
||||||
final int record= item.getItem();
|
final int record= db.getInt(item + ListItem.ITEM);
|
||||||
if(record==0) {
|
if (record == 0) {
|
||||||
if(!allowsNull) {
|
if (!allowsNull) {
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
}
|
}
|
||||||
node= null;
|
node= null;
|
||||||
|
@ -75,8 +77,7 @@ public class PDOMNodeLinkedList {
|
||||||
node.accept(visitor);
|
node.accept(visitor);
|
||||||
}
|
}
|
||||||
visitor.leave(node);
|
visitor.leave(node);
|
||||||
item = item.getNext();
|
} while ((item = db.getInt(item + ListItem.NEXT)) != firstItem);
|
||||||
} while (!item.equals(firstItem));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ListItem getFirstMemberItem() throws CoreException {
|
private ListItem getFirstMemberItem() throws CoreException {
|
||||||
|
@ -85,6 +86,35 @@ public class PDOMNodeLinkedList {
|
||||||
return item != 0 ? new ListItem(db, item) : null;
|
return item != 0 ? new ListItem(db, item) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns node at position {@code pos}. Not recommended to be used in a loop since
|
||||||
|
* such a loop would be more expensive that a single {@code accept(IPDOMVisitor)} call.
|
||||||
|
* @param pos A zero-based position in the list.
|
||||||
|
* @return The node at position {@code pos}, or {@code null} if no such node exists.
|
||||||
|
*/
|
||||||
|
public PDOMNode getNodeAt(int pos) throws CoreException {
|
||||||
|
Database db = pdom.getDB();
|
||||||
|
int firstItem = db.getInt(offset + FIRST_MEMBER);
|
||||||
|
if (firstItem == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
int item = firstItem;
|
||||||
|
do {
|
||||||
|
if (--pos < 0) {
|
||||||
|
int record = db.getInt(item + ListItem.ITEM);
|
||||||
|
if (record == 0) {
|
||||||
|
if (!allowsNull) {
|
||||||
|
throw new NullPointerException();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return linkage.getNode(record);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while ((item = db.getInt(item + ListItem.NEXT)) != firstItem);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public void addMember(PDOMNode member) throws CoreException {
|
public void addMember(PDOMNode member) throws CoreException {
|
||||||
addMember(allowsNull && member==null ? 0 : member.getRecord());
|
addMember(allowsNull && member==null ? 0 : member.getRecord());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue