Class FormatterTreeUtil
java.lang.Object
org.checkerframework.checker.formatter.FormatterTreeUtil
This class provides a collection of utilities to ease working with syntax trees that have
something to do with Formatters.
-
Nested Class Summary
Modifier and TypeClassDescriptionclass
Represents a format method invocation in the syntax tree.static enum
Describes the ways a format method may be invoked.static class
A wrapper around a value of type E, plus an ExpressionTree location. -
Field Summary
Modifier and TypeFieldDescriptionfinal BaseTypeChecker
The checker.protected final ExecutableElement
The value() element/field of an @Format annotation.protected final ExecutableElement
The value() element/field of an @InvalidFormat annotation.final ProcessingEnvironment
The processing environment. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionCreates a@
Format
annotation with the given list as its value.create
(MethodInvocationTree invocationTree, AnnotatedTypeFactory atypeFactory) Creates a new FormatCall, or returns null.Takes an exception that describes an invalid formatter string and, returns a syntax trees element that represents aInvalidFormat
annotation with the exception's error message as value.final void
failure
(FormatterTreeUtil.Result<?> res, @CompilerMessageKey String msgKey, Object... args) Reports an error.Returns the value of a@
Format
annotation.Takes a syntax tree element that represents aInvalidFormat
annotation, and returns its value.boolean
isAsFormatCall
(MethodInvocationNode node, AnnotatedTypeFactory atypeFactory) Returns true if the call is to a method with the @ReturnsFormat annotation.boolean
isFormatMethodCall
(MethodInvocationTree tree, AnnotatedTypeFactory atypeFactory) Returns true iftree
is a call to a method annotated with@FormatMethod
.final void
warning
(FormatterTreeUtil.Result<?> res, @CompilerMessageKey String msgKey, Object... args) Reports a warning.
-
Field Details
-
checker
The checker. -
processingEnv
The processing environment. -
formatValueElement
The value() element/field of an @Format annotation. -
invalidFormatValueElement
The value() element/field of an @InvalidFormat annotation.
-
-
Constructor Details
-
FormatterTreeUtil
-
-
Method Details
-
isAsFormatCall
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
Returns true iftree
is a call to a method annotated with@FormatMethod
.- Parameters:
tree
- a method callatypeFactory
- a type factory- Returns:
- true if
tree
is a call to a method annotated with@FormatMethod
-
create
public @Nullable FormatterTreeUtil.FormatCall create(MethodInvocationTree invocationTree, AnnotatedTypeFactory atypeFactory) Creates a new FormatCall, or returns null.- Parameters:
invocationTree
- a method invocation, where the method is annotated @FormatMethodatypeFactory
- 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 informationmsgKey
- the diagnostic message keyargs
- 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 informationmsgKey
- the diagnostic message keyargs
- arguments to the diagnostic message
-
exceptionToInvalidFormatAnnotation
Takes an exception that describes an invalid formatter string and, returns a syntax trees element that represents aInvalidFormat
annotation with the exception's error message as value. -
invalidFormatAnnotationToErrorMessage
Takes a syntax tree element that represents aInvalidFormat
annotation, and returns its value.- Parameters:
anno
- an InvalidFormat annotation- Returns:
- its value() element/field
-
categoriesToFormatAnnotation
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
Returns the value of a@
Format
annotation.- Parameters:
anno
- a@
Format
annotation- Returns:
- the annotation's
value
element
-