Search in sources :

Example 1 with DependentTypesHelper

use of org.checkerframework.framework.util.dependenttypes.DependentTypesHelper in project checker-framework by typetools.

the class BaseTypeVisitor method standardizeAnnotationFromContract.

/**
 * Standardize a type qualifier annotation obtained from a contract.
 */
private AnnotationMirror standardizeAnnotationFromContract(AnnotationMirror annoFromContract, FlowExpressionContext flowExprContext, TreePath path) {
    DependentTypesHelper dependentTypesHelper = atypeFactory.getDependentTypesHelper();
    if (dependentTypesHelper != null) {
        AnnotationMirror anno = dependentTypesHelper.standardizeAnnotation(flowExprContext, path, annoFromContract, false);
        dependentTypesHelper.checkAnnotation(anno, path.getLeaf());
        return anno;
    } else {
        return annoFromContract;
    }
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) DependentTypesHelper(org.checkerframework.framework.util.dependenttypes.DependentTypesHelper)

Example 2 with DependentTypesHelper

use of org.checkerframework.framework.util.dependenttypes.DependentTypesHelper 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();
            }
        }
    };
}
Also used : FlowExpressionParseUtil(org.checkerframework.framework.util.FlowExpressionParseUtil) FlowExpressionContext(org.checkerframework.framework.util.FlowExpressionParseUtil.FlowExpressionContext) DependentTypesError(org.checkerframework.framework.util.dependenttypes.DependentTypesError) ArrayList(java.util.ArrayList) Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver) TreePath(com.sun.source.util.TreePath) DependentTypesHelper(org.checkerframework.framework.util.dependenttypes.DependentTypesHelper) MethodInvocationTree(com.sun.source.tree.MethodInvocationTree) VariableTree(com.sun.source.tree.VariableTree) Tree(com.sun.source.tree.Tree) ExpressionTree(com.sun.source.tree.ExpressionTree) FlowExpressions(org.checkerframework.dataflow.analysis.FlowExpressions) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

DependentTypesHelper (org.checkerframework.framework.util.dependenttypes.DependentTypesHelper)2 ExpressionTree (com.sun.source.tree.ExpressionTree)1 MethodInvocationTree (com.sun.source.tree.MethodInvocationTree)1 Tree (com.sun.source.tree.Tree)1 VariableTree (com.sun.source.tree.VariableTree)1 TreePath (com.sun.source.util.TreePath)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AnnotationMirror (javax.lang.model.element.AnnotationMirror)1 FlowExpressions (org.checkerframework.dataflow.analysis.FlowExpressions)1 Receiver (org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)1 FlowExpressionParseUtil (org.checkerframework.framework.util.FlowExpressionParseUtil)1 FlowExpressionContext (org.checkerframework.framework.util.FlowExpressionParseUtil.FlowExpressionContext)1 DependentTypesError (org.checkerframework.framework.util.dependenttypes.DependentTypesError)1