Search in sources :

Example 6 with AnnotatedPrimitiveType

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;
}
Also used : AnnotatedPrimitiveType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedPrimitiveType)

Example 7 with AnnotatedPrimitiveType

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");
    }
}
Also used : TypeKind(javax.lang.model.type.TypeKind) BugInCF(org.checkerframework.javacutil.BugInCF) AnnotatedPrimitiveType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedPrimitiveType)

Example 8 with AnnotatedPrimitiveType

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);
    }
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) TypeKind(javax.lang.model.type.TypeKind) AnnotatedPrimitiveType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedPrimitiveType)

Aggregations

AnnotatedPrimitiveType (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedPrimitiveType)8 BugInCF (org.checkerframework.javacutil.BugInCF)3 TypeKind (javax.lang.model.type.TypeKind)2 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 AnnotationMirror (javax.lang.model.element.AnnotationMirror)1 PrimitiveType (javax.lang.model.type.PrimitiveType)1 TypeMirror (javax.lang.model.type.TypeMirror)1 AnnotatedTypeVariable (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable)1 QualifierHierarchy (org.checkerframework.framework.type.QualifierHierarchy)1 AnnotationMirrorMap (org.checkerframework.framework.util.AnnotationMirrorMap)1 AnnotationMirrorSet (org.checkerframework.framework.util.AnnotationMirrorSet)1