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) {
Pair<AnnotatedDeclaredType, AnnotatedExecutableType> result = atypeFactory.getFnInterfaceFromTree(node);
AnnotatedExecutableType functionType = result.second;
if (node.getBody().getKind() != Tree.Kind.BLOCK) {
// Check return type for single statement returns here.
AnnotatedTypeMirror ret = functionType.getReturnType();
if (ret.getKind() != TypeKind.VOID) {
visitorState.setAssignmentContext(Pair.of((Tree) node, ret));
commonAssignmentCheck(ret, (ExpressionTree) node.getBody(), "return.type.incompatible");
}
}
// 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.type.incompatible");
}
return super.visitLambdaExpression(node, p);
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror in project checker-framework by typetools.
the class UpperBoundTransfer method getUBQualifierForAddition.
/**
* Returns the UBQualifier for a node, with additional refinement useful specifically for
* integer addition, based on the information from subcheckers of the Index Checker.
*
* @param n the node
* @param in dataflow analysis transfer input
* @return the UBQualifier for {@code node}
*/
private UBQualifier getUBQualifierForAddition(Node n, TransferInput<CFValue, CFStore> in) {
// The method takes the greatest lower bound of the qualifier returned by
// getUBQualifier and a qualifier created from a SubstringIndexFor annotation, if such
// annotation is present and the index is known to be non-negative.
UBQualifier ubQualifier = getUBQualifier(n, in);
Tree nodeTree = n.getTree();
// Annotation from the Substring Index hierarchy
AnnotatedTypeMirror substringIndexType = atypeFactory.getSubstringIndexAnnotatedTypeFactory().getAnnotatedType(nodeTree);
AnnotationMirror substringIndexAnno = substringIndexType.getAnnotation(SubstringIndexFor.class);
// Annotation from the Lower bound hierarchy
AnnotatedTypeMirror lowerBoundType = atypeFactory.getLowerBoundAnnotatedTypeFactory().getAnnotatedType(nodeTree);
// convert the SubstringIndexFor annotation to a upper bound qualifier.
if (substringIndexAnno != null && (lowerBoundType.hasAnnotation(NonNegative.class) || lowerBoundType.hasAnnotation(Positive.class))) {
UBQualifier substringIndexQualifier = UBQualifier.createUBQualifier(substringIndexAnno);
ubQualifier = ubQualifier.glb(substringIndexQualifier);
}
return ubQualifier;
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror in project checker-framework by typetools.
the class UpperBoundVisitor method visitAccess.
/**
* Checks if this array access is either using a variable that is less than the length of the
* array, or using a constant less than the array's minlen. Issues an error if neither is true.
*/
private void visitAccess(ExpressionTree indexTree, ExpressionTree arrTree) {
AnnotatedTypeMirror indexType = atypeFactory.getAnnotatedType(indexTree);
String arrName = FlowExpressions.internalReprOf(this.atypeFactory, arrTree).toString();
UBQualifier qualifier = UBQualifier.createUBQualifier(indexType, atypeFactory.UNKNOWN);
if (qualifier.isLessThanLengthOf(arrName)) {
return;
}
// Find max because it's important to determine whether the index is less than the
// minimum length of the array. If it could be any of several values, only the max is of
// interest.
Long valMax = IndexUtil.getMaxValue(indexTree, atypeFactory.getValueAnnotatedTypeFactory());
AnnotationMirror sameLenAnno = atypeFactory.sameLenAnnotationFromTree(arrTree);
// Produce the full list of relevant names by checking the SameLen type.
if (sameLenAnno != null && AnnotationUtils.areSameByClass(sameLenAnno, SameLen.class)) {
if (AnnotationUtils.hasElementValue(sameLenAnno, "value")) {
List<String> slNames = AnnotationUtils.getElementValueArray(sameLenAnno, "value", String.class, true);
if (qualifier.isLessThanLengthOfAny(slNames)) {
return;
}
for (String slName : slNames) {
// Check if any of the arrays have a minlen that is greater than the
// known constant value.
int minlenSL = atypeFactory.getValueAnnotatedTypeFactory().getMinLenFromString(slName, arrTree, getCurrentPath());
if (valMax != null && valMax < minlenSL) {
return;
}
}
}
}
// Check against the minlen of the array itself.
int minLen = IndexUtil.getMinLen(arrTree, atypeFactory.getValueAnnotatedTypeFactory());
if (valMax != null && valMax < minLen) {
return;
}
if (IndexUtil.getExactValue(indexTree, atypeFactory.getValueAnnotatedTypeFactory()) != null) {
// Note that valMax is equal to the exact value in this case.
checker.report(Result.failure(UPPER_BOUND_CONST, valMax, atypeFactory.getValueAnnotatedTypeFactory().getAnnotatedType(arrTree).toString(), valMax + 1, valMax + 1), indexTree);
} else if (valMax != null && qualifier.isUnknown()) {
checker.report(Result.failure(UPPER_BOUND_RANGE, atypeFactory.getValueAnnotatedTypeFactory().getAnnotatedType(indexTree).toString(), atypeFactory.getValueAnnotatedTypeFactory().getAnnotatedType(arrTree).toString(), arrName, arrName, valMax + 1), indexTree);
} else {
checker.report(Result.failure(UPPER_BOUND, indexType.toString(), arrName, arrName, arrName), indexTree);
}
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror in project checker-framework by typetools.
the class InitializationAnnotatedTypeFactory method isInitializedForFrame.
public boolean isInitializedForFrame(AnnotatedTypeMirror type, TypeMirror frame) {
AnnotationMirror initializationAnno = type.getEffectiveAnnotationInHierarchy(UNCLASSIFIED);
TypeMirror typeFrame = getTypeFrameFromAnnotation(initializationAnno);
Types types = processingEnv.getTypeUtils();
return types.isSubtype(typeFrame, frame);
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror in project checker-framework by typetools.
the class InitializationAnnotatedTypeFactory method postAsMemberOf.
/**
* {@inheritDoc}
*
* <p>In most cases, subclasses want to call this method first because it may clear all
* annotations and use the hierarchy's root annotations.
*/
@Override
public void postAsMemberOf(AnnotatedTypeMirror type, AnnotatedTypeMirror owner, Element element) {
super.postAsMemberOf(type, owner, element);
if (element.getKind().isField()) {
Collection<? extends AnnotationMirror> declaredFieldAnnotations = getDeclAnnotations(element);
AnnotatedTypeMirror fieldAnnotations = getAnnotatedType(element);
computeFieldAccessType(type, declaredFieldAnnotations, owner, fieldAnnotations, element);
}
}
Aggregations