Search in sources :

Example 1 with WholeProgramInferenceImplementation

use of org.checkerframework.common.wholeprograminference.WholeProgramInferenceImplementation in project checker-framework by typetools.

the class GenericAnnotatedTypeFactory method getPreconditionAnnotations.

/**
 * Return the precondition annotations for the given AMethod. Does not modify the AMethod. This
 * method must only be called when using WholeProgramInferenceScenes.
 *
 * @param m AFU representation of a method
 * @return precondition annotations for the method
 */
public List<AnnotationMirror> getPreconditionAnnotations(AMethod m) {
    List<AnnotationMirror> result = new ArrayList<>(m.getPreconditions().size());
    for (Map.Entry<String, AField> entry : m.getPreconditions().entrySet()) {
        WholeProgramInferenceImplementation<?> wholeProgramInference = (WholeProgramInferenceImplementation<?>) getWholeProgramInference();
        WholeProgramInferenceScenesStorage storage = (WholeProgramInferenceScenesStorage) wholeProgramInference.getStorage();
        TypeMirror typeMirror = entry.getValue().getTypeMirror();
        if (typeMirror == null) {
            throw new BugInCF("null TypeMirror in AField inferred by WPI precondition inference. AField: " + entry.getValue().toString());
        }
        AnnotatedTypeMirror declaredType = storage.getPreconditionDeclaredType(m, entry.getKey());
        AnnotatedTypeMirror inferredType = storage.atmFromStorageLocation(typeMirror, entry.getValue().type);
        result.addAll(getPreconditionAnnotations(entry.getKey(), inferredType, declaredType));
    }
    Collections.sort(result, Ordering.usingToString());
    return result;
}
Also used : WholeProgramInferenceImplementation(org.checkerframework.common.wholeprograminference.WholeProgramInferenceImplementation) ArrayList(java.util.ArrayList) WholeProgramInferenceScenesStorage(org.checkerframework.common.wholeprograminference.WholeProgramInferenceScenesStorage) BugInCF(org.checkerframework.javacutil.BugInCF) AField(scenelib.annotations.el.AField) AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeMirror(javax.lang.model.type.TypeMirror) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap)

Example 2 with WholeProgramInferenceImplementation

use of org.checkerframework.common.wholeprograminference.WholeProgramInferenceImplementation in project checker-framework by typetools.

the class GenericAnnotatedTypeFactory method getPostconditionAnnotations.

/**
 * Return the postcondition annotations for the given AMethod. Does not modify the AMethod. This
 * method must only be called when using WholeProgramInferenceScenes.
 *
 * @param m AFU representation of a method
 * @param preconds the precondition annotations for the method; used to suppress redundant
 *     postconditions
 * @return postcondition annotations for the method
 */
public List<AnnotationMirror> getPostconditionAnnotations(AMethod m, List<AnnotationMirror> preconds) {
    List<AnnotationMirror> result = new ArrayList<>(m.getPostconditions().size());
    for (Map.Entry<String, AField> entry : m.getPostconditions().entrySet()) {
        WholeProgramInferenceImplementation<?> wholeProgramInference = (WholeProgramInferenceImplementation<?>) getWholeProgramInference();
        WholeProgramInferenceScenesStorage storage = (WholeProgramInferenceScenesStorage) wholeProgramInference.getStorage();
        TypeMirror typeMirror = entry.getValue().getTypeMirror();
        if (typeMirror == null) {
            throw new BugInCF("null TypeMirror in AField inferred by WPI postcondition inference. AField: " + entry.getValue().toString());
        }
        AnnotatedTypeMirror declaredType = storage.getPostconditionDeclaredType(m, entry.getKey());
        AnnotatedTypeMirror inferredType = storage.atmFromStorageLocation(typeMirror, entry.getValue().type);
        result.addAll(getPostconditionAnnotations(entry.getKey(), inferredType, declaredType, preconds));
    }
    Collections.sort(result, Ordering.usingToString());
    return result;
}
Also used : WholeProgramInferenceImplementation(org.checkerframework.common.wholeprograminference.WholeProgramInferenceImplementation) ArrayList(java.util.ArrayList) WholeProgramInferenceScenesStorage(org.checkerframework.common.wholeprograminference.WholeProgramInferenceScenesStorage) BugInCF(org.checkerframework.javacutil.BugInCF) AField(scenelib.annotations.el.AField) AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeMirror(javax.lang.model.type.TypeMirror) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap)

Aggregations

ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 IdentityHashMap (java.util.IdentityHashMap)2 Map (java.util.Map)2 AnnotationMirror (javax.lang.model.element.AnnotationMirror)2 TypeMirror (javax.lang.model.type.TypeMirror)2 WholeProgramInferenceImplementation (org.checkerframework.common.wholeprograminference.WholeProgramInferenceImplementation)2 WholeProgramInferenceScenesStorage (org.checkerframework.common.wholeprograminference.WholeProgramInferenceScenesStorage)2 BugInCF (org.checkerframework.javacutil.BugInCF)2 AField (scenelib.annotations.el.AField)2