FileDocCategorySizeDatePackage
ClassInfo.javaAPI DocAndroid 1.5 API10287Wed May 06 22:41:00 BST 2009com.android.apicheck

ClassInfo

public class ClassInfo extends Object

Fields Summary
private String
mName
private String
mSuperClassName
private boolean
mIsInterface
private boolean
mIsAbstract
private boolean
mIsStatic
private boolean
mIsFinal
private String
mDeprecated
private String
mScope
private List
mInterfaces
private HashMap
mMethods
private HashMap
mFields
private HashMap
mConstructors
private boolean
mExistsInBoth
private PackageInfo
mPackage
private SourcePositionInfo
mSourcePosition
private ClassInfo
mSuperClass
private ClassInfo
mParentClass
Constructors Summary
public ClassInfo(String name, PackageInfo pack, String superClass, boolean isInterface, boolean isAbstract, boolean isStatic, boolean isFinal, String deprecated, String visibility, SourcePositionInfo source, ClassInfo parent)

        mName = name;
        mPackage = pack;
        mSuperClassName = superClass;
        mIsInterface = isInterface;
        mIsAbstract = isAbstract;
        mIsStatic = isStatic;
        mIsFinal = isFinal;
        mDeprecated = deprecated;
        mScope = visibility;
        mInterfaces = new ArrayList<String>();
        mMethods = new HashMap<String, MethodInfo>();
        mFields = new HashMap<String, FieldInfo>();
        mConstructors = new HashMap<String, ConstructorInfo>();
        mExistsInBoth = false;
        mSourcePosition = source;
        mParentClass = parent;
    
Methods Summary
public voidaddConstructor(ConstructorInfo cInfo)

        mConstructors.put(cInfo.getHashableName(), cInfo);
        
    
public voidaddField(FieldInfo fInfo)

        mFields.put(fInfo.qualifiedName(), fInfo);
      
    
public voidaddInterface(java.lang.String name)

        mInterfaces.add(name);
    
public voidaddMethod(MethodInfo mInfo)

        mMethods.put(mInfo.getHashableName(), mInfo);
    
