use of org.checkerframework.framework.type.AnnotatedTypeMirror in project checker-framework by typetools.
the class UnitsVisitor method visitCompoundAssignment.
@Override
public Void visitCompoundAssignment(CompoundAssignmentTree node, Void p) {
ExpressionTree var = node.getVariable();
ExpressionTree expr = node.getExpression();
AnnotatedTypeMirror varType = atypeFactory.getAnnotatedType(var);
AnnotatedTypeMirror exprType = atypeFactory.getAnnotatedType(expr);
Kind kind = node.getKind();
if ((kind == Kind.PLUS_ASSIGNMENT || kind == Kind.MINUS_ASSIGNMENT)) {
if (!atypeFactory.getTypeHierarchy().isSubtype(exprType, varType)) {
checker.report(Result.failure("compound.assignment.type.incompatible", varType, exprType), node);
}
} else if (exprType.getAnnotation(UnknownUnits.class) == null) {
// Only allow mul/div with unqualified units
checker.report(Result.failure("compound.assignment.type.incompatible", varType, exprType), node);
}
// super.visitCompoundAssignment(node, p);
return null;
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror in project checker-framework by typetools.
the class FenumVisitor method visitSwitch.
@Override
public Void visitSwitch(SwitchTree node, Void p) {
ExpressionTree expr = node.getExpression();
AnnotatedTypeMirror exprType = atypeFactory.getAnnotatedType(expr);
for (CaseTree caseExpr : node.getCases()) {
ExpressionTree realCaseExpr = caseExpr.getExpression();
if (realCaseExpr != null) {
AnnotatedTypeMirror caseType = atypeFactory.getAnnotatedType(realCaseExpr);
this.commonAssignmentCheck(exprType, caseType, caseExpr, "switch.type.incompatible");
}
}
return super.visitSwitch(node, p);
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror in project checker-framework by typetools.
the class GuiEffectVisitor method visitReturn.
// Returning a lambda expression also triggers inference based on the method's return type.
@Override
public Void visitReturn(ReturnTree node, Void p) {
Void result = super.visitReturn(node, p);
if (node.getExpression() != null && node.getExpression().getKind() == Tree.Kind.LAMBDA_EXPRESSION) {
// Unfortunatelly, need to duplicate a fair bit of BaseTypeVisitor.visitReturn after lambdas have been
// inferred.
Pair<Tree, AnnotatedTypeMirror> preAssCtxt = visitorState.getAssignmentContext();
try {
Tree enclosing = TreeUtils.enclosingMethodOrLambda(getCurrentPath());
AnnotatedTypeMirror ret = null;
if (enclosing.getKind() == Tree.Kind.METHOD) {
MethodTree enclosingMethod = (MethodTree) enclosing;
boolean valid = validateTypeOf(enclosing);
if (valid) {
ret = atypeFactory.getMethodReturnType(enclosingMethod, node);
}
} else {
ret = atypeFactory.getFnInterfaceFromTree((LambdaExpressionTree) enclosing).second.getReturnType();
}
if (ret != null) {
visitorState.setAssignmentContext(Pair.of((Tree) node, ret));
lambdaAssignmentCheck(ret, (LambdaExpressionTree) node.getExpression(), "return.type.incompatible");
}
} finally {
visitorState.setAssignmentContext(preAssCtxt);
}
}
return result;
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror in project checker-framework by typetools.
the class GuiEffectVisitor method lambdaAssignmentCheck.
// For assignments and local variable initialization:
// Check for @UI annotations on the lhs, use them to infer @UI types on lambda expressions in the rhs
private void lambdaAssignmentCheck(AnnotatedTypeMirror varType, LambdaExpressionTree lambdaExp, @CompilerMessageKey String errorKey) {
AnnotatedTypeMirror lambdaType = atypeFactory.getAnnotatedType(lambdaExp);
assert lambdaType != null : "null type for expression: " + lambdaExp;
commonAssignmentCheck(varType, lambdaType, lambdaExp, errorKey);
}
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;
}
}
Aggregations