use of org.checkerframework.javacutil.TypeSystemError in project checker-framework by typetools.
the class ValueTransfer method refineIntRanges.
/**
* Calculates the result of a binary comparison on a pair of intRange annotations, and refines
* annotations appropriately.
*/
private List<Boolean> refineIntRanges(Node leftNode, AnnotationMirror leftAnno, Node rightNode, AnnotationMirror rightAnno, ComparisonOperators op, CFStore thenStore, CFStore elseStore) {
Range leftRange = getIntRangeFromAnnotation(leftNode, leftAnno);
Range rightRange = getIntRangeFromAnnotation(rightNode, rightAnno);
final Range thenRightRange;
final Range thenLeftRange;
final Range elseRightRange;
final Range elseLeftRange;
switch(op) {
case EQUAL:
thenRightRange = rightRange.refineEqualTo(leftRange);
// Only needs to be computed once.
thenLeftRange = thenRightRange;
elseRightRange = rightRange.refineNotEqualTo(leftRange);
elseLeftRange = leftRange.refineNotEqualTo(rightRange);
break;
case GREATER_THAN:
thenLeftRange = leftRange.refineGreaterThan(rightRange);
thenRightRange = rightRange.refineLessThan(leftRange);
elseRightRange = rightRange.refineGreaterThanEq(leftRange);
elseLeftRange = leftRange.refineLessThanEq(rightRange);
break;
case GREATER_THAN_EQ:
thenRightRange = rightRange.refineLessThanEq(leftRange);
thenLeftRange = leftRange.refineGreaterThanEq(rightRange);
elseLeftRange = leftRange.refineLessThan(rightRange);
elseRightRange = rightRange.refineGreaterThan(leftRange);
break;
case LESS_THAN:
thenLeftRange = leftRange.refineLessThan(rightRange);
thenRightRange = rightRange.refineGreaterThan(leftRange);
elseRightRange = rightRange.refineLessThanEq(leftRange);
elseLeftRange = leftRange.refineGreaterThanEq(rightRange);
break;
case LESS_THAN_EQ:
thenRightRange = rightRange.refineGreaterThanEq(leftRange);
thenLeftRange = leftRange.refineLessThanEq(rightRange);
elseLeftRange = leftRange.refineGreaterThan(rightRange);
elseRightRange = rightRange.refineLessThan(leftRange);
break;
case NOT_EQUAL:
thenRightRange = rightRange.refineNotEqualTo(leftRange);
thenLeftRange = leftRange.refineNotEqualTo(rightRange);
elseRightRange = rightRange.refineEqualTo(leftRange);
// Equality only needs to be computed once.
elseLeftRange = elseRightRange;
break;
default:
throw new TypeSystemError("ValueTransfer: unsupported operation: " + op);
}
createAnnotationFromRangeAndAddToStore(thenStore, thenRightRange, rightNode);
createAnnotationFromRangeAndAddToStore(thenStore, thenLeftRange, leftNode);
createAnnotationFromRangeAndAddToStore(elseStore, elseRightRange, rightNode);
createAnnotationFromRangeAndAddToStore(elseStore, elseLeftRange, leftNode);
// TODO: Refine the type of the comparison.
return null;
}
use of org.checkerframework.javacutil.TypeSystemError in project checker-framework by typetools.
the class UpperBoundAnnotatedTypeFactory method createLTEqLengthOfAnnotation.
/**
* Creates a new @LTEqLengthOf annotation.
*
* @param names the arguments to @LTEqLengthOf
* @return a new @LTEqLengthOf annotation with the given arguments
*/
AnnotationMirror createLTEqLengthOfAnnotation(String... names) {
if (names == null || names.length == 0) {
throw new TypeSystemError("createLTEqLengthOfAnnotation: bad argument %s", Arrays.toString(names));
}
AnnotationBuilder builder = new AnnotationBuilder(getProcessingEnv(), LTEqLengthOf.class);
builder.setValue("value", names);
return builder.build();
}
use of org.checkerframework.javacutil.TypeSystemError in project checker-framework by typetools.
the class UpperBoundAnnotatedTypeFactory method createLTLengthOfAnnotation.
/**
* Creates a new @LTLengthOf annotation.
*
* @param names the arguments to @LTLengthOf
* @return a new @LTLengthOf annotation with the given arguments
*/
AnnotationMirror createLTLengthOfAnnotation(String... names) {
if (names == null || names.length == 0) {
throw new TypeSystemError("createLTLengthOfAnnotation: bad argument %s", Arrays.toString(names));
}
AnnotationBuilder builder = new AnnotationBuilder(getProcessingEnv(), LTLengthOf.class);
builder.setValue("value", names);
return builder.build();
}
use of org.checkerframework.javacutil.TypeSystemError in project checker-framework by typetools.
the class UnitsAnnotatedTypeFactory method addUnitsRelations.
/**
* Look for an @UnitsRelations annotation on the qualifier and add it to the list of
* UnitsRelations.
*
* @param qual the qualifier to investigate
*/
private void addUnitsRelations(Class<? extends Annotation> qual) {
AnnotationMirror am = AnnotationBuilder.fromClass(elements, qual);
for (AnnotationMirror ama : am.getAnnotationType().asElement().getAnnotationMirrors()) {
if (areSameByClass(ama, unitsRelationsAnnoClass)) {
String theclassname = AnnotationUtils.getElementValueClassName(ama, unitsRelationsValueElement).toString();
if (!Signatures.isClassGetName(theclassname)) {
throw new UserError("Malformed class name \"%s\" should be in ClassGetName format in annotation %s", theclassname, ama);
}
Class<?> valueElement;
try {
ClassLoader classLoader = InternalUtils.getClassLoaderForClass(AnnotationUtils.class);
valueElement = Class.forName(theclassname, true, classLoader);
} catch (ClassNotFoundException e) {
String msg = String.format("Could not load class '%s' for field 'value' in annotation %s", theclassname, ama);
throw new UserError(msg, e);
}
Class<? extends UnitsRelations> unitsRelationsClass;
try {
unitsRelationsClass = valueElement.asSubclass(UnitsRelations.class);
} catch (ClassCastException ex) {
throw new UserError("Invalid @UnitsRelations meta-annotation found in %s. " + "@UnitsRelations value %s is not a subclass of " + "org.checkerframework.checker.units.UnitsRelations.", qual, ama);
}
String classname = unitsRelationsClass.getCanonicalName();
if (!getUnitsRel().containsKey(classname)) {
try {
unitsRel.put(classname, unitsRelationsClass.getDeclaredConstructor().newInstance().init(processingEnv));
} catch (Throwable e) {
throw new TypeSystemError("Throwable when instantiating UnitsRelations", e);
}
}
}
}
}
use of org.checkerframework.javacutil.TypeSystemError in project checker-framework by typetools.
the class ElementQualifierHierarchy method getPolymorphicAnnotation.
@Override
@Nullable
public AnnotationMirror getPolymorphicAnnotation(AnnotationMirror start) {
QualifierKind polyKind = getQualifierKind(start).getPolymorphic();
if (polyKind == null) {
return null;
}
AnnotationMirror poly = kindToElementlessQualifier.get(polyKind);
if (poly == null) {
throw new TypeSystemError("Poly %s has an element. Override ElementQualifierHierarchy#getPolymorphicAnnotation.", polyKind);
}
return poly;
}
Aggregations