use of org.checkerframework.framework.util.dependenttypes.DependentTypesError in project checker-framework by typetools.
the class LockAnnotatedTypeFactory method createDependentTypesHelper.
@Override
protected DependentTypesHelper createDependentTypesHelper() {
return new DependentTypesHelper(this) {
@Override
protected void reportErrors(Tree errorTree, List<DependentTypesError> errors) {
// If the error message is NOT_EFFECTIVELY_FINAL, then report lock.expression.not
// .final instead of an expression.unparsable.type.invalid error.
List<DependentTypesError> superErrors = new ArrayList<>();
for (DependentTypesError error : errors) {
if (error.error.equals(NOT_EFFECTIVELY_FINAL)) {
checker.report(Result.failure("lock.expression.not.final", error.expression), errorTree);
} else {
superErrors.add(error);
}
}
super.reportErrors(errorTree, superErrors);
}
@Override
protected String standardizeString(String expression, FlowExpressionContext context, TreePath localScope, boolean useLocalScope) {
if (DependentTypesError.isExpressionError(expression)) {
return expression;
}
// Adds logic to parse <self> expression, which only the Lock Checker uses.
if (LockVisitor.selfReceiverPattern.matcher(expression).matches()) {
return expression;
}
try {
FlowExpressions.Receiver result = FlowExpressionParseUtil.parse(expression, context, localScope, useLocalScope);
if (result == null) {
return new DependentTypesError(expression, " ").toString();
}
if (!isExpressionEffectivelyFinal(result)) {
// NOT_EFFECTIVELY_FINAL error string.
return new DependentTypesError(expression, NOT_EFFECTIVELY_FINAL).toString();
}
return result.toString();
} catch (FlowExpressionParseUtil.FlowExpressionParseException e) {
return new DependentTypesError(expression, e).toString();
}
}
};
}
use of org.checkerframework.framework.util.dependenttypes.DependentTypesError in project checker-framework by typetools.
the class LockVisitor method parseExpressionString.
private LockExpression parseExpressionString(String expression, FlowExpressionContext flowExprContext, TreePath path, Receiver itself) {
LockExpression lockExpression = new LockExpression(expression);
if (DependentTypesError.isExpressionError(expression)) {
lockExpression.error = new DependentTypesError(expression);
return lockExpression;
}
Matcher selfReceiverMatcher = selfReceiverPattern.matcher(expression);
try {
if (selfReceiverMatcher.matches()) {
String remainingExpression = selfReceiverMatcher.group(2);
if (remainingExpression == null || remainingExpression.isEmpty()) {
lockExpression.lockExpression = itself;
if (!atypeFactory.isExpressionEffectivelyFinal(lockExpression.lockExpression)) {
checker.report(Result.failure("lock.expression.not.final", lockExpression.lockExpression), path.getLeaf());
}
return lockExpression;
} else {
// TODO: The proper way to do this is to call
// flowExprContext.copyChangeToParsingMemberOfReceiver to set the receiver to
// the <self> expression, and then call FlowExpressionParseUtil.parse on the
// remaining expression string with the new flow expression context. However,
// this currently results in a FlowExpressions.Receiver that has a different
// hash code than if the following flow expression is parsed directly, which
// results in our inability to check that a lock expression is held as it does
// not match anything in the store due to the hash code mismatch. For now,
// convert the "<self>" portion to the node's string representation, and parse
// the entire string:
lockExpression.lockExpression = FlowExpressionParseUtil.parse(itself.toString() + "." + remainingExpression, flowExprContext, path, true);
if (!atypeFactory.isExpressionEffectivelyFinal(lockExpression.lockExpression)) {
checker.report(Result.failure("lock.expression.not.final", lockExpression.lockExpression), path.getLeaf());
}
return lockExpression;
}
} else {
lockExpression.lockExpression = FlowExpressionParseUtil.parse(expression, flowExprContext, path, true);
return lockExpression;
}
} catch (FlowExpressionParseException ex) {
lockExpression.error = new DependentTypesError(expression, ex);
return lockExpression;
}
}
Aggregations