Class FormatterTreeUtil
- java.lang.Object
-
- org.checkerframework.checker.formatter.FormatterTreeUtil
-
public class FormatterTreeUtil extends java.lang.Object
This 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 class
FormatterTreeUtil.FormatCall
Represents a format method invocation in the syntax tree.static class
FormatterTreeUtil.InvocationType
Describes the ways a format method may be invoked.static class
FormatterTreeUtil.Result<E>
A wrapper around a value of type E, plus an ExpressionTree location.
-
Field Summary
Fields Modifier and Type Field Description BaseTypeChecker
checker
The checker.protected javax.lang.model.element.ExecutableElement
formatValueElement
The value() element/field of an @Format annotation.protected javax.lang.model.element.ExecutableElement
invalidFormatValueElement
The value() element/field of an @InvalidFormat annotation.javax.annotation.processing.ProcessingEnvironment
processingEnv
The 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.AnnotationMirror
categoriesToFormatAnnotation(ConversionCategory[] args)
Creates a@
Format
annotation with the given list as its value.@Nullable FormatterTreeUtil.FormatCall
create(com.sun.source.tree.MethodInvocationTree invocationTree, AnnotatedTypeFactory atypeFactory)
Creates a new FormatCall, or returns null.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 aInvalidFormat
annotation with the exception's error message as value.void
failure(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@
Format
annotation.java.lang.String
invalidFormatAnnotationToErrorMessage(javax.lang.model.element.AnnotationMirror anno)
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(com.sun.source.tree.MethodInvocationTree tree, AnnotatedTypeFactory atypeFactory)
Returns true iftree
is a call to a method annotated with@FormatMethod
.void
warning(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 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(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 aInvalidFormat
annotation 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 aInvalidFormat
annotation, 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@
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(javax.lang.model.element.AnnotationMirror anno)
Returns the value of a@
Format
annotation.- Parameters:
anno
- a@
Format
annotation- Returns:
- the annotation's
value
element
-
-