framework.src.org.checkerframework.qualframework.poly.PolyQualHierarchy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of checker Show documentation
Show all versions of checker Show documentation
The Checker Framework enhances Java’s type system to
make it more powerful and useful. This lets software developers
detect and prevent errors in their Java programs.
The Checker Framework includes compiler plug-ins ("checkers")
that find bugs or verify their absence. It also permits you to
write your own compiler plug-ins.
package org.checkerframework.qualframework.poly;
import org.checkerframework.qualframework.base.QualifierHierarchy;
/** A qualifier hierarchy for {@link PolyQual} instances. This class extends
* the underlying subtyping hierarchy with qualifier variables, which are
* handled like Java type variables (JLS 4.10.2 - a type variable is a subtype
* of its upper bound and a supertype of its lower bound).
*/
public class PolyQualHierarchy implements QualifierHierarchy> {
private QualifierHierarchy groundHierarchy;
public PolyQualHierarchy(QualifierHierarchy groundHierarchy) {
this.groundHierarchy = groundHierarchy;
}
@Override
public boolean isSubtype(PolyQual subtype, PolyQual supertype) {
if (subtype.equals(supertype)) {
return true;
}
Q subMax = subtype.getMaximum();
Q superMin = supertype.getMinimum();
return groundHierarchy.isSubtype(subMax, superMin);
}
@Override
public PolyQual leastUpperBound(PolyQual a, PolyQual b) {
if (isSubtype(a, b)) {
return b;
}
if (isSubtype(b, a)) {
return a;
}
Q aMax = a.getMaximum();
Q bMax = b.getMaximum();
Q groundLub = groundHierarchy.leastUpperBound(aMax, bMax);
return new PolyQual.GroundQual(groundLub);
}
@Override
public PolyQual greatestLowerBound(PolyQual a, PolyQual b) {
if (isSubtype(a, b)) {
return a;
}
if (isSubtype(b, a)) {
return b;
}
Q aMin = a.getMinimum();
Q bMin = b.getMinimum();
Q groundGlb = groundHierarchy.greatestLowerBound(aMin, bMin);
return new PolyQual.GroundQual(groundGlb);
}
@Override
public PolyQual getTop() {
return new PolyQual.GroundQual(groundHierarchy.getTop());
}
@Override
public PolyQual getBottom() {
return new PolyQual.GroundQual(groundHierarchy.getBottom());
}
}