use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedArrayType in project checker-framework by typetools.
the class AtmLubVisitor method visitArray_Array.
@Override
public Void visitArray_Array(AnnotatedArrayType type1, AnnotatedArrayType type2, AnnotatedTypeMirror lub) {
AnnotatedArrayType lubArray = castLub(type1, lub);
lubPrimaryAnnotations(type1, type2, lubArray);
visit(type1.getComponentType(), type2.getComponentType(), lubArray.getComponentType());
return null;
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedArrayType in project checker-framework by typetools.
the class BaseTypeVisitor method checkVarargs.
/**
* A helper method to check that the array type of actual varargs is a subtype of the
* corresponding required varargs, and issues "argument.invalid" error if it's not a subtype of
* the required one.
*
* <p>Note it's required that type checking for each element in varargs is executed by the
* caller before or after calling this method.
*
* @see #checkArguments(List, List)
* @param invokedMethod the method type to be invoked
* @param tree method or constructor invocation tree
*/
protected void checkVarargs(AnnotatedExecutableType invokedMethod, Tree tree) {
if (!invokedMethod.isVarArgs()) {
return;
}
List<AnnotatedTypeMirror> formals = invokedMethod.getParameterTypes();
int numFormals = formals.size();
int lastArgIndex = numFormals - 1;
AnnotatedArrayType lastParamAnnotatedType = (AnnotatedArrayType) formals.get(lastArgIndex);
// We will skip type checking so that we avoid duplicating error message
// if the last argument is same depth with the depth of formal varargs
// because type checking is already done in checkArguments.
List<? extends ExpressionTree> args;
switch(tree.getKind()) {
case METHOD_INVOCATION:
args = ((MethodInvocationTree) tree).getArguments();
break;
case NEW_CLASS:
args = ((NewClassTree) tree).getArguments();
break;
default:
throw new AssertionError("Unexpected kind of tree: " + tree);
}
if (numFormals == args.size()) {
AnnotatedTypeMirror lastArgType = atypeFactory.getAnnotatedType(args.get(args.size() - 1));
if (lastArgType.getKind() == TypeKind.ARRAY && AnnotatedTypes.getArrayDepth(lastParamAnnotatedType) == AnnotatedTypes.getArrayDepth((AnnotatedArrayType) lastArgType)) {
return;
}
}
AnnotatedTypeMirror wrappedVarargsType = atypeFactory.getAnnotatedTypeVarargsArray(tree);
// annotation to be checked for generated varargs array.
if (wrappedVarargsType == null) {
return;
}
// is also needed to avoid duplicating error message caused by elements in varargs
if (wrappedVarargsType.getKind() == TypeKind.ARRAY) {
((AnnotatedArrayType) wrappedVarargsType).setComponentType(lastParamAnnotatedType.getComponentType());
}
commonAssignmentCheck(lastParamAnnotatedType, wrappedVarargsType, tree, "varargs.type.incompatible");
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedArrayType in project checker-framework by typetools.
the class CollectionToArrayHeuristics method setComponentNullness.
/**
* Sets the nullness of the component of the array type.
*
* @param isNonNull indicates which annotation ({@code NonNull} or {@code Nullable}) should be
* inserted
* @param type the array type
*/
private void setComponentNullness(boolean isNonNull, AnnotatedTypeMirror type) {
assert type.getKind() == TypeKind.ARRAY;
AnnotatedTypeMirror compType = ((AnnotatedArrayType) type).getComponentType();
compType.replaceAnnotation(isNonNull ? atypeFactory.NONNULL : atypeFactory.NULLABLE);
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedArrayType in project checker-framework by typetools.
the class WholeProgramInferenceScenesHelper method typeElementToATM.
/**
* Updates an {@link org.checkerframework.framework.type.AnnotatedTypeMirror} to contain the
* {@link scenelib.annotations.Annotation}s of an {@link scenelib.annotations.el.ATypeElement}.
*
* @param atm the AnnotatedTypeMirror to be modified
* @param type the {@link scenelib.annotations.el.ATypeElement}
* @param atf the annotated type factory of a given type system, whose type hierarchy will be
* used
*/
private void typeElementToATM(AnnotatedTypeMirror atm, ATypeElement type, AnnotatedTypeFactory atf) {
Set<Annotation> annos = getSupportedAnnosInSet(type.tlAnnotationsHere, atf);
for (Annotation anno : annos) {
AnnotationMirror am = AnnotationConverter.annotationToAnnotationMirror(anno, atf.getProcessingEnv());
atm.addAnnotation(am);
}
if (atm.getKind() == TypeKind.ARRAY) {
AnnotatedArrayType aat = (AnnotatedArrayType) atm;
for (ATypeElement innerType : type.innerTypes.values()) {
typeElementToATM(aat.getComponentType(), innerType, atf);
}
}
if (atm.getKind() == TypeKind.TYPEVAR) {
AnnotatedTypeVariable atv = (AnnotatedTypeVariable) atm;
for (ATypeElement innerType : type.innerTypes.values()) {
typeElementToATM(atv.getUpperBound(), innerType, atf);
}
}
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedArrayType in project checker-framework by typetools.
the class AnnotatedTypeCopier method visitArray.
@Override
public AnnotatedTypeMirror visitArray(AnnotatedArrayType original, IdentityHashMap<AnnotatedTypeMirror, AnnotatedTypeMirror> originalToCopy) {
if (originalToCopy.containsKey(original)) {
return originalToCopy.get(original);
}
final AnnotatedArrayType copy = (AnnotatedArrayType) AnnotatedTypeMirror.createType(original.getUnderlyingType(), original.atypeFactory, original.isDeclaration());
maybeCopyPrimaryAnnotations(original, copy);
originalToCopy.put(original, copy);
copy.setComponentType(visit(original.getComponentType(), originalToCopy));
return copy;
}
Aggregations