return firstCommonSupertype;
}
private ObjectType computeFirstCommonSuperclassOfObjectTypes(ObjectType a, ObjectType b) throws ClassNotFoundException {
ObjectType firstCommonSupertype;
ClassDescriptor aDesc = DescriptorFactory.getClassDescriptor(a);
ClassDescriptor bDesc = DescriptorFactory.getClassDescriptor(b);
ClassVertex aVertex = resolveClassVertex(aDesc);
ClassVertex bVertex = resolveClassVertex(bDesc);
Set<ClassDescriptor> aSuperTypes = computeKnownSupertypes(aDesc);
Set<ClassDescriptor> bSuperTypes = computeKnownSupertypes(bDesc);
if (bSuperTypes.contains(aDesc)) {
return a;
}
if (aSuperTypes.contains(bDesc)) {
return b;
}
ArrayList<ClassVertex> aSuperList = getAllSuperclassVertices(aVertex);
ArrayList<ClassVertex> bSuperList = getAllSuperclassVertices(bVertex);
// Work backwards until the lists diverge.
// The last element common to both lists is the first
// common superclass.
int aIndex = aSuperList.size() - 1;
int bIndex = bSuperList.size() - 1;
ClassVertex lastCommonInBackwardsSearch = null;
while (aIndex >= 0 && bIndex >= 0) {
if (aSuperList.get(aIndex) != bSuperList.get(bIndex)) {
break;
}
lastCommonInBackwardsSearch = aSuperList.get(aIndex);
aIndex--;
bIndex--;
}
if (lastCommonInBackwardsSearch == null) {
firstCommonSupertype = Type.OBJECT;
} else {
firstCommonSupertype = ObjectTypeFactory.getInstance(lastCommonInBackwardsSearch.getClassDescriptor()
.toDottedClassName());
}
if (firstCommonSupertype.equals(Type.OBJECT)) {
// see if we can't do better
ClassDescriptor objDesc = DescriptorFactory.getClassDescriptor(Type.OBJECT);
aSuperTypes.retainAll(bSuperTypes);
aSuperTypes.remove(objDesc);
for (ClassDescriptor c : aSuperTypes) {
if (c.getPackageName().equals(aDesc.getPackageName()) || c.getPackageName().equals(bDesc.getPackageName())) {
return ObjectTypeFactory.getInstance(c.toDottedClassName());