Search in sources :

Example 56 with AnnotatedDeclaredType

use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType in project checker-framework by typetools.

the class AtmLubVisitor method visitIntersection_Intersection.

@Override
public Void visitIntersection_Intersection(AnnotatedIntersectionType type1, AnnotatedIntersectionType type2, AnnotatedTypeMirror lub) {
    AnnotatedIntersectionType castedLub = castLub(type1, lub);
    lubPrimaryAnnotations(type1, type2, lub);
    for (int i = 0; i < lub.directSuperTypes().size(); i++) {
        AnnotatedDeclaredType lubST = castedLub.directSuperTypes().get(i);
        visit(type1.directSuperTypes().get(i), type2.directSuperTypes().get(i), lubST);
    }
    return null;
}
Also used : AnnotatedIntersectionType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedIntersectionType) AnnotatedDeclaredType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType)

Example 57 with AnnotatedDeclaredType

use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType in project checker-framework by typetools.

the class InitializationAnnotatedTypeFactory method setSelfTypeInInitializationCode.

protected void setSelfTypeInInitializationCode(Tree tree, AnnotatedDeclaredType selfType, TreePath path) {
    ClassTree enclosingClass = TreeUtils.enclosingClass(path);
    Type classType = ((JCTree) enclosingClass).type;
    AnnotationMirror annotation = null;
    // there might still be subclasses that need initialization.
    if (areAllFieldsCommittedOnly(enclosingClass)) {
        Store store = getStoreBefore(tree);
        if (store != null) {
            List<AnnotationMirror> annos = Collections.emptyList();
            if (getUninitializedInvariantFields(store, path, false, annos).size() == 0) {
                if (classType.isFinal()) {
                    annotation = COMMITTED;
                } else if (useFbc) {
                    annotation = createFreeAnnotation(classType);
                } else {
                    annotation = createUnclassifiedAnnotation(classType);
                }
            }
        }
    }
    if (annotation == null) {
        annotation = getFreeOrRawAnnotationOfSuperType(classType);
    }
    selfType.replaceAnnotation(annotation);
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) AnnotatedExecutableType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType) AnnotatedDeclaredType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType) Type(com.sun.tools.javac.code.Type) DeclaredType(javax.lang.model.type.DeclaredType) NewClassTree(com.sun.source.tree.NewClassTree) ClassTree(com.sun.source.tree.ClassTree) JCTree(com.sun.tools.javac.tree.JCTree)

Example 58 with AnnotatedDeclaredType

use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType in project checker-framework by typetools.

the class InitializationAnnotatedTypeFactory method getSelfType.

@Override
public AnnotatedDeclaredType getSelfType(Tree tree) {
    AnnotatedDeclaredType selfType = super.getSelfType(tree);
    TreePath path = getPath(tree);
    Tree topLevelMember = findTopLevelClassMemberForTree(path);
    if (topLevelMember != null) {
        if (topLevelMember.getKind() != Kind.METHOD || TreeUtils.isConstructor((MethodTree) topLevelMember)) {
            setSelfTypeInInitializationCode(tree, selfType, path);
        }
    }
    return selfType;
}
Also used : TreePath(com.sun.source.util.TreePath) MethodTree(com.sun.source.tree.MethodTree) AnnotatedDeclaredType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType) LiteralTree(com.sun.source.tree.LiteralTree) MethodTree(com.sun.source.tree.MethodTree) VariableTree(com.sun.source.tree.VariableTree) NewClassTree(com.sun.source.tree.NewClassTree) Tree(com.sun.source.tree.Tree) ClassTree(com.sun.source.tree.ClassTree) ExpressionTree(com.sun.source.tree.ExpressionTree) JCTree(com.sun.tools.javac.tree.JCTree)

Example 59 with AnnotatedDeclaredType

use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType in project checker-framework by typetools.

the class CollectionToArrayHeuristics method isNonNullReceiver.

/**
 * Returns {@code true} if the method invocation tree receiver is collection who is known to
 * contain non-null elements (i.e. its type argument is a {@code NonNull}.
 */
private boolean isNonNullReceiver(MethodInvocationTree tree) {
    // check receiver
    AnnotatedTypeMirror receiver = atypeFactory.getReceiverType(tree);
    AnnotatedDeclaredType collection = AnnotatedTypes.asSuper(atypeFactory, receiver, collectionType);
    if (collection.getTypeArguments().isEmpty() || !collection.getTypeArguments().get(0).hasEffectiveAnnotation(atypeFactory.NONNULL)) {
        return false;
    }
    return true;
}
Also used : AnnotatedDeclaredType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror)

Example 60 with AnnotatedDeclaredType

use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType in project checker-framework by typetools.

the class KeyForPropagationTreeAnnotator method visitVariable.

/**
 * Transfers annotations to the variableTree if the right side is a call to
 * java.util.Map.KeySet.
 */
@Override
public Void visitVariable(VariableTree variableTree, AnnotatedTypeMirror type) {
    super.visitVariable(variableTree, type);
    // This should only happen on map.keySet();
    if (type.getKind() == TypeKind.DECLARED) {
        final ExpressionTree initializer = variableTree.getInitializer();
        if (isCallToKeyset(initializer)) {
            final AnnotatedDeclaredType variableType = (AnnotatedDeclaredType) type;
            final AnnotatedTypeMirror initializerType = atypeFactory.getAnnotatedType(initializer);
            // array types and boxed primitives etc don't require propagation
            if (variableType.getKind() == TypeKind.DECLARED) {
                keyForPropagator.propagate((AnnotatedDeclaredType) initializerType, variableType, PropagationDirection.TO_SUPERTYPE, atypeFactory);
            }
        }
    }
    return null;
}
Also used : AnnotatedDeclaredType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType) ExpressionTree(com.sun.source.tree.ExpressionTree) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror)

Aggregations

AnnotatedDeclaredType (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType)72 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)26 ArrayList (java.util.ArrayList)19 ExpressionTree (com.sun.source.tree.ExpressionTree)18 AnnotatedExecutableType (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType)18 MethodTree (com.sun.source.tree.MethodTree)17 Tree (com.sun.source.tree.Tree)16 ClassTree (com.sun.source.tree.ClassTree)14 VariableTree (com.sun.source.tree.VariableTree)14 LambdaExpressionTree (com.sun.source.tree.LambdaExpressionTree)13 ConditionalExpressionTree (com.sun.source.tree.ConditionalExpressionTree)12 NewClassTree (com.sun.source.tree.NewClassTree)12 ExecutableElement (javax.lang.model.element.ExecutableElement)11 IdentifierTree (com.sun.source.tree.IdentifierTree)10 MethodInvocationTree (com.sun.source.tree.MethodInvocationTree)10 NewArrayTree (com.sun.source.tree.NewArrayTree)9 ReturnTree (com.sun.source.tree.ReturnTree)9 AnnotatedTypeVariable (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable)9 AnnotatedWildcardType (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedWildcardType)9 AssignmentTree (com.sun.source.tree.AssignmentTree)8