jdiff

Class APIComparator

public class APIComparator extends 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
APIDiffapiDiff
Top-level object representing the differences between two APIs.
PackageDiffpkgDiff
Package-level object representing the differences between two packages.
Constructor Summary
APIComparator()
Default constructor.
Method Summary
static intchangedInheritance(String oldInherit, String newInherit)
Decide if two elements changed where they were defined.
booleancompareAllCtors(ClassAPI oldClass, ClassAPI newClass, ClassDiff classDiff)
Compare all the constructors in two classes.
booleancompareAllFields(ClassAPI oldClass, ClassAPI newClass, ClassDiff classDiff)
Compare all the fields in two classes.
booleancompareAllMethods(ClassAPI oldClass, ClassAPI newClass, ClassDiff classDiff)
Compare all the methods in two classes.
voidcompareAPIs(API oldAPI, API newAPI)
Compare two APIs.
doublecompareClasses(ClassAPI oldClass, ClassAPI newClass, PackageDiff pkgDiff)
Compare two classes.
booleancompareMethods(MethodAPI oldMethod, MethodAPI newMethod, ClassDiff classDiff)
Compare two methods which have the same name.
doublecomparePackages(PackageAPI oldPkg, PackageAPI newPkg)
Compare two packages.
static booleandocChanged(String oldDoc, String newDoc)
Decide if two blocks of documentation changed.
static StringlinkToClass(MethodAPI m, boolean useNew)
Generate a link to the Javadoc page for the given method.
static StringlinkToClass(FieldAPI m, boolean useNew)
Generate a link to the Javadoc page for the given field.
static StringlinkToClass(String className, String memberName, String memberType, boolean useNew)
Given the name of the class, generate a link to a relevant page.
intnumLocalFields(List fields)
Return the number of fields which are locally defined.
intnumLocalMethods(List methods)
Return the number of methods which are locally defined.

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 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

changedInheritance

public static int changedInheritance(String oldInherit, 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.

compareAllCtors

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

compareAllFields

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

compareAllMethods

public boolean compareAllMethods(ClassAPI oldClass, ClassAPI newClass, 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.

compareAPIs

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

compareClasses

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

compareMethods

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

comparePackages

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

docChanged

public static boolean docChanged(String oldDoc, 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.

linkToClass

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

linkToClass

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

linkToClass

public static String linkToClass(String className, String memberName, 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.

numLocalFields

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

numLocalMethods

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