Class AnnotationHelper

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(java.lang.String annotName, java.util.Map<java.lang.String,​java.lang.String[]> annotAttrs, Location loc)
      Adds an annotation definition.
      void addByCompoundValue​(java.lang.String cval, Location loc)
      Adds annotation by specifying the content in the compound format.
      void applyAnnotations​(Component comp, java.lang.String propName, boolean clear)
      Applies the annotations defined in this helper to the specified component.
      void applyAnnotations​(AnnotationMap annots, java.lang.String propName, boolean clear)
      Applies the annotations defined in this helper to the specified annotation map.
      void applyAnnotations​(ComponentInfo compInfo, java.lang.String propName, boolean clear)
      Applies the annotations defined in this helper to the specified instance definition.
      void applyAnnotations​(ShadowInfo compInfo, java.lang.String propName, boolean clear)
      Applies the annotations defined in this helper to the specified instance definition.
      boolean clear()
      Clears the annotations defined in this helper.
      static boolean isAnnotation​(java.lang.String val)
      Test if the given value is an annotation.
      static java.lang.String[] parseAttributeValue​(java.lang.String val, Location loc)
      Parses the attribute value.
      void setIgnoreAnnotNamespace​(boolean ignoreAnnotNamespace)
      Sets whether to ignore annotation namespace.
      boolean shouldIgnoreAnnotNamespace()
      Whether to ignore annotation namespace.
      • Methods inherited from class java.lang.Object

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

      • AnnotationHelper

        public AnnotationHelper()
    • Method Detail

      • add

        public void add​(java.lang.String annotName,
                        java.util.Map<java.lang.String,​java.lang.String[]> annotAttrs,
                        Location loc)
        Adds an annotation definition. The annotation's attributes must be parsed into a map (annotAttrs).
        Parameters:
        annotName - the annotation name.
        annotAttrs - a map of attributes of the annotation. If null, it means no attribute at all.
        loc - the location information of the annotation in the document, or null if not available.
        See Also:
        addByCompoundValue(java.lang.String, org.zkoss.util.resource.Location)
      • addByCompoundValue

        public void addByCompoundValue​(java.lang.String cval,
                                       Location loc)
        Adds annotation by specifying the content in the compound format.

        There are two formats:

        Format 1 (recommended, since 6.0):
        @annot-name(att1-name=att1-value, att2-name=att2-value) @annot-name() @default(annot3-attrs)

        In the first format, it must be a list of annotations separated by space. And, each annotation is in the format of @annot-name(key=value, value, key=value). That is, it starts with the annotation's name and a parenthesis to enclose any number of key and value pairs (key is optional). The annotation's names must be composed of letters, numbers, the underscore _, the dash - and the dollar sign $. The names may only begin with a letter, the underscore or a dollar sign. In additions, all characters are preserved, including the single and double quotes.

        Parameters:
        cval - the compound value to check. This method assumes that cval starts with @ and the length is larger than 2
        loc - the location information of the value for displaying better error message. Ignored if null.
        Since:
        6.0.0
      • parseAttributeValue

        public static java.lang.String[] parseAttributeValue​(java.lang.String val,
                                                             Location loc)
        Parses the attribute value. If the value starts with { and ends with }, an array of String is returned. Otherwise, the value is returned directly (without any processing).
        Parameters:
        val - the value. This method assumes val has been trimmed before the call.
        loc - the location information of the value for displaying better error message. Ignored if null.
        Throws:
        java.lang.NullPointerException - if val is null.
        Since:
        6.0.0
      • applyAnnotations

        public void applyAnnotations​(ComponentInfo compInfo,
                                     java.lang.String propName,
                                     boolean clear)
        Applies the annotations defined in this helper to the specified instance definition.
        Parameters:
        compInfo - the instance definition to update
        propName - the property name
        clear - whether to clear all definitions before returning
        Since:
        6.0.1
        See Also:
        clear()
      • applyAnnotations

        public void applyAnnotations​(ShadowInfo compInfo,
                                     java.lang.String propName,
                                     boolean clear)
        Applies the annotations defined in this helper to the specified instance definition.
        Parameters:
        compInfo - the instance definition to update
        propName - the property name
        clear - whether to clear all definitions before returning
        Since:
        8.0.0
        See Also:
        clear()
      • applyAnnotations

        public void applyAnnotations​(Component comp,
                                     java.lang.String propName,
                                     boolean clear)
        Applies the annotations defined in this helper to the specified component.
        Parameters:
        comp - the component to update
        propName - the property name
        clear - whether to clear all definitions before returning
        See Also:
        clear()
      • applyAnnotations

        public void applyAnnotations​(AnnotationMap annots,
                                     java.lang.String propName,
                                     boolean clear)
        Applies the annotations defined in this helper to the specified annotation map.
        Parameters:
        annots - the annotation map where the annotations are added.
        propName - the property name
        clear - whether to clear all definitions before returning
        Since:
        6.0.1
        See Also:
        clear()
      • shouldIgnoreAnnotNamespace

        public boolean shouldIgnoreAnnotNamespace()
        Whether to ignore annotation namespace.
        Returns:
        true if should ignore annotation namespace.
        Since:
        8.5.2
      • setIgnoreAnnotNamespace

        public void setIgnoreAnnotNamespace​(boolean ignoreAnnotNamespace)
        Sets whether to ignore annotation namespace.
        Parameters:
        ignoreAnnotNamespace - whether to ignore annotation namespace
        Since:
        8.5.2