use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedPrimitiveType in project checker-framework by typetools.
the class InterningAnnotatedTypeFactory method getUnboxedType.
/**
* Unbox type and replace any interning type annotations with @Interned since all primitives can
* safely use ==. See case 4 in the class comments.
*/
@Override
public AnnotatedPrimitiveType getUnboxedType(AnnotatedDeclaredType type) {
AnnotatedPrimitiveType primitive = super.getUnboxedType(type);
primitive.replaceAnnotation(INTERNED);
return primitive;
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedPrimitiveType in project checker-framework by typetools.
the class AnnotatedTypeFactory method getWidenedType.
/**
* Returns a widened type if applicable, otherwise returns its first argument.
*
* <p>Subclasses should override {@link #getWidenedAnnotations} rather than this method.
*
* @param exprType type to possibly widen
* @param widenedType type to possibly widen to; its annotations are ignored
* @return if widening is applicable, the result of converting {@code type} to the underlying type
* of {@code widenedType}; otherwise {@code type}
*/
public final AnnotatedTypeMirror getWidenedType(AnnotatedTypeMirror exprType, AnnotatedTypeMirror widenedType) {
TypeKind exprKind = exprType.getKind();
TypeKind widenedKind = widenedType.getKind();
if (!TypeKindUtils.isNumeric(widenedKind)) {
// The target type is not a numeric primitive, so primitive widening is not applicable.
return exprType;
}
AnnotatedPrimitiveType exprPrimitiveType;
if (TypeKindUtils.isNumeric(exprKind)) {
exprPrimitiveType = (AnnotatedPrimitiveType) exprType;
} else if (TypesUtils.isNumericBoxed(exprType.getUnderlyingType())) {
exprPrimitiveType = getUnboxedType((AnnotatedDeclaredType) exprType);
} else {
return exprType;
}
switch(TypeKindUtils.getPrimitiveConversionKind(exprPrimitiveType.getKind(), widenedType.getKind())) {
case WIDENING:
return getWidenedPrimitive(exprPrimitiveType, widenedType.getUnderlyingType());
case NARROWING:
return getNarrowedPrimitive(exprPrimitiveType, widenedType.getUnderlyingType());
case SAME:
return exprType;
default:
throw new BugInCF("unhandled PrimitiveConversionKind");
}
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedPrimitiveType in project checker-framework by typetools.
the class AnnotatedTypeFactory method binaryTreeArgTypes.
/**
* Returns the types of the two arguments to a binarya operation, accounting for widening and
* unboxing if applicable.
*
* @param left the type of the left argument of a binary operation
* @param right the type of the right argument of a binary operation
* @return the types of the two arguments
*/
public Pair<AnnotatedTypeMirror, AnnotatedTypeMirror> binaryTreeArgTypes(AnnotatedTypeMirror left, AnnotatedTypeMirror right) {
TypeKind resultTypeKind = TypeKindUtils.widenedNumericType(left.getUnderlyingType(), right.getUnderlyingType());
if (TypeKindUtils.isNumeric(resultTypeKind)) {
TypeMirror resultTypeMirror = types.getPrimitiveType(resultTypeKind);
AnnotatedPrimitiveType leftUnboxed = applyUnboxing(left);
AnnotatedPrimitiveType rightUnboxed = applyUnboxing(right);
AnnotatedPrimitiveType leftWidened = (leftUnboxed.getKind() == resultTypeKind ? leftUnboxed : getWidenedPrimitive(leftUnboxed, resultTypeMirror));
AnnotatedPrimitiveType rightWidened = (rightUnboxed.getKind() == resultTypeKind ? rightUnboxed : getWidenedPrimitive(rightUnboxed, resultTypeMirror));
return Pair.of(leftWidened, rightWidened);
} else {
return Pair.of(left, right);
}
}
Aggregations