Class GenericAnnotation

    • Constructor Detail

      • GenericAnnotation

        public GenericAnnotation()
      • GenericAnnotation

        public GenericAnnotation​(String type)
        Creates a new annotation for a given type.

        Note that it is technically to have two annotations with the same type but different fields. This is a side effect of the capability to access the annotation in a generic way. The user is responsible for keeping consistent types of annotations.

        Parameters:
        type - the identifier of the type (cannot be null or empty).
      • GenericAnnotation

        public GenericAnnotation​(String type,
                                 Object... list)
        Creates a new annotation for a given type. With a list of fields. This method simply call the setFields(Object...) method after creating the annotation.
        Parameters:
        type - the identifier of the type (cannot be null or empty).
        list - the list of key+value pairs to set.
    • Method Detail

      • createFromString

        public static GenericAnnotation createFromString​(String storage)
        Creates a new GenericAnnotation object from a storage string.
        Parameters:
        storage - the serialized representation of the object.
        Returns:
        a new GenericAnnotation object.
      • addAnnotation

        public static void addAnnotation​(ITextUnit tu,
                                         GenericAnnotation ann)
        Adds an annotation to a text unit. If the text unit has no annotation set attached yet one is created and attached, otherwise the annotation to add is added to the existing set.
        Parameters:
        tu - the text unit where to attach the annotation.
        ann - the annotation to attach (if null, nothing is attached).
      • addAnnotation

        public static void addAnnotation​(TextContainer tc,
                                         GenericAnnotation ann)
        Adds an annotation to a text container. If the text container has no annotation set attached yet one is created and attached, otherwise the annotation to add is added to the existing set.
        Parameters:
        tc - the text container where to attach the annotation.
        ann - the annotation to attach (if null, nothing is attached).
      • addAnnotation

        public static void addAnnotation​(Code code,
                                         GenericAnnotation ann)
        Adds an annotation to an inline code. If the inline code has no annotation set attached yet one is created and attached, otherwise the annotation to add is added to the existing set.
        Parameters:
        code - the code where to add the annotation.
        ann - the annotation to add (if null, nothing is attached).
      • setFields

        public void setFields​(Object... list)
        Sets a list of key+values pairs for this annotation. Each pair must be made of a string that is the name of the field, and an object that is the value to set. The object can be null in that case: the key is not set or deleted. Only supported types must be used.
        Parameters:
        list - the list of key+value pairs to set.
      • getType

        public String getType()
        Gets the type of annotation.
        Returns:
        the type identifier for the annotation.
      • getString

        public String getString​(String name)
        Gets the string value for a given field.
        Parameters:
        name - the name of the field.
        Returns:
        the field's value as a string.
      • setString

        public void setString​(String name,
                              String value)
        Sets a string field.
        Parameters:
        name - the name of the field to set.
        value - the value to set, use null to remove the field.
      • setBoolean

        public void setBoolean​(String name,
                               Boolean value)
        sets a boolean field.
        Parameters:
        name - the name of the field to set.
        value - the value to set, use null to remove the field.
      • setDouble

        public void setDouble​(String name,
                              Double value)
      • setInteger

        public void setInteger​(String name,
                               Integer value)
      • toString

        public String toString()
        Description copied from class: InlineAnnotation
        Gets a storage string representation of the whole annotation that can be used for serialization.
        Specified by:
        toString in interface IAnnotation
        Overrides:
        toString in class InlineAnnotation
        Returns:
        The storage string representation of this annotation.
      • getFieldCount

        public int getFieldCount()
      • remove

        public void remove​(String name)