Tweak how hashCode and equals works for MethodReferences

This fixes an issue where method references weren't being properly
interned when generating a dex file
This commit is contained in:
Ben Gruver
2013-04-17 00:13:12 -07:00
parent dda097947f
commit 3d5423ed2b
3 changed files with 58 additions and 3 deletions

View File

@ -33,6 +33,7 @@ package org.jf.dexlib2.base.reference;
import com.google.common.collect.Ordering;
import org.jf.dexlib2.iface.reference.MethodReference;
import org.jf.util.CharSequenceUtils;
import org.jf.util.CollectionUtils;
import javax.annotation.Nonnull;
@ -54,7 +55,7 @@ public abstract class BaseMethodReference implements MethodReference {
return getDefiningClass().equals(other.getDefiningClass()) &&
getName().equals(other.getName()) &&
getReturnType().equals(other.getReturnType()) &&
getParameterTypes().equals(other.getParameterTypes());
CharSequenceUtils.listEquals(getParameterTypes(), other.getParameterTypes());
}
return false;
}

View File

@ -77,7 +77,7 @@ public interface MethodReference extends Reference, Comparable<MethodReference>
* int hashCode = getDefiningClass().hashCode();
* hashCode = hashCode*31 + getName().hashCode();
* hashCode = hashCode*31 + getReturnType().hashCode();
* hashCode = hashCode*31 + getParameters().hashCode();
* hashCode = hashCode*31 + CharSequenceUtils.listHashCode(getParameters());
* }</pre>
*
* @return The hash code value for this MethodReference
@ -88,7 +88,10 @@ public interface MethodReference extends Reference, Comparable<MethodReference>
* Compares this MethodReference to another MethodReference for equality.
*
* This MethodReference is equal to another MethodReference if all of it's "fields" are equal. That is, if
* the return values of getDefiningClass(), getName(), getReturnType() and getParameters() are all equal.
* the return values of getDefiningClass(), getName(), getReturnType() and getParameterTypes() are all equal.
*
* Equality for getParameters() should be tested by comparing the string representation of each element. I.e.
* CharSequenceUtils.listEquals(this.getParameterTypes(), other.getParameterTypes())
*
* @param o The object to be compared for equality with this MethodReference
* @return true if the specified object is equal to this MethodReference