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;
}
}
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();
}
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);
}
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);
}
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);
}
Aggregations