FileDocCategorySizeDatePackage
ClassDiff.javaAPI DocAndroid 1.5 API5272Wed May 06 22:41:22 BST 2009jdiff

ClassDiff

public class ClassDiff extends Object
The changes between two classes. See the file LICENSE.txt for copyright details.
author
Matthew Doar, mdoar@pobox.com

Fields Summary
public String
name_
Name of the class.
public boolean
isInterface_
Set if this class is an interface in the new API.
public String
inheritanceChange_
A string describing the changes in inheritance.
public String
documentationChange_
A string describing the changes in documentation.
public String
modifiersChange_
A string describing the changes in modifiers. Changes can be in whether this is a class or interface, whether it is abstract, static, final, and in its visibility.
public List
ctorsAdded
Constructors added in the new API.
public List
ctorsRemoved
Constructors removed in the new API.
public List
ctorsChanged
Constructors changed in the new API.
public List
methodsAdded
Methods added in the new API.
public List
methodsRemoved
Methods removed in the new API.
public List
methodsChanged
Methods changed in the new API.
public List
fieldsAdded
Fields added in the new API.
public List
fieldsRemoved
Fields removed in the new API.
public List
fieldsChanged
Fields changed in the new API.
public double
pdiff
Constructors Summary
public ClassDiff(String name)
Default constructor.


       
       
        name_ = name;
        isInterface_ = false;

        ctorsAdded = new ArrayList(); // ConstructorAPI[]
        ctorsRemoved = new ArrayList(); // ConstructorAPI[]
        ctorsChanged = new ArrayList(); // MemberDiff[]

        methodsAdded = new ArrayList(); // MethodAPI[]
        methodsRemoved = new ArrayList(); // MethodAPI[]
        methodsChanged = new ArrayList(); // MemberDiff[]

        fieldsAdded = new ArrayList(); // FieldAPI[]
        fieldsRemoved = new ArrayList(); // FieldAPI[]
        fieldsChanged = new ArrayList(); // MemberDiff[]
    
Methods Summary
public voidaddModifiersChange(java.lang.String commonModifierChanges)
Add a change in the modifiers.

        if (commonModifierChanges != null) {
            if (modifiersChange_ == null)
                modifiersChange_ = commonModifierChanges;
            else
                modifiersChange_ += " " + commonModifierChanges;
        }
    
public static java.lang.Stringdiff(ClassAPI oldClass, ClassAPI newClass)
Compare the inheritance details of two classes and produce a String for the inheritanceChanges_ field in this class. If there is no difference, null is returned.

        Collections.sort(oldClass.implements_);
        Collections.sort(newClass.implements_);
        String res = "";
        boolean hasContent = false;
        if (oldClass.extends_ != null && newClass.extends_ != null &&
            oldClass.extends_.compareTo(newClass.extends_) != 0) {
            res += "The superclass changed from <code>" + oldClass.extends_ + "</code> to <code>" + newClass.extends_ + "</code>.<br>";
            hasContent = true;
        }
        // Check for implemented interfaces which were removed
        String removedInterfaces = "";
        int numRemoved = 0;
        Iterator iter = oldClass.implements_.iterator();
        while (iter.hasNext()) {
            String oldInterface = (String)(iter.next());
            int idx = Collections.binarySearch(newClass.implements_, oldInterface);
            if (idx < 0) {
                if (numRemoved != 0)
                    removedInterfaces += ", ";
                removedInterfaces += oldInterface;
                numRemoved++;
            }
        }
        String addedInterfaces = "";
        int numAdded = 0;
        iter = newClass.implements_.iterator();
        while (iter.hasNext()) {
            String newInterface = (String)(iter.next());
            int idx = Collections.binarySearch(oldClass.implements_, newInterface);
            if (idx < 0) {
                if (numAdded != 0)
                    addedInterfaces += ", ";
                addedInterfaces += newInterface;
                numAdded++;
            }
        }
        if (numRemoved != 0) {
            if (hasContent)
                res += " ";
            if (numRemoved == 1)
                res += "Removed interface <code>" + removedInterfaces + "</code>.<br>";
            else
                res += "Removed interfaces <code>" + removedInterfaces + "</code>.<br>";
            hasContent = true;
        }
        if (numAdded != 0) {
            if (hasContent)
                res += " ";
            if (numAdded == 1)
                res += "Added interface <code>" + addedInterfaces + "</code>.<br>";
            else
                res += "Added interfaces <code>" + addedInterfaces + "</code>.<br>";
            hasContent = true;
        }
        if (res.compareTo("") == 0)
            return null;
        return res;