Search in sources :

Example 1 with IgnoreInWholeProgramInference

use of org.checkerframework.framework.qual.IgnoreInWholeProgramInference in project checker-framework by typetools.

the class WholeProgramInferenceScenes method updateInferredFieldType.

/**
 * Updates the type of the field lhs in the Scene of the class with tree classTree. If the field
 * has a declaration annotation with the {@link IgnoreInWholeProgramInference} meta-annotation,
 * no type annotation will be inferred for that field.
 *
 * <p>If the Scene contains no entry for the field lhs, the entry will be created and its type
 * will be the type of rhs. If the Scene previously contained an entry/type for lhs, its new
 * type will be the LUB between the previous type and the type of rhs.
 *
 * <p>
 *
 * @param lhs the field whose type will be refined
 * @param rhs the expression being assigned to the field
 * @param classTree the ClassTree for the enclosing class of the assignment
 * @param atf the annotated type factory of a given type system, whose type hierarchy will be
 *     used to update the field's type
 */
@Override
public void updateInferredFieldType(FieldAccessNode lhs, Node rhs, ClassTree classTree, AnnotatedTypeFactory atf) {
    ClassSymbol classSymbol = getEnclosingClassSymbol(classTree, lhs);
    // https://github.com/typetools/checker-framework/issues/682
    if (classSymbol == null) {
        // TODO: Handle anonymous classes.
        return;
    }
    // https://github.com/typetools/checker-framework/issues/682
    if (!classSymbol.getEnclosedElements().contains((Symbol) lhs.getElement())) {
        return;
    }
    // @IgnoreInWholeProgramInference meta-annotation, exit this routine.
    for (AnnotationMirror declAnno : atf.getDeclAnnotations(TreeUtils.elementFromTree(lhs.getTree()))) {
        if (AnnotationUtils.areSameByClass(declAnno, IgnoreInWholeProgramInference.class)) {
            return;
        }
        Element elt = declAnno.getAnnotationType().asElement();
        if (elt.getAnnotation(IgnoreInWholeProgramInference.class) != null) {
            return;
        }
    }
    String className = classSymbol.flatname.toString();
    String jaifPath = helper.getJaifPath(className);
    AClass clazz = helper.getAClass(className, jaifPath);
    AField field = clazz.fields.vivify(lhs.getFieldName());
    AnnotatedTypeMirror lhsATM = atf.getAnnotatedType(lhs.getTree());
    AnnotatedTypeMirror rhsATM = atf.getAnnotatedType(rhs.getTree());
    helper.updateAnnotationSetInScene(field.type, atf, jaifPath, rhsATM, lhsATM, TypeUseLocation.FIELD);
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) VarSymbol(com.sun.tools.javac.code.Symbol.VarSymbol) TypeSymbol(com.sun.tools.javac.code.Symbol.TypeSymbol) Symbol(com.sun.tools.javac.code.Symbol) VariableElement(javax.lang.model.element.VariableElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) IgnoreInWholeProgramInference(org.checkerframework.framework.qual.IgnoreInWholeProgramInference) AClass(scenelib.annotations.el.AClass) AnnotatedTypeMirror(org.checkerframework.framework.type.AnnotatedTypeMirror) AField(scenelib.annotations.el.AField)

Aggregations

Symbol (com.sun.tools.javac.code.Symbol)1 ClassSymbol (com.sun.tools.javac.code.Symbol.ClassSymbol)1 MethodSymbol (com.sun.tools.javac.code.Symbol.MethodSymbol)1 TypeSymbol (com.sun.tools.javac.code.Symbol.TypeSymbol)1 VarSymbol (com.sun.tools.javac.code.Symbol.VarSymbol)1 AnnotationMirror (javax.lang.model.element.AnnotationMirror)1 Element (javax.lang.model.element.Element)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 VariableElement (javax.lang.model.element.VariableElement)1 IgnoreInWholeProgramInference (org.checkerframework.framework.qual.IgnoreInWholeProgramInference)1 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)1 AClass (scenelib.annotations.el.AClass)1 AField (scenelib.annotations.el.AField)1