public booleanisConsistent(com.android.apicheck.ClassInfo cl)

        cl.mExistsInBoth = true;
        mExistsInBoth = true;
        boolean consistent = true;

        if (isInterface() != cl.isInterface()) {
            Errors.error(Errors.CHANGED_CLASS, cl.position(),
                    "Class " + cl.qualifiedName()
                    + " changed class/interface declaration");
            consistent = false;
        }
        for (String iface : mInterfaces) {
            if (!cl.mInterfaces.contains(iface)) {
                Errors.error(Errors.REMOVED_INTERFACE, cl.position(),
                        "Class " + qualifiedName() + " no longer implements " + iface);
            }
        }
        for (String iface : cl.mInterfaces) {
          if (!mInterfaces.contains(iface)) {
              Errors.error(Errors.ADDED_INTERFACE, cl.position(),
                      "Added interface " + iface + " to class "
                      + qualifiedName());
              consistent = false;
            }
        }
        
        for (MethodInfo mInfo : mMethods.values()) {
            if (cl.mMethods.containsKey(mInfo.getHashableName())) {
                if (!mInfo.isConsistent(cl.mMethods.get(mInfo.getHashableName()))) {
                    consistent = false;
                }
            } else {
                /* This class formerly provided this method directly, and now does not.
                 * Check our ancestry to see if there's an inherited version that still
                 * fulfills the API requirement.
                 */
                MethodInfo mi = mInfo.containingClass().overriddenMethod(mInfo);
                if (mi == null) {
                    Errors.error(Errors.REMOVED_METHOD, mInfo.position(),
                            "Removed public method " + mInfo.qualifiedName());
                    consistent = false;
                }
            }
        }
        for (MethodInfo mInfo : cl.mMethods.values()) {
            if (!mInfo.isInBoth()) {
                /* Similarly to the above, do not fail if this "new" method is
                 * really an override of an existing superclass method.
                 */
                MethodInfo mi = mInfo.containingClass().overriddenMethod(mInfo);
                if (mi == null) {
                    Errors.error(Errors.ADDED_METHOD, mInfo.position(),
                            "Added public method " + mInfo.qualifiedName());
                    consistent = false;
                }
            }
        }
        
        for (ConstructorInfo mInfo : mConstructors.values()) {
          if (cl.mConstructors.containsKey(mInfo.getHashableName())) {
              if (!mInfo.isConsistent(cl.mConstructors.get(mInfo.getHashableName()))) {
                  consistent = false;
              }
          } else {
              Errors.error(Errors.REMOVED_METHOD, mInfo.position(),
                      "Removed public constructor " + mInfo.prettySignature());
              consistent = false;
          }
        }
        for (ConstructorInfo mInfo : cl.mConstructors.values()) {
            if (!mInfo.isInBoth()) {
                Errors.error(Errors.ADDED_METHOD, mInfo.position(),
                        "Added public constructor " + mInfo.prettySignature());
                consistent = false;
            }
        }
        
        for (FieldInfo mInfo : mFields.values()) {
          if (cl.mFields.containsKey(mInfo.qualifiedName())) {
              if (!mInfo.isConsistent(cl.mFields.get(mInfo.qualifiedName()))) {
                  consistent = false;
              }
          } else {
              Errors.error(Errors.REMOVED_FIELD, mInfo.position(),
                      "Removed field " + mInfo.qualifiedName());
              consistent = false;
          }
        }
        for (FieldInfo mInfo : cl.mFields.values()) {
            if (!mInfo.isInBoth()) {
                Errors.error(Errors.ADDED_FIELD, mInfo.position(),
                        "Added public field " + mInfo.qualifiedName());
                consistent = false;
            }
        }
        
        if (mIsAbstract != cl.mIsAbstract) {
            consistent = false;
            Errors.error(Errors.CHANGED_ABSTRACT, cl.position(),
                    "Class " + cl.qualifiedName() + " changed abstract qualifier");
        }
      
        if (mIsFinal != cl.mIsFinal) {
            consistent = false;
            Errors.error(Errors.CHANGED_FINAL, cl.position(),
                    "Class " + cl.qualifiedName() + " changed final qualifier");
        }
      
        if (mIsStatic != cl.mIsStatic) {
            consistent = false;
            Errors.error(Errors.CHANGED_STATIC, cl.position(),
                    "Class " + cl.qualifiedName() + " changed static qualifier");
        }
     
        if (!mScope.equals(cl.mScope)) {
            consistent = false;
            Errors.error(Errors.CHANGED_SCOPE, cl.position(),
                    "Class " + cl.qualifiedName() + " scope changed from "
                    + mScope + " to " + cl.mScope);
        }
        
        if (!mDeprecated.equals(cl.mDeprecated)) {
            consistent = false;
            Errors.error(Errors.CHANGED_DEPRECATED, cl.position(),
                    "Class " + cl.qualifiedName() + " has changed deprecation state");
        }
        
        if (mSuperClassName != null) {
            if (cl.mSuperClassName == null || !mSuperClassName.equals(cl.mSuperClassName)) {
                consistent = false;
                Errors.error(Errors.CHANGED_SUPERCLASS, cl.position(),
                        "Class " + qualifiedName() + " superclass changed from "
                        + mSuperClassName + " to " + cl.mSuperClassName);
            }
        } else if (cl.mSuperClassName != null) {
            consistent = false;
            Errors.error(Errors.CHANGED_SUPERCLASS, cl.position(),
                    "Class " + qualifiedName() + " superclass changed from "
                    + "null to " + cl.mSuperClassName);
        }
        
        return consistent;
    
public booleanisFinal()

        return mIsFinal;
    
public booleanisInBoth()

        return mExistsInBoth;
    
public booleanisInterface()

        return mIsInterface;
    
public java.lang.Stringname()

        return mName;
    
public MethodInfooverriddenMethod(MethodInfo candidate)

        if (mSuperClass == null) {
            return null;
        }
        
        // does our immediate superclass have it?
        ClassInfo sup = mSuperClass;
        for (MethodInfo mi : sup.mMethods.values()) {
            if (mi.matches(candidate)) {
                // found it
                return mi;
            }
        }

        // no, so recurse
        if (sup.mSuperClass != null) {
            return mSuperClass.overriddenMethod(candidate);
        }
        
        // no parent, so we just don't have it
        return null;
    
public SourcePositionInfoposition()

        return mSourcePosition;
    
public java.lang.StringqualifiedName()

        String parentQName = (mParentClass != null)
                ? (mParentClass.qualifiedName() + ".")
                : "";
        return mPackage.name() + "." + parentQName + name();
    
public voidsetSuperClass(com.android.apicheck.ClassInfo superclass)

        mSuperClass = superclass;
    
public java.lang.StringsuperclassName()

        return mSuperClassName;