use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedPrimitiveType in project checker-framework by typetools.
the class AnnotatedTypeFactory method getWidenedPrimitive.
/**
* Returns an AnnotatedPrimitiveType with underlying type {@code widenedTypeMirror} and with
* annotations copied or adapted from {@code type}.
*
* @param type type to widen; a primitive or boxed primitive
* @param widenedTypeMirror underlying type for the returned type mirror; a primitive or boxed
* primitive (same boxing as {@code type})
* @return result of converting {@code type} to {@code widenedTypeMirror}
*/
private AnnotatedPrimitiveType getWidenedPrimitive(AnnotatedPrimitiveType type, TypeMirror widenedTypeMirror) {
AnnotatedPrimitiveType result = (AnnotatedPrimitiveType) AnnotatedTypeMirror.createType(widenedTypeMirror, this, type.isDeclaration());
result.addAnnotations(getWidenedAnnotations(type.getAnnotations(), type.getKind(), result.getKind()));
return result;
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedPrimitiveType in project checker-framework by typetools.
the class AnnotatedTypeFactory method getUnboxedType.
/**
* Returns the annotated primitive type of the given declared type if it is a boxed declared type.
* Otherwise, it throws <i>IllegalArgumentException</i> exception.
*
* <p>In the {@code AnnotatedTypeFactory} implementation, the returned type has the same primary
* annotations as the given type. Subclasses may override this behavior.
*
* @param type the declared type
* @return the unboxed primitive type
* @throws IllegalArgumentException if the type given has no unbox conversion
*/
public AnnotatedPrimitiveType getUnboxedType(AnnotatedDeclaredType type) throws IllegalArgumentException {
PrimitiveType primitiveType = types.unboxedType(type.getUnderlyingType());
AnnotatedPrimitiveType pt = (AnnotatedPrimitiveType) AnnotatedTypeMirror.createType(primitiveType, this, false);
pt.addAnnotations(type.getAnnotations());
return pt;
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedPrimitiveType in project checker-framework by typetools.
the class AnnotatedTypeFactory method getNarrowedPrimitive.
/**
* Returns AnnotatedPrimitiveType with underlying type {@code narrowedTypeMirror} and with
* annotations copied or adapted from {@code type}.
*
* <p>Currently this method is called only for primitives that are narrowed at assignments from
* literal ints, for example, {@code byte b = 1;}. All other narrowing conversions happen at
* typecasts.
*
* @param type type to narrow
* @param narrowedTypeMirror underlying type for the returned type mirror
* @return result of converting {@code type} to {@code narrowedTypeMirror}
*/
public AnnotatedPrimitiveType getNarrowedPrimitive(AnnotatedPrimitiveType type, TypeMirror narrowedTypeMirror) {
AnnotatedPrimitiveType narrowed = (AnnotatedPrimitiveType) AnnotatedTypeMirror.createType(narrowedTypeMirror, this, type.isDeclaration());
narrowed.addAnnotations(type.getAnnotations());
return narrowed;
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedPrimitiveType in project checker-framework by typetools.
the class TypeArgInferenceUtil method leastUpperBound.
/**
* Successively calls least upper bound on the elements of types. Unlike leastUpperBound, this
* method will box primitives if necessary
*/
public static AnnotatedTypeMirror leastUpperBound(final AnnotatedTypeFactory typeFactory, final Iterable<AnnotatedTypeMirror> types) {
final Iterator<AnnotatedTypeMirror> typesIter = types.iterator();
if (!typesIter.hasNext()) {
throw new BugInCF("Calling LUB on empty list");
}
AnnotatedTypeMirror lubType = typesIter.next();
AnnotatedTypeMirror nextType = null;
while (typesIter.hasNext()) {
nextType = typesIter.next();
if (lubType.getKind().isPrimitive()) {
if (!nextType.getKind().isPrimitive()) {
lubType = typeFactory.getBoxedType((AnnotatedPrimitiveType) lubType);
}
} else if (nextType.getKind().isPrimitive()) {
if (!lubType.getKind().isPrimitive()) {
nextType = typeFactory.getBoxedType((AnnotatedPrimitiveType) nextType);
}
}
lubType = AnnotatedTypes.leastUpperBound(typeFactory, lubType, nextType);
}
return lubType;
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedPrimitiveType in project checker-framework by typetools.
the class SupertypesSolver method leastUpperBound.
/**
* Successively calls least upper bound on the elements of types. Unlike
* AnnotatedTypes.leastUpperBound, this method will box primitives if necessary
*/
public static AnnotatedTypeMirror leastUpperBound(final TypeVariable target, final AnnotatedTypeFactory typeFactory, final Map<AnnotatedTypeMirror, AnnotationMirrorSet> types) {
QualifierHierarchy qualifierHierarchy = typeFactory.getQualifierHierarchy();
AnnotatedTypeVariable targetsDeclaredType = (AnnotatedTypeVariable) typeFactory.getAnnotatedType(target.asElement());
final AnnotationMirrorMap<AnnotationMirror> lowerBoundAnnos = TypeArgInferenceUtil.createHierarchyMap(new AnnotationMirrorSet(targetsDeclaredType.getLowerBound().getEffectiveAnnotations()), qualifierHierarchy);
final Iterator<Map.Entry<AnnotatedTypeMirror, AnnotationMirrorSet>> typesIter = types.entrySet().iterator();
if (!typesIter.hasNext()) {
throw new BugInCF("Calling LUB on empty list.");
}
/**
* If a constraint implies that a type parameter Ti is a supertype of an annotated type mirror
* Ai but only in a subset of all qualifier hierarchies then for all other qualifier hierarchies
* replace the primary annotation on Ai with the lowest possible annotation (ensuring that it
* won't be the LUB unless there are no other constraints, or all other constraints imply the
* bottom annotation is the LUB). Note: Even if we choose bottom as the lub here, the assignment
* context may raise this annotation.
*/
final Map.Entry<AnnotatedTypeMirror, AnnotationMirrorSet> head = typesIter.next();
AnnotatedTypeMirror lubType = groundMissingHierarchies(head, lowerBoundAnnos);
AnnotatedTypeMirror nextType = null;
while (typesIter.hasNext()) {
nextType = groundMissingHierarchies(typesIter.next(), lowerBoundAnnos);
if (lubType.getKind().isPrimitive()) {
if (!nextType.getKind().isPrimitive()) {
lubType = typeFactory.getBoxedType((AnnotatedPrimitiveType) lubType);
}
} else if (nextType.getKind().isPrimitive()) {
if (!lubType.getKind().isPrimitive()) {
nextType = typeFactory.getBoxedType((AnnotatedPrimitiveType) nextType);
}
}
lubType = AnnotatedTypes.leastUpperBound(typeFactory, lubType, nextType);
}
return lubType;
}
Aggregations