Class FormatterTreeUtil

java.lang.Object
org.checkerframework.checker.formatter.FormatterTreeUtil

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

    • checker

      public final BaseTypeChecker checker
      The checker.
    • processingEnv

      public final ProcessingEnvironment processingEnv
      The processing environment.
    • formatValueElement

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

      protected final ExecutableElement invalidFormatValueElement
      The value() element/field of an @InvalidFormat annotation.
  • Constructor Details

  • Method Details

    • 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.
    • asFormatCallCategories

      public FormatterTreeUtil.Result<ConversionCategory[]> asFormatCallCategories(MethodInvocationNode node)
    • isFormatMethodCall

      public boolean isFormatMethodCall(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

      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 String msgKey, 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 String msgKey, 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 AnnotationMirror exceptionToInvalidFormatAnnotation(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 String invalidFormatAnnotationToErrorMessage(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 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(AnnotationMirror anno)
      Returns the value of a @Format annotation.
      Parameters:
      anno - a @Format annotation
      Returns:
      the annotation's value element