Class FormatterTreeUtil
- java.lang.Object
 - 
- org.checkerframework.checker.formatter.FormatterTreeUtil
 
 
- 
public class FormatterTreeUtil extends java.lang.ObjectThis class provides a collection of utilities to ease working with syntax trees that have something to do with Formatters. 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description classFormatterTreeUtil.FormatCallRepresents a format method invocation in the syntax tree.static classFormatterTreeUtil.InvocationTypeDescribes the ways a format method may be invoked.static classFormatterTreeUtil.Result<E>A wrapper around a value of type E, plus an ExpressionTree location. 
- 
Field Summary
Fields Modifier and Type Field Description BaseTypeCheckercheckerThe checker.protected javax.lang.model.element.ExecutableElementformatValueElementThe value() element/field of an @Format annotation.protected javax.lang.model.element.ExecutableElementinvalidFormatValueElementThe value() element/field of an @InvalidFormat annotation.javax.annotation.processing.ProcessingEnvironmentprocessingEnvThe processing environment. 
- 
Constructor Summary
Constructors Constructor Description FormatterTreeUtil(BaseTypeChecker checker) 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FormatterTreeUtil.Result<ConversionCategory[]>asFormatCallCategories(MethodInvocationNode node)javax.lang.model.element.AnnotationMirrorcategoriesToFormatAnnotation(ConversionCategory[] args)Creates a@Formatannotation with the given list as its value.@Nullable FormatterTreeUtil.FormatCallcreate(com.sun.source.tree.MethodInvocationTree invocationTree, AnnotatedTypeFactory atypeFactory)Creates a new FormatCall, or returns null.javax.lang.model.element.AnnotationMirrorexceptionToInvalidFormatAnnotation(java.util.IllegalFormatException ex)Takes an exception that describes an invalid formatter string and, returns a syntax trees element that represents aInvalidFormatannotation with the exception's error message as value.voidfailure(FormatterTreeUtil.Result<?> res, @CompilerMessageKey java.lang.String msgKey, java.lang.Object... args)Reports an error.ConversionCategory[]formatAnnotationToCategories(javax.lang.model.element.AnnotationMirror anno)Returns the value of a@Formatannotation.java.lang.StringinvalidFormatAnnotationToErrorMessage(javax.lang.model.element.AnnotationMirror anno)Takes a syntax tree element that represents aInvalidFormatannotation, and returns its value.booleanisAsFormatCall(MethodInvocationNode node, AnnotatedTypeFactory atypeFactory)Returns true if the call is to a method with the @ReturnsFormat annotation.booleanisFormatMethodCall(com.sun.source.tree.MethodInvocationTree tree, AnnotatedTypeFactory atypeFactory)Returns true iftreeis a call to a method annotated with@FormatMethod.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. 
- 
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
- 
FormatterTreeUtil
public FormatterTreeUtil(BaseTypeChecker checker)
 
 - 
 
- 
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. 
- 
asFormatCallCategories
public FormatterTreeUtil.Result<ConversionCategory[]> asFormatCallCategories(MethodInvocationNode node)
 
- 
isFormatMethodCall
public boolean isFormatMethodCall(com.sun.source.tree.MethodInvocationTree tree, AnnotatedTypeFactory atypeFactory)Returns true iftreeis a call to a method annotated with@FormatMethod.- Parameters:
 tree- a method callatypeFactory- a type factory- Returns:
 - true if 
treeis 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 @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 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
 
- 
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 aInvalidFormatannotation 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 aInvalidFormatannotation, 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@Formatannotation with the given list as its value.- Parameters:
 args- conversion categories for the@Formatannotation- Returns:
 - a 
@Formatannotation with the given list as its value 
 
- 
formatAnnotationToCategories
public ConversionCategory[] formatAnnotationToCategories(javax.lang.model.element.AnnotationMirror anno)
Returns the value of a@Formatannotation.- Parameters:
 anno- a@Formatannotation- Returns:
 - the annotation's 
valueelement 
 
 - 
 
 -