Class I18nFormatterTreeUtil
- java.lang.Object
 - 
- org.checkerframework.checker.i18nformatter.I18nFormatterTreeUtil
 
 
- 
public class I18nFormatterTreeUtil extends java.lang.ObjectThis 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
Nested Classes Modifier and Type Class Description static classI18nFormatterTreeUtil.FormatTypeDescribe the format annotation type.classI18nFormatterTreeUtil.I18nFormatCallRepresents a format method invocation in the syntax tree. 
- 
Field Summary
Fields Modifier and Type Field Description BaseTypeCheckercheckerThe checker.protected javax.lang.model.element.ExecutableElementi18nFormatForValueElementThe value() element/field of an @I18nFormatFor annotation.protected javax.lang.model.element.ExecutableElementi18nFormatValueElementThe value() element/field of an @I18nFormat annotation.protected javax.lang.model.element.ExecutableElementi18nInvalidFormatValueElementThe value() element/field of an @I18nInvalidFormat annotation.javax.annotation.processing.ProcessingEnvironmentprocessingEnvThe processing environment. 
- 
Constructor Summary
Constructors Constructor Description I18nFormatterTreeUtil(BaseTypeChecker checker)Creates a new I18nFormatterTreeUtil. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.lang.model.element.AnnotationMirrorcategoriesToFormatAnnotation(I18nConversionCategory[] args)Creates a@I18nFormatannotation with the given list as its value.@Nullable I18nFormatterTreeUtil.I18nFormatCallcreateFormatForCall(com.sun.source.tree.MethodInvocationTree tree, I18nFormatterAnnotatedTypeFactory atypeFactory)Returns an I18nFormatCall instance, only if there is an@I18nFormatForannotation.javax.lang.model.element.AnnotationMirrorexceptionToInvalidFormatAnnotation(java.lang.IllegalArgumentException ex)Takes an exception that describes an invalid formatter string and returns a syntax trees element that represents aI18nInvalidFormatannotation with the exception's error message as value.voidfailure(FormatterTreeUtil.Result<?> res, @CompilerMessageKey java.lang.String msgKey, java.lang.Object... args)Reports an error.I18nConversionCategory[]formatAnnotationToCategories(javax.lang.model.element.AnnotationMirror anno)FormatterTreeUtil.Result<I18nConversionCategory[]>getHasFormatCallCategories(MethodInvocationNode node)java.lang.StringinvalidFormatAnnotationToErrorMessage(javax.lang.model.element.AnnotationMirror anno)Takes a syntax tree element that represents aI18nInvalidFormatannotation, and returns its value.booleanisHasFormatCall(MethodInvocationNode node, AnnotatedTypeFactory atypeFactory)Returns true if the call is to a method with the @I18nChecksFormat annotation.booleanisIsFormatCall(MethodInvocationNode node, AnnotatedTypeFactory atypeFactory)Returns true if the call is to a method with the @I18nValidFormat annotation.booleanisMakeFormatCall(MethodInvocationNode node, AnnotatedTypeFactory atypeFactory)Returns true if the call is to a method with the @I18nMakeFormat annotation.FormatterTreeUtil.Result<I18nConversionCategory[]>makeFormatCallCategories(MethodInvocationNode node, I18nFormatterAnnotatedTypeFactory atypeFactory)voidwarning(FormatterTreeUtil.Result<?> res, @CompilerMessageKey java.lang.String msgKey, java.lang.Object... args)Reports a warning. 
 - 
 
- 
- 
Field Detail
- 
checker
public final BaseTypeChecker checker
The checker. 
- 
processingEnv
public final javax.annotation.processing.ProcessingEnvironment processingEnv
The processing environment. 
- 
i18nFormatValueElement
protected final javax.lang.model.element.ExecutableElement i18nFormatValueElement
The value() element/field of an @I18nFormat annotation. 
- 
i18nFormatForValueElement
protected final javax.lang.model.element.ExecutableElement i18nFormatForValueElement
The value() element/field of an @I18nFormatFor annotation. 
- 
i18nInvalidFormatValueElement
protected final javax.lang.model.element.ExecutableElement i18nInvalidFormatValueElement
The value() element/field of an @I18nInvalidFormat annotation. 
 - 
 
- 
Constructor Detail
- 
I18nFormatterTreeUtil
public I18nFormatterTreeUtil(BaseTypeChecker checker)
Creates a new I18nFormatterTreeUtil.- Parameters:
 checker- the checker
 
 - 
 
- 
Method Detail
- 
exceptionToInvalidFormatAnnotation
public javax.lang.model.element.AnnotationMirror exceptionToInvalidFormatAnnotation(java.lang.IllegalArgumentException ex)
Takes an exception that describes an invalid formatter string and returns a syntax trees element that represents aI18nInvalidFormatannotation 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 aI18nInvalidFormatannotation, and returns its value.- Parameters:
 anno- an I18nInvalidFormat annotation- Returns:
 - its value() element/field, within double-quotes
 
 
- 
categoriesToFormatAnnotation
public javax.lang.model.element.AnnotationMirror categoriesToFormatAnnotation(I18nConversionCategory[] args)
Creates a@I18nFormatannotation with the given list as its value.- Parameters:
 args- conversion categories for the@Formatannotation- Returns:
 - a 
@I18nFormatannotation with the given list as its value 
 
- 
formatAnnotationToCategories
public I18nConversionCategory[] formatAnnotationToCategories(javax.lang.model.element.AnnotationMirror anno)
- Parameters:
 anno- an@I18nFormatannotation- Returns:
 - the 
@I18nFormatannotation'svalueelement 
 
- 
isHasFormatCall
public boolean isHasFormatCall(MethodInvocationNode node, AnnotatedTypeFactory atypeFactory)
Returns true if the call is to a method with the @I18nChecksFormat annotation. An example of such a method is I18nFormatUtil.hasFormat. 
- 
isIsFormatCall
public boolean isIsFormatCall(MethodInvocationNode node, AnnotatedTypeFactory atypeFactory)
Returns true if the call is to a method with the @I18nValidFormat annotation. An example of such a method is I18nFormatUtil.isFormat. 
- 
isMakeFormatCall
public boolean isMakeFormatCall(MethodInvocationNode node, AnnotatedTypeFactory atypeFactory)
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 java.lang.String msgKey, java.lang.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 java.lang.String msgKey, java.lang.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(com.sun.source.tree.MethodInvocationTree tree, I18nFormatterAnnotatedTypeFactory atypeFactory)
Returns an I18nFormatCall instance, only if there is an@I18nFormatForannotation. Otherwise, returns null.- Parameters:
 tree- method invocation treeatypeFactory- type factory- Returns:
 - an I18nFormatCall instance, only if there is an 
@I18nFormatForannotation. Otherwise, returns null. 
 
 - 
 
 -