use of org.jgrapht.graph.SimpleGraph in project jop by jop-devel.
the class TypeGraph method getInterfaceConflictGraph.
/** Compute the interface conflict graph.<br/>
* Two distinct types A and B conflict if either {@code A <: B} or
* {@code B <: A}, or if A and B share a common descendant.
* Algorithmically, assume A conflicts with B.
* Then either<ul>
* <li/>A is in the <emph>subtype set</emph> of B or vice versa
* <li/>A and B are ancestors of some join node T.
* </ul>
* A join node is a type which is the root of a single inheritance hierarchy,
* but has more than one parent (think: the leaves of the multiple inheritance
* hierarchy).
* <p>
* For detailed information see
* <quote>Vitek, J., Horspool, R. N., and Krall, A. 1997. Efficient type inclusion tests.
* SIGPLAN Not. 32, 10 (Oct. 1997), 142-157.</quote>
* </p>
*
* @return
*/
public SimpleGraph<ClassInfo, DefaultEdge> getInterfaceConflictGraph() {
SimpleGraph<ClassInfo, DefaultEdge> conflicts = new SimpleGraph<ClassInfo, DefaultEdge>(DefaultEdge.class);
Map<ClassInfo, Set<ClassInfo>> ancestors = getSupertypeSets();
Map<ClassInfo, Set<ClassInfo>> subtypes = getSubtypeSets();
for (ClassInfo v : topDownTraversal()) {
if (v.isInterface())
conflicts.addVertex(v);
}
for (ClassInfo a : conflicts.vertexSet()) {
for (ClassInfo b : subtypes.get(a)) {
if (b.isInterface())
conflicts.addEdge(a, b);
}
}
for (ClassInfo joinNode : getJoinNodes()) {
for (ClassInfo a : ancestors.get(joinNode)) {
if (!a.isInterface())
continue;
if (joinNode.isInterface())
conflicts.addEdge(joinNode, a);
for (ClassInfo b : ancestors.get(joinNode)) {
if (b.isInterface() && !a.equals(b))
conflicts.addEdge(a, b);
}
}
}
return conflicts;
}
Aggregations