Add Item.isPlaced() method and replace getOffset() != -1 with !isPlaced() in ClassDefItem

This commit is contained in:
Ben Gruver 2012-06-05 13:43:19 -07:00
parent e5466fee23
commit d320d6ce8c
2 changed files with 11 additions and 2 deletions

View File

@ -324,7 +324,7 @@ public class ClassDefItem extends Item<ClassDefItem> {
} }
private void placeClass(ClassDefItem classDefItem) { private void placeClass(ClassDefItem classDefItem) {
if (classDefItem.getOffset() == -1) { if (!classDefItem.isPlaced()) {
TypeIdItem superType = classDefItem.superType; TypeIdItem superType = classDefItem.superType;
ClassDefItem superClassDefItem = unplacedClassDefsByType.get(superType); ClassDefItem superClassDefItem = unplacedClassDefsByType.get(superType);

View File

@ -189,6 +189,7 @@ public abstract class Item<T extends Item> implements Comparable<T> {
/** /**
* Note that the item must have been placed before calling this method (See <code>DexFile.place()</code>)
* @return the offset in the dex file where this item is located * @return the offset in the dex file where this item is located
*/ */
public int getOffset() { public int getOffset() {
@ -198,7 +199,8 @@ public abstract class Item<T extends Item> implements Comparable<T> {
} }
/** /**
* @return the index of this item within the item's containing section * Note that the item must have been placed before calling this method (See <code>DexFile.place()</code>)
* @return the index of this item within the item's containing section.
*/ */
public int getIndex() { public int getIndex() {
Preconditions.checkState(index != -1, Preconditions.checkState(index != -1,
@ -206,6 +208,13 @@ public abstract class Item<T extends Item> implements Comparable<T> {
return index; return index;
} }
/**
* @return True if this item has been placed, otherwise False
*/
public boolean isPlaced() {
return offset != -1;
}
/** /**
* @return the <code>DexFile</code> that contains this item * @return the <code>DexFile</code> that contains this item
*/ */