Search in sources :

Example 6 with AnnotatedArrayType

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

Example 7 with AnnotatedArrayType

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

Example 8 with AnnotatedArrayType

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

Example 9 with AnnotatedArrayType

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);
        }
    }
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) AnnotatedArrayType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedArrayType) AnnotatedTypeVariable(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable) Annotation(scenelib.annotations.Annotation) ATypeElement(scenelib.annotations.el.ATypeElement)

Example 10 with AnnotatedArrayType

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

Aggregations

AnnotatedArrayType (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedArrayType)23 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)15 AnnotatedDeclaredType (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType)6 ExpressionTree (com.sun.source.tree.ExpressionTree)4 NewArrayTree (com.sun.source.tree.NewArrayTree)4 AnnotatedExecutableType (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType)4 MethodInvocationTree (com.sun.source.tree.MethodInvocationTree)3 Tree (com.sun.source.tree.Tree)3 TypeCastTree (com.sun.source.tree.TypeCastTree)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 AnnotationMirror (javax.lang.model.element.AnnotationMirror)3 AnnotatedWildcardType (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedWildcardType)3 AnnotationTree (com.sun.source.tree.AnnotationTree)2 AssignmentTree (com.sun.source.tree.AssignmentTree)2 ClassTree (com.sun.source.tree.ClassTree)2 CompilationUnitTree (com.sun.source.tree.CompilationUnitTree)2 CompoundAssignmentTree (com.sun.source.tree.CompoundAssignmentTree)2 ConditionalExpressionTree (com.sun.source.tree.ConditionalExpressionTree)2 IdentifierTree (com.sun.source.tree.IdentifierTree)2