forked from openkylin/platform_build
Use a typed comparison of floating point field values rather than just a string comparison.
This addresses toolchain issues; see http://code.google.com/p/android/issues/detail?id=994
This commit is contained in:
parent
3caa7cfa04
commit
824b6963bd
|
@ -66,6 +66,40 @@ public class FieldInfo {
|
|||
return parentQName + name();
|
||||
}
|
||||
|
||||
// Check the declared value with a typed comparison, not a string comparison,
|
||||
// to accommodate toolchains with different fp -> string conversions.
|
||||
public boolean valueEquals(FieldInfo other) {
|
||||
// Type mismatch means nonequal, as does a null/non-null mismatch
|
||||
if (!mType.equals(other.mType)
|
||||
|| ((mValue == null) != (other.mValue == null))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Null values are considered equal
|
||||
if (mValue == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Floating point gets an implementation-type comparison; all others just use the string
|
||||
// If float/double parse fails, fall back to string comparison -- it means that it's a
|
||||
// canonical droiddoc-generated constant expression that represents a NaN.
|
||||
try {
|
||||
if (mType.equals("float")) {
|
||||
float val = Float.parseFloat(mValue);
|
||||
float otherVal = Float.parseFloat(other.mValue);
|
||||
return (val == otherVal);
|
||||
} else if (mType.equals("double")) {
|
||||
double val = Double.parseDouble(mValue);
|
||||
double otherVal = Double.parseDouble(other.mValue);
|
||||
return (val == otherVal);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
// fall through
|
||||
}
|
||||
|
||||
return mValue.equals(other.mValue);
|
||||
}
|
||||
|
||||
public boolean isConsistent(FieldInfo fInfo) {
|
||||
fInfo.mExistsInBoth = true;
|
||||
mExistsInBoth = true;
|
||||
|
@ -75,8 +109,8 @@ public class FieldInfo {
|
|||
"Field " + fInfo.qualifiedName() + " has changed type");
|
||||
consistent = false;
|
||||
}
|
||||
if ((mValue != null && !mValue.equals(fInfo.mValue)) ||
|
||||
(mValue == null && fInfo.mValue != null)) {
|
||||
|
||||
if (!this.valueEquals(fInfo)) {
|
||||
Errors.error(Errors.CHANGED_VALUE, fInfo.position(),
|
||||
"Field " + fInfo.qualifiedName() + " has changed value from "
|
||||
+ mValue + " to " + fInfo.mValue);
|
||||
|
|
Loading…
Reference in New Issue