Merge "fix searching of ancestors for removed methods"

This commit is contained in:
Vasu Nori
2010-05-03 13:24:00 -07:00
committed by Android (Google) Code Review

View File

@@ -86,41 +86,35 @@ public class ClassInfo {
return mIsFinal; return mIsFinal;
} }
// Find a superclass implementation of the given method. Looking at our superclass // Find a superclass implementation of the given method.
// instead of at 'this' is unusual, but it fits the point-of-call demands well. public static MethodInfo overriddenMethod(MethodInfo candidate, ClassInfo newClassObj) {
public MethodInfo overriddenMethod(MethodInfo candidate) { if (newClassObj == null) {
if (mSuperClass == null) {
return null; return null;
} }
for (MethodInfo mi : newClassObj.mMethods.values()) {
// does our immediate superclass have it?
ClassInfo sup = mSuperClass;
for (MethodInfo mi : sup.mMethods.values()) {
if (mi.matches(candidate)) { if (mi.matches(candidate)) {
// found it // found it
return mi; return mi;
} }
} }
// no, so recurse // not found here. recursively search ancestors
if (sup.mSuperClass != null) { return ClassInfo.overriddenMethod(candidate, newClassObj.mSuperClass);
return mSuperClass.overriddenMethod(candidate);
}
// no parent, so we just don't have it
return null;
} }
// Find a superinterface declaration of the given method. // Find a superinterface declaration of the given method.
public MethodInfo interfaceMethod(MethodInfo candidate) { public static MethodInfo interfaceMethod(MethodInfo candidate, ClassInfo newClassObj) {
for (ClassInfo interfaceInfo : mInterfaces) { if (newClassObj == null) {
return null;
}
for (ClassInfo interfaceInfo : newClassObj.mInterfaces) {
for (MethodInfo mi : interfaceInfo.mMethods.values()) { for (MethodInfo mi : interfaceInfo.mMethods.values()) {
if (mi.matches(candidate)) { if (mi.matches(candidate)) {
return mi; return mi;
} }
} }
} }
return (mSuperClass != null) ? mSuperClass.interfaceMethod(candidate) : null; return ClassInfo.interfaceMethod(candidate, newClassObj.mSuperClass);
} }
public boolean isConsistent(ClassInfo cl) { public boolean isConsistent(ClassInfo cl) {
@@ -159,9 +153,9 @@ public class ClassInfo {
* Check our ancestry to see if there's an inherited version that still * Check our ancestry to see if there's an inherited version that still
* fulfills the API requirement. * fulfills the API requirement.
*/ */
MethodInfo mi = mInfo.containingClass().overriddenMethod(mInfo); MethodInfo mi = ClassInfo.overriddenMethod(mInfo, cl);
if (mi == null) { if (mi == null) {
mi = mInfo.containingClass().interfaceMethod(mInfo); mi = ClassInfo.interfaceMethod(mInfo, cl);
} }
if (mi == null) { if (mi == null) {
Errors.error(Errors.REMOVED_METHOD, mInfo.position(), Errors.error(Errors.REMOVED_METHOD, mInfo.position(),
@@ -175,7 +169,7 @@ public class ClassInfo {
/* Similarly to the above, do not fail if this "new" method is /* Similarly to the above, do not fail if this "new" method is
* really an override of an existing superclass method. * really an override of an existing superclass method.
*/ */
MethodInfo mi = mInfo.containingClass().overriddenMethod(mInfo); MethodInfo mi = ClassInfo.overriddenMethod(mInfo, cl);
if (mi == null) { if (mi == null) {
Errors.error(Errors.ADDED_METHOD, mInfo.position(), Errors.error(Errors.ADDED_METHOD, mInfo.position(),
"Added public method " + mInfo.qualifiedName()); "Added public method " + mInfo.qualifiedName());