framework.src.org.checkerframework.qualframework.poly.CombiningOperation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of checker-qual Show documentation
Show all versions of checker-qual Show documentation
Checker Qual is the set of annotations (qualifiers) and supporting classes
used by the Checker Framework to type check Java source code. Please
see artifact:
org.checkerframework:checker
package org.checkerframework.qualframework.poly;
import org.checkerframework.qualframework.base.QualifierHierarchy;
/** A binary operation for combining qualifiers of type {@code Q}.
*/
public interface CombiningOperation {
/** Apply the operation to two qualifiers, producing a new qualifier. The
* operation is expected to be commutative and associative.
*/
Q combine(Q a, Q b);
/** The identity element for this operation. It should always be the case
* that {@code op.combine(op.identity(), x)} is equivalent to {@code x}.
*/
Q identity();
/** The least-upper-bound operation over a qualifier hierarchy.
*/
public static class Lub implements CombiningOperation {
QualifierHierarchy hierarchy;
public Lub(QualifierHierarchy hierarchy) {
this.hierarchy = hierarchy;
}
@Override
public Q combine(Q a, Q b) {
return hierarchy.leastUpperBound(a, b);
}
@Override
public Q identity() {
return hierarchy.getBottom();
}
@Override
public boolean equals(Object o) {
if (o == null || o.getClass() != this.getClass()) {
return false;
}
@SuppressWarnings("rawtypes")
Lub other = (Lub)o;
return this.hierarchy.equals(other.hierarchy);
}
@Override
public int hashCode() {
return this.hierarchy.hashCode();
}
@Override
public String toString() {
return "Lub";
}
}
/** The greatest-lower-bound operation over a qualifier hierarchy.
*/
public static class Glb implements CombiningOperation {
QualifierHierarchy hierarchy;
public Glb(QualifierHierarchy hierarchy) {
this.hierarchy = hierarchy;
}
@Override
public Q combine(Q a, Q b) {
return hierarchy.greatestLowerBound(a, b);
}
@Override
public Q identity() {
return hierarchy.getTop();
}
@Override
public boolean equals(Object o) {
if (o == null || o.getClass() != this.getClass()) {
return false;
}
@SuppressWarnings("rawtypes")
Glb other = (Glb)o;
return this.hierarchy.equals(other.hierarchy);
}
@Override
public int hashCode() {
return this.hierarchy.hashCode();
}
@Override
public String toString() {
return "Glb";
}
}
}