Allow multiple ClassDefItems to share a single empty ClassDataItem

This commit is contained in:
Ben Gruver 2012-09-03 17:00:45 -07:00
parent ed33c426e7
commit b58433a074

View File

@ -392,6 +392,17 @@ public class ClassDataItem extends Item<ClassDataItem> {
/** {@inheritDoc} */ /** {@inheritDoc} */
public int compareTo(ClassDataItem other) { public int compareTo(ClassDataItem other) {
// An empty CodeDataItem may be shared by multiple ClassDefItems, so we can't use parent in this case
if (isEmpty()) {
if (other.isEmpty()) {
return 0;
}
return -1;
}
if (other.isEmpty()) {
return 1;
}
if (parent == null) { if (parent == null) {
if (other.parent == null) { if (other.parent == null) {
return 0; return 0;
@ -409,7 +420,7 @@ public class ClassDataItem extends Item<ClassDataItem> {
* @param classDefItem the <code>ClassDefItem</code> that this <code>ClassDataItem</code> is associated with * @param classDefItem the <code>ClassDefItem</code> that this <code>ClassDataItem</code> is associated with
*/ */
protected void setParent(ClassDefItem classDefItem) { protected void setParent(ClassDefItem classDefItem) {
Preconditions.checkState(parent == null || parent.compareTo(classDefItem) == 0); Preconditions.checkState(parent == null || parent.compareTo(classDefItem) == 0 || isEmpty());
parent = classDefItem; parent = classDefItem;
} }
@ -497,6 +508,14 @@ public class ClassDataItem extends Item<ClassDataItem> {
return virtualMethods.length; return virtualMethods.length;
} }
/**
* @return true if this is an empty ClassDataItem
*/
public boolean isEmpty() {
return (getStaticFieldCount() + getInstanceFieldCount() +
getDirectMethodCount() + getVirtualMethodCount()) == 0;
}
/** /**
* Performs a binary search for the definition of the specified direct method * Performs a binary search for the definition of the specified direct method
* @param methodIdItem The MethodIdItem of the direct method to search for * @param methodIdItem The MethodIdItem of the direct method to search for