use of org.checkerframework.checker.signature.qual.Identifier in project checker-framework by typetools.
the class ValueTreeAnnotator method visitFieldAccess.
/**
* Visit a tree that might be a field access.
*
* @param tree a tree that might be a field access. It is either a MemberSelectTree or an
* IdentifierTree (if the programmer omitted the leading `this.`).
* @param type its type
*/
private void visitFieldAccess(ExpressionTree tree, AnnotatedTypeMirror type) {
if (!TreeUtils.isFieldAccess(tree) || !handledByValueChecker(type)) {
return;
}
VariableElement fieldElement = (VariableElement) TreeUtils.elementFromTree(tree);
Object value = fieldElement.getConstantValue();
if (value != null) {
// The field is a compile-time constant.
type.replaceAnnotation(atypeFactory.createResultingAnnotation(type.getUnderlyingType(), value));
return;
}
if (ElementUtils.isStatic(fieldElement) && ElementUtils.isFinal(fieldElement)) {
// The field is static and final, but its declaration does not initialize it to a
// compile-time constant. Obtain its value reflectively.
Element classElement = fieldElement.getEnclosingElement();
if (classElement != null) {
@// TODO: bug in ValueAnnotatedTypeFactory.
SuppressWarnings(// TODO: bug in ValueAnnotatedTypeFactory.
"signature") @BinaryName String classname = ElementUtils.getQualifiedClassName(classElement).toString();
// https://tinyurl.com/cfissue/658 for Name.toString()
@SuppressWarnings("signature") @Identifier String fieldName = fieldElement.getSimpleName().toString();
value = atypeFactory.evaluator.evaluateStaticFieldAccess(classname, fieldName, tree);
if (value != null) {
type.replaceAnnotation(atypeFactory.createResultingAnnotation(type.getUnderlyingType(), value));
}
return;
}
}
return;
}
Aggregations