use of org.checkerframework.checker.compilermsgs.qual.CompilerMessageKey in project checker-framework by typetools.
the class InitializationVisitor method commonAssignmentCheck.
@Override
protected void commonAssignmentCheck(Tree varTree, ExpressionTree valueExp, @CompilerMessageKey String errorKey) {
// field write of the form x.f = y
if (TreeUtils.isFieldAccess(varTree)) {
// cast is safe: a field access can only be an IdentifierTree or
// MemberSelectTree
ExpressionTree lhs = (ExpressionTree) varTree;
ExpressionTree y = valueExp;
Element el = TreeUtils.elementFromUse(lhs);
AnnotatedTypeMirror xType = atypeFactory.getReceiverType(lhs);
AnnotatedTypeMirror yType = atypeFactory.getAnnotatedType(y);
// the special FBC rules do not apply if there is an explicit
// UnknownInitialization annotation
Set<AnnotationMirror> fieldAnnotations = atypeFactory.getAnnotatedType(TreeUtils.elementFromUse(lhs)).getAnnotations();
if (!AnnotationUtils.containsSameIgnoringValues(fieldAnnotations, atypeFactory.UNCLASSIFIED)) {
if (!ElementUtils.isStatic(el) && !(atypeFactory.isCommitted(yType) || atypeFactory.isFree(xType) || atypeFactory.isFbcBottom(yType))) {
@CompilerMessageKey String err;
if (atypeFactory.isCommitted(xType)) {
err = COMMITMENT_INVALID_FIELD_WRITE_COMMITTED;
} else {
err = COMMITMENT_INVALID_FIELD_WRITE_UNCLASSIFIED;
}
checker.report(Result.failure(err, varTree), varTree);
// prevent issuing another errow about subtyping
return;
}
}
}
super.commonAssignmentCheck(varTree, valueExp, errorKey);
}
use of org.checkerframework.checker.compilermsgs.qual.CompilerMessageKey in project checker-framework by typetools.
the class BaseTypeVisitor method checkContractsAtMethodDeclaration.
private void checkContractsAtMethodDeclaration(MethodTree node, ExecutableElement methodElement, List<String> formalParamNames, boolean abstractMethod) {
FlowExpressionContext flowExprContext = null;
List<Contract> contracts = contractsUtils.getContracts(methodElement);
for (Contract contract : contracts) {
String expression = contract.expression;
AnnotationMirror annotation = contract.annotation;
if (flowExprContext == null) {
flowExprContext = FlowExpressionContext.buildContextForMethodDeclaration(node, getCurrentPath(), checker.getContext());
}
annotation = standardizeAnnotationFromContract(annotation, flowExprContext, getCurrentPath());
FlowExpressions.Receiver expr = null;
try {
expr = FlowExpressionParseUtil.parse(expression, flowExprContext, getCurrentPath(), false);
} catch (FlowExpressionParseException e) {
checker.report(e.getResult(), node);
}
if (expr != null && !abstractMethod) {
switch(contract.kind) {
case POSTCONDTION:
checkPostcondition(node, annotation, expr);
break;
case CONDITIONALPOSTCONDTION:
checkConditionalPostcondition(node, annotation, expr, ((ConditionalPostcondition) contract).annoResult);
break;
case PRECONDITION:
// Preconditions are checked at method invocations, not declarations
break;
}
}
if (formalParamNames != null && formalParamNames.contains(expression)) {
@SuppressWarnings("CompilerMessages") @CompilerMessageKey String key = "contracts." + contract.kind.errorKey + ".expression.parameter.name";
checker.report(Result.warning(key, node.getName().toString(), expression, formalParamNames.indexOf(expression) + 1, expression), node);
}
checkParametersAreEffectivelyFinal(node, methodElement, expression);
}
}
Aggregations