Class I18nFormatterTreeUtil
java.lang.Object
org.checkerframework.checker.i18nformatter.I18nFormatterTreeUtil
This class provides a collection of utilities to ease working with syntax trees that have
something to do with I18nFormatters.
- See the Checker Framework Manual:
- Internationalization Format String Checker
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Describe the format annotation type.class
Represents a format method invocation in the syntax tree. -
Field Summary
Modifier and TypeFieldDescriptionfinal BaseTypeChecker
The checker.protected final ExecutableElement
The value() element/field of an @I18nFormatFor annotation.protected final ExecutableElement
The value() element/field of an @I18nFormat annotation.protected final ExecutableElement
The value() element/field of an @I18nInvalidFormat annotation.final ProcessingEnvironment
The processing environment. -
Constructor Summary
ConstructorDescriptionI18nFormatterTreeUtil
(BaseTypeChecker checker) Creates a new I18nFormatterTreeUtil. -
Method Summary
Modifier and TypeMethodDescriptionCreates a@
I18nFormat
annotation with the given list as its value.createFormatForCall
(MethodInvocationTree tree, I18nFormatterAnnotatedTypeFactory atypeFactory) Returns an I18nFormatCall instance, only if there is an@I18nFormatFor
annotation.Takes an exception that describes an invalid formatter string and returns a syntax trees element that represents aI18nInvalidFormat
annotation with the exception's error message as value.final void
failure
(FormatterTreeUtil.Result<?> res, @CompilerMessageKey String msgKey, Object... args) Reports an error.Takes a syntax tree element that represents aI18nInvalidFormat
annotation, and returns its value.boolean
isHasFormatCall
(MethodInvocationNode node, AnnotatedTypeFactory atypeFactory) Returns true if the call is to a method with the @I18nChecksFormat annotation.boolean
isIsFormatCall
(MethodInvocationNode node, AnnotatedTypeFactory atypeFactory) Returns true if the call is to a method with the @I18nValidFormat annotation.boolean
isMakeFormatCall
(MethodInvocationNode node, AnnotatedTypeFactory atypeFactory) Returns true if the call is to a method with the @I18nMakeFormat annotation.makeFormatCallCategories
(MethodInvocationNode node, I18nFormatterAnnotatedTypeFactory atypeFactory) final void
warning
(FormatterTreeUtil.Result<?> res, @CompilerMessageKey String msgKey, Object... args) Reports a warning.
-
Field Details
-
checker
The checker. -
processingEnv
The processing environment. -
i18nFormatValueElement
The value() element/field of an @I18nFormat annotation. -
i18nFormatForValueElement
The value() element/field of an @I18nFormatFor annotation. -
i18nInvalidFormatValueElement
The value() element/field of an @I18nInvalidFormat annotation.
-
-
Constructor Details
-
I18nFormatterTreeUtil
Creates a new I18nFormatterTreeUtil.- Parameters:
checker
- the checker
-
-
Method Details
-
exceptionToInvalidFormatAnnotation
Takes an exception that describes an invalid formatter string and returns a syntax trees element that represents aI18nInvalidFormat
annotation with the exception's error message as value. -
invalidFormatAnnotationToErrorMessage
Takes a syntax tree element that represents aI18nInvalidFormat
annotation, and returns its value.- Parameters:
anno
- an I18nInvalidFormat annotation- Returns:
- its value() element/field, within double-quotes
-
categoriesToFormatAnnotation
Creates a@
I18nFormat
annotation with the given list as its value.- Parameters:
args
- conversion categories for the@Format
annotation- Returns:
- a
@
I18nFormat
annotation with the given list as its value
-
formatAnnotationToCategories
- Parameters:
anno
- an@
I18nFormat
annotation- Returns:
- the
@
I18nFormat
annotation'svalue
element
-
isHasFormatCall
Returns true if the call is to a method with the @I18nChecksFormat annotation. An example of such a method is I18nFormatUtil.hasFormat. -
isIsFormatCall
Returns true if the call is to a method with the @I18nValidFormat annotation. An example of such a method is I18nFormatUtil.isFormat. -
isMakeFormatCall
Returns true if the call is to a method with the @I18nMakeFormat annotation. An example of such a method is ResourceBundle.getString. -
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
-
getHasFormatCallCategories
public FormatterTreeUtil.Result<I18nConversionCategory[]> getHasFormatCallCategories(MethodInvocationNode node) -
makeFormatCallCategories
public FormatterTreeUtil.Result<I18nConversionCategory[]> makeFormatCallCategories(MethodInvocationNode node, I18nFormatterAnnotatedTypeFactory atypeFactory) -
createFormatForCall
public @Nullable I18nFormatterTreeUtil.I18nFormatCall createFormatForCall(MethodInvocationTree tree, I18nFormatterAnnotatedTypeFactory atypeFactory) Returns an I18nFormatCall instance, only if there is an@I18nFormatFor
annotation. Otherwise, returns null.- Parameters:
tree
- method invocation treeatypeFactory
- type factory- Returns:
- an I18nFormatCall instance, only if there is an
@I18nFormatFor
annotation. Otherwise, returns null.
-