/*
 * Copyright (C) 2008 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.apicheck;

public class FieldInfo {
  
    private String mName;
    private String mType;
    private boolean mIsTransient;
    private boolean mIsVolatile;
    private String mValue;
    private boolean mIsStatic;
    private boolean mIsFinal;
    private String mDeprecated;
    private String mScope;
    private boolean mExistsInBoth;
    private SourcePositionInfo mSourcePosition;
    private ClassInfo mClass;
    
    public FieldInfo (String name, String type, boolean isTransient, boolean isVolatile,
                       String value, boolean isStatic, boolean isFinal, String deprecated,
                       String scope, SourcePositionInfo source, ClassInfo parent) {
        mName = name;
        mType = type;
        mIsTransient = isTransient;
        mIsVolatile = isVolatile;
        mValue = value;
        mIsStatic = isStatic;
        mIsFinal = isFinal;
        mDeprecated = deprecated;
        mScope = scope;
        mExistsInBoth = false;
        mSourcePosition = source;
        mClass = parent;
    }
    
    public boolean isInBoth() {
        return mExistsInBoth;
    }
    public SourcePositionInfo position() {
        return mSourcePosition;
    }
    
    public String name() {
        return mName;
    }
    
    public String qualifiedName() {
        String parentQName = (mClass != null)
                ? (mClass.qualifiedName() + ".")
                : "";
        return parentQName + name();
    }
    
    public boolean isConsistent(FieldInfo fInfo) {
      fInfo.mExistsInBoth = true;
      mExistsInBoth = true;
      boolean consistent = true;
      if (!mType.equals(fInfo.mType)) {
          Errors.error(Errors.CHANGED_TYPE, fInfo.position(),
                  "Field " + fInfo.qualifiedName() + " has changed type");
          consistent = false;
      }
      if ((mValue != null && !mValue.equals(fInfo.mValue)) || 
          (mValue == null && fInfo.mValue != null)) {
          Errors.error(Errors.CHANGED_VALUE, fInfo.position(),
                  "Field " + fInfo.qualifiedName() + " has changed value from "
                  + mValue + " to " + fInfo.mValue);
          consistent = false;
      }
      
      if (!mScope.equals(fInfo.mScope)) {
          Errors.error(Errors.CHANGED_SCOPE, fInfo.position(),
                  "Method " + fInfo.qualifiedName() + " changed scope from "
                  + mScope + " to " + fInfo.mScope);
          consistent = false;
      }
      
      if (mIsStatic != fInfo.mIsStatic) {
          Errors.error(Errors.CHANGED_STATIC, fInfo.position(),
                  "Field " + fInfo.qualifiedName() + " has changed 'static' qualifier");
          consistent = false;
      }
      
      if (mIsFinal != fInfo.mIsFinal) {
          Errors.error(Errors.CHANGED_FINAL, fInfo.position(),
                  "Field " + fInfo.qualifiedName() + " has changed 'final' qualifier");
          consistent = false;
      }
      
      if (mIsTransient != fInfo.mIsTransient) {
          Errors.error(Errors.CHANGED_TRANSIENT, fInfo.position(),
                  "Field " + fInfo.qualifiedName() + " has changed 'transient' qualifier");
          consistent = false;
      }
      
      if (mIsVolatile != fInfo.mIsVolatile) {
          Errors.error(Errors.CHANGED_VOLATILE, fInfo.position(),
                  "Field " + fInfo.qualifiedName() + " has changed 'volatile' qualifier");
          consistent = false;
      }
      
      return consistent;
    }

}

@@ -2083,32 +2083,1428 @@
 e();%0A    %7D%0A    %0A
+    // Check the declared value with a typed comparison, not a string comparison,%0A    // to accommodate toolchains with different fp -%3E string conversions.%0A    public boolean valueEquals(FieldInfo other) %7B%0A        // Type mismatch means nonequal, as does a null/non-null mismatch%0A        if (!mType.equals(other.mType)%0A                %7C%7C ((mValue == null) != (other.mValue == null))) %7B%0A            return false;%0A        %7D%0A%0A        // Null values are considered equal%0A        if (mValue == null) %7B%0A            return true;%0A        %7D%0A%0A        // Floating point gets an implementation-type comparison; all others just use the string%0A        // If float/double parse fails, fall back to string comparison -- it means that it's a%0A        // canonical droiddoc-generated constant expression that represents a NaN.%0A        try %7B%0A            if (mType.equals(%22float%22)) %7B%0A                float val = Float.parseFloat(mValue);%0A                float otherVal = Float.parseFloat(other.mValue);%0A                return (val == otherVal);%0A            %7D else if (mType.equals(%22double%22)) %7B%0A                double val = Double.parseDouble(mValue);%0A                double otherVal = Double.parseDouble(other.mValue);%0A                return (val == otherVal);%0A            %7D%0A        %7D catch (NumberFormatException e) %7B%0A            // fall through%0A        %7D%0A        %0A        return mValue.equals(other.mValue);%0A    %7D%0A%0A
     public boole
@@ -3534,24 +3534,24 @@
 fo fInfo) %7B%0A
-
       fInfo.
@@ -3844,24 +3844,25 @@
 se;%0A      %7D%0A
+%0A
       if ((m
@@ -3863,36 +3863,20 @@
 if (
-(mValue != null && !mV
+!this.v
 alue
-.e
+E
 qual
@@ -3886,71 +3886,8 @@
 Info
-.mValue)) %7C%7C %0A          (mValue == null && fInfo.mValue != null
 )) %7B

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