Search in sources :

Example 26 with AnnotatedTypeMirror

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

the class IndexUtil method getMinValue.

/**
 * Finds the minimum value in a Value Checker type. If there is no information (such as when the
 * list of possible values is empty or null), returns null. Otherwise, returns the smallest
 * value in the list of possible values.
 */
public static Long getMinValue(Tree tree, ValueAnnotatedTypeFactory factory) {
    AnnotatedTypeMirror valueType = factory.getAnnotatedType(tree);
    Range possibleValues = getPossibleValues(valueType, factory);
    if (possibleValues != null) {
        return possibleValues.from;
    } else {
        return null;
    }
}
Also used : Range(org.checkerframework.common.value.util.Range) IntRange(org.checkerframework.common.value.qual.IntRange) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror)

Example 27 with AnnotatedTypeMirror

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

the class IndexUtil method getMinLenFromTree.

/**
 * Looks up the minlen of a member select tree. The tree must be an access to a sequence length.
 */
public static Integer getMinLenFromTree(Tree tree, ValueAnnotatedTypeFactory valueATF) {
    AnnotatedTypeMirror minLenType = valueATF.getAnnotatedType(tree);
    Long min = valueATF.getMinimumIntegralValue(minLenType);
    if (min == null) {
        return null;
    }
    if (min < 0 || min > Integer.MAX_VALUE) {
        min = 0L;
    }
    return min.intValue();
}
Also used : AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror)

Example 28 with AnnotatedTypeMirror

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

the class LessThanAnnotatedTypeFactory method isLessThan.

/**
 * @return Is left less than right?
 */
public boolean isLessThan(Tree left, String right) {
    AnnotatedTypeMirror leftATM = getAnnotatedType(left);
    if (leftATM.getAnnotations().size() != 1) {
        return false;
    }
    List<String> expressions = getLessThanExpressions(leftATM.getAnnotations().iterator().next());
    if (expressions == null) {
        return true;
    }
    return expressions.contains(right);
}
Also used : AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror)

Example 29 with AnnotatedTypeMirror

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

the class BaseTypeVisitor method visitEnhancedForLoop.

/**
 * Performs a subtype check, to test whether the node expression iterable type is a subtype of the
 * variable type in the enhanced for loop.
 *
 * <p>If the subtype check fails, it issues a "enhancedfor" error.
 */
@Override
public Void visitEnhancedForLoop(EnhancedForLoopTree node, Void p) {
    AnnotatedTypeMirror var = atypeFactory.getAnnotatedTypeLhs(node.getVariable());
    AnnotatedTypeMirror iteratedType = atypeFactory.getIterableElementType(node.getExpression());
    boolean valid = validateTypeOf(node.getVariable());
    if (valid) {
        commonAssignmentCheck(var, iteratedType, node.getExpression(), "enhancedfor");
    }
    return super.visitEnhancedForLoop(node, p);
}
Also used : AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror)

Example 30 with AnnotatedTypeMirror

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

the class BaseTypeVisitor method visitLambdaExpression.

@Override
public Void visitLambdaExpression(LambdaExpressionTree node, Void p) {
    AnnotatedExecutableType functionType = atypeFactory.getFunctionTypeFromTree(node);
    if (node.getBody().getKind() != Tree.Kind.BLOCK) {
        // Check return type for single statement returns here.
        AnnotatedTypeMirror ret = functionType.getReturnType();
        if (ret.getKind() != TypeKind.VOID) {
            commonAssignmentCheck(ret, (ExpressionTree) node.getBody(), "return");
        }
    }
    // Check parameters
    for (int i = 0; i < functionType.getParameterTypes().size(); ++i) {
        AnnotatedTypeMirror lambdaParameter = atypeFactory.getAnnotatedType(node.getParameters().get(i));
        commonAssignmentCheck(lambdaParameter, functionType.getParameterTypes().get(i), node.getParameters().get(i), "lambda.param", i);
    }
    return super.visitLambdaExpression(node, p);
}
Also used : AnnotatedExecutableType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror)

Aggregations

AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)299 AnnotationMirror (javax.lang.model.element.AnnotationMirror)84 ExpressionTree (com.sun.source.tree.ExpressionTree)53 AnnotatedDeclaredType (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType)44 ExecutableElement (javax.lang.model.element.ExecutableElement)41 Tree (com.sun.source.tree.Tree)40 TypeMirror (javax.lang.model.type.TypeMirror)38 AnnotatedExecutableType (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType)38 AnnotatedTypeVariable (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable)38 MethodTree (com.sun.source.tree.MethodTree)34 ArrayList (java.util.ArrayList)34 BugInCF (org.checkerframework.javacutil.BugInCF)32 MethodInvocationTree (com.sun.source.tree.MethodInvocationTree)30 TypeElement (javax.lang.model.element.TypeElement)29 VariableElement (javax.lang.model.element.VariableElement)29 VariableTree (com.sun.source.tree.VariableTree)28 LambdaExpressionTree (com.sun.source.tree.LambdaExpressionTree)27 AnnotatedArrayType (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedArrayType)26 ClassTree (com.sun.source.tree.ClassTree)25 Map (java.util.Map)24