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 |
APIDiff | apiDiff
Top-level object representing the differences between two APIs.
|
PackageDiff | pkgDiff
Package-level object representing the differences between two packages.
|
Method Summary |
static int | changedInheritance(String oldInherit, String newInherit)
Decide if two elements changed where they were defined.
|
boolean | compareAllCtors(ClassAPI oldClass, ClassAPI newClass, ClassDiff classDiff)
Compare all the constructors in two classes.
|
boolean | compareAllFields(ClassAPI oldClass, ClassAPI newClass, ClassDiff classDiff)
Compare all the fields in two classes. |
boolean | compareAllMethods(ClassAPI oldClass, ClassAPI newClass, ClassDiff classDiff)
Compare all the methods in two classes.
|
void | compareAPIs(API oldAPI, API newAPI)
Compare two APIs. |
double | compareClasses(ClassAPI oldClass, ClassAPI newClass, PackageDiff pkgDiff)
Compare two classes.
|
boolean | compareMethods(MethodAPI oldMethod, MethodAPI newMethod, ClassDiff classDiff)
Compare two methods which have the same name. |
double | comparePackages(PackageAPI oldPkg, PackageAPI newPkg)
Compare two packages. |
static boolean | docChanged(String oldDoc, String newDoc)
Decide if two blocks of documentation changed.
|
static String | linkToClass(MethodAPI m, boolean useNew)
Generate a link to the Javadoc page for the given method. |
static String | linkToClass(FieldAPI m, boolean useNew)
Generate a link to the Javadoc page for the given field. |
static String | linkToClass(String className, String memberName, String memberType, boolean useNew)
Given the name of the class, generate a link to a relevant page.
|
int | numLocalFields(List fields)
Return the number of fields which are locally defined. |
int | numLocalMethods(List methods)
Return the number of methods which are locally defined. |
Top-level object representing the differences between two APIs.
It is this object which is used to generate the report later on.
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.
public APIComparator()
Default constructor.
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.
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.
public boolean compareAllFields(ClassAPI oldClass, ClassAPI newClass, ClassDiff classDiff)
Compare all the fields in two classes.
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.
public void compareAPIs(
API oldAPI,
API newAPI)
Compare two APIs.
public double compareClasses(ClassAPI oldClass, ClassAPI newClass, PackageDiff pkgDiff)
Compare two classes.
Need to compare constructors, methods and fields.
public boolean compareMethods(MethodAPI oldMethod, MethodAPI newMethod, ClassDiff classDiff)
Compare two methods which have the same name.
public double comparePackages(PackageAPI oldPkg, PackageAPI newPkg)
Compare two packages.
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.
public static String linkToClass(MethodAPI m, boolean useNew)
Generate a link to the Javadoc page for the given method.
public static String linkToClass(FieldAPI m, boolean useNew)
Generate a link to the Javadoc page for the given field.
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.
public int numLocalFields(List fields)
Return the number of fields which are locally defined.
public int numLocalMethods(List methods)
Return the number of methods which are locally defined.