Search in sources :

Example 11 with ClassName

use of org.checkerframework.dataflow.analysis.FlowExpressions.ClassName in project checker-framework by typetools.

the class LockAnnotatedTypeFactory method isExpressionEffectivelyFinal.

/**
 * Returns whether or not the expression is effectively final.
 *
 * <p>This method returns true in the following cases when expr is:
 *
 * <p>1. a field access and the field is final and the field access expression is effectively
 * final as specified by this method.
 *
 * <p>2. an effectively final local variable.
 *
 * <p>3. a deterministic method call whose arguments and receiver expression are effectively
 * final as specified by this method.
 *
 * <p>4. a this reference or a class literal
 *
 * @param expr expression
 * @return whether or not the expression is effectively final
 */
boolean isExpressionEffectivelyFinal(Receiver expr) {
    if (expr instanceof FieldAccess) {
        FieldAccess fieldAccess = (FieldAccess) expr;
        Receiver recv = fieldAccess.getReceiver();
        // Don't call fieldAccess
        return fieldAccess.isFinal() && isExpressionEffectivelyFinal(recv);
    } else if (expr instanceof LocalVariable) {
        return ElementUtils.isEffectivelyFinal(((LocalVariable) expr).getElement());
    } else if (expr instanceof MethodCall) {
        MethodCall methodCall = (MethodCall) expr;
        for (Receiver param : methodCall.getParameters()) {
            if (!isExpressionEffectivelyFinal(param)) {
                return false;
            }
        }
        return PurityUtils.isDeterministic(this, methodCall.getElement()) && isExpressionEffectivelyFinal(methodCall.getReceiver());
    } else if (expr instanceof ThisReference || expr instanceof ClassName) {
        // final too.
        return true;
    } else {
        // type of 'expr' is not supported in @GuardedBy(...) lock expressions
        return false;
    }
}
Also used : LocalVariable(org.checkerframework.dataflow.analysis.FlowExpressions.LocalVariable) ClassName(org.checkerframework.dataflow.analysis.FlowExpressions.ClassName) Receiver(org.checkerframework.dataflow.analysis.FlowExpressions.Receiver) FieldAccess(org.checkerframework.dataflow.analysis.FlowExpressions.FieldAccess) ThisReference(org.checkerframework.dataflow.analysis.FlowExpressions.ThisReference) MethodCall(org.checkerframework.dataflow.analysis.FlowExpressions.MethodCall)

Aggregations

ClassName (org.checkerframework.dataflow.analysis.FlowExpressions.ClassName)11 FieldAccess (org.checkerframework.dataflow.analysis.FlowExpressions.FieldAccess)6 Receiver (org.checkerframework.dataflow.analysis.FlowExpressions.Receiver)6 VariableElement (javax.lang.model.element.VariableElement)5 TypeMirror (javax.lang.model.type.TypeMirror)5 ThisReference (org.checkerframework.dataflow.analysis.FlowExpressions.ThisReference)5 Element (javax.lang.model.element.Element)4 LocalVariable (org.checkerframework.dataflow.analysis.FlowExpressions.LocalVariable)4 ExecutableElement (javax.lang.model.element.ExecutableElement)3 TypeElement (javax.lang.model.element.TypeElement)3 FlowExpressions (org.checkerframework.dataflow.analysis.FlowExpressions)3 MethodCall (org.checkerframework.dataflow.analysis.FlowExpressions.MethodCall)3 Resolver (org.checkerframework.javacutil.Resolver)3 AnnotationMirror (javax.lang.model.element.AnnotationMirror)2 DeclaredType (javax.lang.model.type.DeclaredType)2 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)2 Pair (org.checkerframework.javacutil.Pair)2 ClassTree (com.sun.source.tree.ClassTree)1 MethodTree (com.sun.source.tree.MethodTree)1 Tree (com.sun.source.tree.Tree)1