Search in sources :

Example 11 with ClassName

use of org.checkerframework.dataflow.expression.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(JavaExpression expr) {
    if (expr instanceof FieldAccess) {
        FieldAccess fieldAccess = (FieldAccess) expr;
        JavaExpression receiver = fieldAccess.getReceiver();
        // Don't call fieldAccess
        return fieldAccess.isFinal() && isExpressionEffectivelyFinal(receiver);
    } else if (expr instanceof LocalVariable) {
        return ElementUtils.isEffectivelyFinal(((LocalVariable) expr).getElement());
    } else if (expr instanceof MethodCall) {
        MethodCall methodCall = (MethodCall) expr;
        for (JavaExpression arg : methodCall.getArguments()) {
            if (!isExpressionEffectivelyFinal(arg)) {
                return false;
            }
        }
        return PurityUtils.isDeterministic(this, methodCall.getElement()) && isExpressionEffectivelyFinal(methodCall.getReceiver());
    } else if (expr instanceof ThisReference || expr instanceof ClassName) {
        // too.
        return true;
    } else {
        // type of 'expr' is not supported in @GuardedBy(...) lock expressions
        return false;
    }
}
Also used : JavaExpression(org.checkerframework.dataflow.expression.JavaExpression) LocalVariable(org.checkerframework.dataflow.expression.LocalVariable) ClassName(org.checkerframework.dataflow.expression.ClassName) FieldAccess(org.checkerframework.dataflow.expression.FieldAccess) ThisReference(org.checkerframework.dataflow.expression.ThisReference) MethodCall(org.checkerframework.dataflow.expression.MethodCall)

Aggregations

ClassName (org.checkerframework.dataflow.expression.ClassName)11 FieldAccess (org.checkerframework.dataflow.expression.FieldAccess)9 LocalVariable (org.checkerframework.dataflow.expression.LocalVariable)8 MethodCall (org.checkerframework.dataflow.expression.MethodCall)6 ThisReference (org.checkerframework.dataflow.expression.ThisReference)6 ArrayAccess (org.checkerframework.dataflow.expression.ArrayAccess)5 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AnnotationMirror (javax.lang.model.element.AnnotationMirror)2 ExecutableElement (javax.lang.model.element.ExecutableElement)2 JavaExpression (org.checkerframework.dataflow.expression.JavaExpression)2 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)2 ParseProblemException (com.github.javaparser.ParseProblemException)1 LanguageLevel (com.github.javaparser.ParserConfiguration.LanguageLevel)1 Expression (com.github.javaparser.ast.expr.Expression)1 ClassTree (com.sun.source.tree.ClassTree)1 MethodTree (com.sun.source.tree.MethodTree)1 Element (javax.lang.model.element.Element)1 ElementKind (javax.lang.model.element.ElementKind)1 TypeElement (javax.lang.model.element.TypeElement)1