* @see #computeLongestInheritancePathToObject(Type)
* @see #getLeastUpperBound(Type)
*/
private static int computeLongestInheritancePathToObject(InterfaceType type, int depth,
HashSet<ClassElement> visitedClasses) {
ClassElement classElement = type.getElement();
// Object case
if (classElement.getSupertype() == null || visitedClasses.contains(classElement)) {
return depth;
}
int longestPath = 1;
try {
visitedClasses.add(classElement);
InterfaceType[] superinterfaces = classElement.getInterfaces();
int pathLength;
if (superinterfaces.length > 0) {
// loop through each of the superinterfaces recursively calling this method and keeping track
// of the longest path to return
for (InterfaceType superinterface : superinterfaces) {
pathLength = computeLongestInheritancePathToObject(
superinterface,
depth + 1,
visitedClasses);
if (pathLength > longestPath) {
longestPath = pathLength;
}
}
}
// finally, perform this same check on the super type
// TODO(brianwilkerson) Does this also need to add in the number of mixin classes?
InterfaceType supertype = classElement.getSupertype();
pathLength = computeLongestInheritancePathToObject(supertype, depth + 1, visitedClasses);
if (pathLength > longestPath) {
longestPath = pathLength;
}
} finally {