Top Description Fields Constructors Methods
org.checkerframework.checker.formatter.qual

public final Enum ConversionCategory

extends Enum<ConversionCategory>
Class Inheritance
Annotations
@SuppressWarnings:unchecked
@AnnotatedFor:nullness
Imports
java.math.BigDecimal, .BigInteger, java.util.ArrayList, .Arrays, .Calendar, .Date, .HashSet, .List, .Set, .StringJoiner, org.checkerframework.checker.nullness.qual.Nullable, org.checkerframework.dataflow.qual.Pure, org.checkerframework.framework.qual.AnnotatedFor

Elements of this enumeration are used in a Format annotation to indicate the valid types that may be passed as a format parameter. For example:
@Format({GENERAL, INT}) String f = "String '%s' has length %d";

String.format(f, "Example", 7);
The annotation indicates that the format string requires any Object as the first parameter (ConversionCategory#GENERAL) and an integer as the second parameter (ConversionCategory#INT).
See Also
Format

Field Summary

Modifier and TypeField and Description
public static final ConversionCategory
CHAR

Use if the parameter is of a basic types which represent Unicode characters: char, Character, byte, Byte, short, and Short.

public static final ConversionCategory
CHAR_AND_INT

Use if the parameter is both a char and an int.

public final @Nullable String
chars

The format specifier characters.

private static final ConversionCategory[]
conversionCategoriesForIntersect

Conversion categories that need to be considered by intersect.

private static final ConversionCategory[]
conversionCategoriesForUnion

Conversion categories that need to be considered by union.

private static final ConversionCategory[]
conversionCategoriesWithChar

The conversion categories that have a corresponding conversion character.

public static final ConversionCategory
FLOAT

Use if the parameter is a floating-point type: float, Float, double, Double, and BigDecimal.

public static final ConversionCategory
GENERAL

Use if the parameter can be of any type.

public static final ConversionCategory
INT

Use if the parameter is an integral type: byte, Byte, short, Short, int and Integer, long, Long, and BigInteger.

public static final ConversionCategory
INT_AND_TIME

Use if the parameter is both an int and a time.

public static final ConversionCategory
NULL

Use if no object of any type can be passed as parameter.

public static final ConversionCategory
TIME

Use if the parameter is a type which is capable of encoding a date or time: long, Long, Calendar, and Date.

public final @Nullable Class<?>[]
types

The argument types.

public static final ConversionCategory
UNUSED

Use if a parameter is not used by the formatter.

Constructor Summary

AccessConstructor and Description
private
ConversionCategory(@Nullable String
the format specifier characters. Null means users cannot specify it directly.
chars
,
@Nullable Class<?>...
the argument types. Null means every type.
types
)

Create a new conversion category.

Method Summary

Modifier and TypeMethod and Description
private static <E> Set<E>
arrayToSet(E[] a)

public static ConversionCategory

Returns:

the category for the given conversion character
fromConversionChar
(char
a conversion character
c
)

Converts a conversion character to a category.

public static ConversionCategory

Returns:

the intersection of the two categories (their greatest lower bound)
intersect
(ConversionCategory
a category
a
,
ConversionCategory
a category
b
)

Returns the intersection of two categories.

public boolean

Returns:

true if argType can be an argument used by this format specifier
isAssignableFrom
(Class<?>
an argument type
argType
)

Returns true if argType can be an argument used by this format specifier.

public static boolean
public String
toString()

Overrides java.lang.Enum.toString.

Returns a pretty printed ConversionCategory.
public static ConversionCategory

Returns:

the union of the two categories (their least upper bound)
union
(ConversionCategory
a category
a
,
ConversionCategory
a category
b
)

Returns the union of two categories.

private static @Nullable Class<? extends Object>

Returns:

the unwrapped primitive, or null
unwrapPrimitive
(Class<?>
a class
c
)

If the given class is a primitive wrapper, return the corresponding primitive class.

public static ConversionCategory
public static ConversionCategory[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinalvalueOf

Field Detail

CHARback to summary
public static final ConversionCategory CHAR

Use if the parameter is of a basic types which represent Unicode characters: char, Character, byte, Byte, short, and Short. This conversion may also be applied to the types int and Integer when Character.isValidCodePoint(int) returns true. Applicable for conversions c, C.

CHAR_AND_INTback to summary
public static final ConversionCategory CHAR_AND_INT

Use if the parameter is both a char and an int.

In a format string, multiple conversions may be applied to the same parameter. This is seldom needed, but the following is an example of such use:

  format("Test %1$c %1$d", (int)42);
In this example, the first parameter is interpreted as both a character and an int, therefore the parameter must be compatible with both conversion, and can therefore neither be char nor long. This intersection of conversions is called CHAR_AND_INT.

One other conversion intersection is interesting, namely the intersection of INT and TIME, resulting in INT_AND_TIME.

All other intersection either lead to an already existing type, or NULL, in which case it is illegal to pass object's of any type as parameter.

charsback to summary
public final @Nullable String chars

The format specifier characters. Null means users cannot specify it directly.

conversionCategoriesForIntersectback to summary
private static final ConversionCategory[] conversionCategoriesForIntersect

Conversion categories that need to be considered by intersect.

conversionCategoriesForUnionback to summary
private static final ConversionCategory[] conversionCategoriesForUnion

Conversion categories that need to be considered by union.

conversionCategoriesWithCharback to summary
private static final ConversionCategory[] conversionCategoriesWithChar

The conversion categories that have a corresponding conversion character. This lacks UNUSED, TIME_AND_INT, etc.

FLOATback to summary
public static final ConversionCategory FLOAT

Use if the parameter is a floating-point type: float, Float, double, Double, and BigDecimal. Applicable for conversions e, E, f, g, G, a, A.

GENERALback to summary
public static final ConversionCategory GENERAL

Use if the parameter can be of any type. Applicable for conversions b, B, h, H, s, S.

INTback to summary
public static final ConversionCategory INT

Use if the parameter is an integral type: byte, Byte, short, Short, int and Integer, long, Long, and BigInteger. Applicable for conversions d, o, x, X.

INT_AND_TIMEback to summary
public static final ConversionCategory INT_AND_TIME

Use if the parameter is both an int and a time.

See Also
CHAR_AND_INT
NULLback to summary
public static final ConversionCategory NULL

Use if no object of any type can be passed as parameter. In this case, the only legal value is null. This is seldomly needed, and indicates an error in most cases. For example:

  format("Test %1$f %1$d", null);
Only null can be legally passed, passing a value such as 4 or 4.2 would lead to an exception.
TIMEback to summary
public static final ConversionCategory TIME

Use if the parameter is a type which is capable of encoding a date or time: long, Long, Calendar, and Date. Applicable for conversions t, T.

Annotations
@SuppressWarnings:JdkObsolete
typesback to summary
public final @Nullable Class<?>[] types

The argument types. Null means every type.

Annotations
@SuppressWarnings:ImmutableEnumChecker
UNUSEDback to summary
public static final ConversionCategory UNUSED

Use if a parameter is not used by the formatter. This is seldomly needed, and indicates an error in most cases. For example:

  format("Test %1$s %3$s", "a","unused","b");
Only the first "a" and third "b" parameters are used, the second "unused" parameter is ignored.

Constructor Detail

ConversionCategoryback to summary
private ConversionCategory(@Nullable String chars, @Nullable Class<?>... types)

Create a new conversion category.

Parameters
chars:@Nullable String

the format specifier characters. Null means users cannot specify it directly.

types:@Nullable Class<?>[]

the argument types. Null means every type.

Method Detail

arrayToSetback to summary
private static <E> Set<E> arrayToSet(E[] a)
fromConversionCharback to summary
public static ConversionCategory fromConversionChar(char c)

Converts a conversion character to a category. For example:

ConversionCategory.fromConversionChar('d') == ConversionCategory.INT
Parameters
c:char

a conversion character

Returns:ConversionCategory

the category for the given conversion character

Annotations
@SuppressWarnings:nullness:dereference.of.nullable
intersectback to summary
public static ConversionCategory intersect(ConversionCategory a, ConversionCategory b)

Returns the intersection of two categories. This is seldomly needed.

ConversionCategory.intersect(INT, TIME) == INT_AND_TIME;
Parameters
a:ConversionCategory

a category

b:ConversionCategory

a category

Returns:ConversionCategory

the intersection of the two categories (their greatest lower bound)

isAssignableFromback to summary
public boolean isAssignableFrom(Class<?> argType)

Returns true if argType can be an argument used by this format specifier.

Parameters
argType:Class<?>

an argument type

Returns:boolean

true if argType can be an argument used by this format specifier

isSubsetOfback to summary
public static boolean isSubsetOf(ConversionCategory a, ConversionCategory b)
toStringback to summary
public String toString()

Overrides java.lang.Enum.toString.

Returns a pretty printed ConversionCategory.

Returns:String

Doc from java.lang.Enum.toString.

the name of this enum constant

Annotations
@Pure
@Override
unionback to summary
public static ConversionCategory union(ConversionCategory a, ConversionCategory b)

Returns the union of two categories. This is seldomly needed.

ConversionCategory.union(INT, TIME) == GENERAL;
Parameters
a:ConversionCategory

a category

b:ConversionCategory

a category

Returns:ConversionCategory

the union of the two categories (their least upper bound)

unwrapPrimitiveback to summary
private static @Nullable Class<? extends Object> unwrapPrimitive(Class<?> c)

If the given class is a primitive wrapper, return the corresponding primitive class. Otherwise return null.

Parameters
c:Class<?>

a class

Returns:@Nullable Class<? extends Object>

the unwrapped primitive, or null

valueOfback to summary
public static ConversionCategory valueOf(String name)
valuesback to summary
public static ConversionCategory[] values()