Class FieldInvariants


  • public class FieldInvariants
    extends java.lang.Object
    Represents field invariants, which the user states by writing @FieldInvariant. Think of this as a set of (field name, qualifier) pairs.

    If a FieldInvariants object is malformed (inconsistent number of fields and qualifiers), BaseTypeVisitor will issue an error.

    • Constructor Summary

      Constructors 
      Constructor Description
      FieldInvariants​(@Nullable FieldInvariants other, java.util.List<java.lang.String> fields, java.util.List<javax.lang.model.element.AnnotationMirror> qualifiers, AnnotatedTypeFactory atypeFactory)
      Creates a new object with all the invariants in other, plus those specified by fields and qualifiers.
      FieldInvariants​(java.util.List<java.lang.String> fields, java.util.List<javax.lang.model.element.AnnotationMirror> qualifiers, AnnotatedTypeFactory atypeFactory)
      Creates a new FieldInvariants object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.List<java.lang.String> getFields()
      The simple names of the fields that have a qualifier.
      java.util.List<javax.lang.model.element.AnnotationMirror> getQualifiersFor​(java.lang.CharSequence field)
      Returns a list of qualifiers for field.
      @Nullable DiagMessage isStrongerThan​(FieldInvariants superInvar)
      Returns null if this is stronger than the given FieldInvariants, otherwise returns the error message.
      boolean isWellFormed()
      Returns true if there is a qualifier for each field in fields.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FieldInvariants

        public FieldInvariants​(java.util.List<java.lang.String> fields,
                               java.util.List<javax.lang.model.element.AnnotationMirror> qualifiers,
                               AnnotatedTypeFactory atypeFactory)
        Creates a new FieldInvariants object. The result is well-formed if the length of qualifiers is either 1 or equal to length of fields.
        Parameters:
        fields - list of fields
        qualifiers - list of qualifiers, or a single qualifier that applies to all fields
        atypeFactory - the type factory
      • FieldInvariants

        public FieldInvariants​(@Nullable FieldInvariants other,
                               java.util.List<java.lang.String> fields,
                               java.util.List<javax.lang.model.element.AnnotationMirror> qualifiers,
                               AnnotatedTypeFactory atypeFactory)
        Creates a new object with all the invariants in other, plus those specified by fields and qualifiers. The result is well-formed if the length of qualifiers is either 1 or equal to length of fields.
        Parameters:
        other - other invariant object, may be null
        fields - list of fields
        qualifiers - list of qualifiers
        atypeFactory - the type factory
    • Method Detail

      • getFields

        public java.util.List<java.lang.String> getFields()
        The simple names of the fields that have a qualifier. May contain duplicates.
      • getQualifiersFor

        public java.util.List<javax.lang.model.element.AnnotationMirror> getQualifiersFor​(java.lang.CharSequence field)
        Returns a list of qualifiers for field. If field has no qualifiers, returns an empty list.
        Parameters:
        field - simple field name
        Returns:
        a list of qualifiers for field, possibly empty
      • isWellFormed

        public boolean isWellFormed()
        Returns true if there is a qualifier for each field in fields.
        Returns:
        true if there is a qualifier for each field in fields
      • isStrongerThan

        public @Nullable DiagMessage isStrongerThan​(FieldInvariants superInvar)
        Returns null if this is stronger than the given FieldInvariants, otherwise returns the error message. This is stronger if each of its qualifiers is a subtype of (or equal to) the respective qualfier in the given FieldInvariants.
        Parameters:
        superInvar - the value to check for being a weaker invariant
        Returns:
        null if this is stronger, otherwise returns an error message