jdiff
Class APIComparator

java.lang.Object
  extended by jdiff.APIComparator

public class APIComparator
extends java.lang.Object

This class contains method to compare two API objects. The differences are stored in an APIDiff object. See the file LICENSE.txt for copyright details.


Field Summary
 APIDiff apiDiff
          Top-level object representing the differences between two APIs.
 jdiff.PackageDiff pkgDiff
          Package-level object representing the differences between two packages.
 
Constructor Summary
APIComparator()
          Default constructor.
 
Method Summary
static int changedInheritance(java.lang.String oldInherit, java.lang.String newInherit)
          Decide if two elements changed where they were defined.
 boolean compareAllCtors(jdiff.ClassAPI oldClass, jdiff.ClassAPI newClass, jdiff.ClassDiff classDiff)
          Compare all the constructors in two classes.
 boolean compareAllFields(jdiff.ClassAPI oldClass, jdiff.ClassAPI newClass, jdiff.ClassDiff classDiff)
          Compare all the fields in two classes.
 boolean compareAllMethods(jdiff.ClassAPI oldClass, jdiff.ClassAPI newClass, jdiff.ClassDiff classDiff)
          Compare all the methods in two classes.
 void compareAPIs(API oldAPI, API newAPI)
          Compare two APIs.
 double compareClasses(jdiff.ClassAPI oldClass, jdiff.ClassAPI newClass, jdiff.PackageDiff pkgDiff)
          Compare two classes.
 boolean compareMethods(jdiff.MethodAPI oldMethod, jdiff.MethodAPI newMethod, jdiff.ClassDiff classDiff)
          Compare two methods which have the same name.
 double comparePackages(jdiff.PackageAPI oldPkg, jdiff.PackageAPI newPkg)
          Compare two packages.
static boolean docChanged(java.lang.String oldDoc, java.lang.String newDoc)
          Decide if two blocks of documentation changed.
static java.lang.String linkToClass(jdiff.FieldAPI m, boolean useNew)
          Generate a link to the Javadoc page for the given field.
static java.lang.String linkToClass(jdiff.MethodAPI m, boolean useNew)
          Generate a link to the Javadoc page for the given method.
static java.lang.String linkToClass(java.lang.String className, java.lang.String memberName, java.lang.String memberType, boolean useNew)
          Given the name of the class, generate a link to a relevant page.
 int numLocalFields(java.util.List fields)
          Return the number of fields which are locally defined.
 int numLocalMethods(java.util.List methods)
          Return the number of methods which are locally defined.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

apiDiff

public APIDiff apiDiff
Top-level object representing the differences between two APIs. It is this object which is used to generate the report later on.


pkgDiff

public jdiff.PackageDiff pkgDiff
Package-level object representing the differences between two packages. This object is also used to determine which file to write documentation differences into.

Constructor Detail

APIComparator

public APIComparator()
Default constructor.

Method Detail

compareAPIs

public void compareAPIs(API oldAPI,
                        API newAPI)
Compare two APIs.


comparePackages

public double comparePackages(jdiff.PackageAPI oldPkg,
                              jdiff.PackageAPI newPkg)
Compare two packages.


compareClasses

public double compareClasses(jdiff.ClassAPI oldClass,
                             jdiff.ClassAPI newClass,
                             jdiff.PackageDiff pkgDiff)
Compare two classes. Need to compare constructors, methods and fields.


compareAllCtors

public boolean compareAllCtors(jdiff.ClassAPI oldClass,
                               jdiff.ClassAPI newClass,
                               jdiff.ClassDiff classDiff)
Compare all the constructors in two classes. The compareTo method in the ConstructorAPI class acts only upon the type.


compareAllMethods

public boolean compareAllMethods(jdiff.ClassAPI oldClass,
                                 jdiff.ClassAPI newClass,
                                 jdiff.ClassDiff classDiff)
Compare all the methods in two classes. We have to deal with the cases where: - there is only one method with a given name, but its signature changes - there is more than one method with the same name, and some of them may have signature changes The simplest way to deal with this is to make the MethodAPI comparator check the params and return type, as well as the name. This means that changing a parameter's type would cause the method to be seen as removed and added. To avoid this for the simple case, check for before recording a method as removed or added.


compareMethods

public boolean compareMethods(jdiff.MethodAPI oldMethod,
                              jdiff.MethodAPI newMethod,
                              jdiff.ClassDiff classDiff)
Compare two methods which have the same name.


compareAllFields

public boolean compareAllFields(jdiff.ClassAPI oldClass,
                                jdiff.ClassAPI newClass,
                                jdiff.ClassDiff classDiff)
Compare all the fields in two classes.


docChanged

public static boolean docChanged(java.lang.String oldDoc,
                                 java.lang.String newDoc)
Decide if two blocks of documentation changed.

Returns:
true if both are non-null and differ, or if one is null and the other is not.

changedInheritance

public static int changedInheritance(java.lang.String oldInherit,
                                     java.lang.String newInherit)
Decide if two elements changed where they were defined.

Returns:
0 if both are null, or both are non-null and are the same. 1 if the oldInherit was null and newInherit is non-null. 2 if the oldInherit was non-null and newInherit is null. 3 if the oldInherit was non-null and newInherit is non-null and they differ.

linkToClass

public static java.lang.String linkToClass(jdiff.MethodAPI m,
                                           boolean useNew)
Generate a link to the Javadoc page for the given method.


linkToClass

public static java.lang.String linkToClass(jdiff.FieldAPI m,
                                           boolean useNew)
Generate a link to the Javadoc page for the given field.


linkToClass

public static java.lang.String linkToClass(java.lang.String className,
                                           java.lang.String memberName,
                                           java.lang.String memberType,
                                           boolean useNew)
Given the name of the class, generate a link to a relevant page. This was originally for inheritance changes, so the JDiff page could be a class changes page, or a section in a removed or added classes table. Since there was no easy way to tell which type the link should be, it is now just a link to the relevant Javadoc page.


numLocalMethods

public int numLocalMethods(java.util.List methods)
Return the number of methods which are locally defined.


numLocalFields

public int numLocalFields(java.util.List fields)
Return the number of fields which are locally defined.