Class FormatterTreeUtil


  • public class FormatterTreeUtil
    extends java.lang.Object
    This class provides a collection of utilities to ease working with syntax trees that have something to do with Formatters.
    • Field Detail

      • processingEnv

        public final javax.annotation.processing.ProcessingEnvironment processingEnv
        The processing environment.
      • formatValueElement

        protected final javax.lang.model.element.ExecutableElement formatValueElement
        The value() element/field of an @Format annotation.
      • invalidFormatValueElement

        protected final javax.lang.model.element.ExecutableElement invalidFormatValueElement
        The value() element/field of an @InvalidFormat annotation.
    • Constructor Detail

    • Method Detail

      • isAsFormatCall

        public boolean isAsFormatCall​(MethodInvocationNode node,
                                      AnnotatedTypeFactory atypeFactory)
        Returns true if the call is to a method with the @ReturnsFormat annotation. An example of such a method is FormatUtil.asFormat.
      • isFormatMethodCall

        public boolean isFormatMethodCall​(com.sun.source.tree.MethodInvocationTree tree,
                                          AnnotatedTypeFactory atypeFactory)
        Returns true if tree is a call to a method annotated with @FormatMethod.
        Parameters:
        tree - a method call
        atypeFactory - a type factory
        Returns:
        true if tree is a call to a method annotated with @FormatMethod
      • create

        public @Nullable FormatterTreeUtil.FormatCall create​(com.sun.source.tree.MethodInvocationTree invocationTree,
                                                             AnnotatedTypeFactory atypeFactory)
        Creates a new FormatCall, or returns null.
        Parameters:
        invocationTree - a method invocation, where the method is annotated @FormatMethod
        atypeFactory - the type factory
        Returns:
        a new FormatCall, or null if the invocation is of a method that is improperly annotated @FormatMethod
      • failure

        public final void failure​(FormatterTreeUtil.Result<?> res,
                                  @CompilerMessageKey java.lang.String msgKey,
                                  java.lang.Object... args)
        Reports an error.
        Parameters:
        res - used for source location information
        msgKey - the diagnostic message key
        args - arguments to the diagnostic message
      • warning

        public final void warning​(FormatterTreeUtil.Result<?> res,
                                  @CompilerMessageKey java.lang.String msgKey,
                                  java.lang.Object... args)
        Reports a warning.
        Parameters:
        res - used for source location information
        msgKey - the diagnostic message key
        args - arguments to the diagnostic message
      • exceptionToInvalidFormatAnnotation

        public javax.lang.model.element.AnnotationMirror exceptionToInvalidFormatAnnotation​(java.util.IllegalFormatException ex)
        Takes an exception that describes an invalid formatter string and, returns a syntax trees element that represents a InvalidFormat annotation with the exception's error message as value.
      • invalidFormatAnnotationToErrorMessage

        public java.lang.String invalidFormatAnnotationToErrorMessage​(javax.lang.model.element.AnnotationMirror anno)
        Takes a syntax tree element that represents a InvalidFormat annotation, and returns its value.
        Parameters:
        anno - an InvalidFormat annotation
        Returns:
        its value() element/field
      • categoriesToFormatAnnotation

        public javax.lang.model.element.AnnotationMirror categoriesToFormatAnnotation​(ConversionCategory[] args)
        Creates a @Format annotation with the given list as its value.
        Parameters:
        args - conversion categories for the @Format annotation
        Returns:
        a @Format annotation with the given list as its value
      • formatAnnotationToCategories

        public ConversionCategory[] formatAnnotationToCategories​(javax.lang.model.element.AnnotationMirror anno)
        Returns the value of a @Format annotation.
        Parameters:
        anno - a @Format annotation
        Returns:
        the annotation's value element