1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
// Example from the manual
import static org.checkerframework.checker.i18nformatter.qual.I18nConversionCategory.DATE;
import static org.checkerframework.checker.i18nformatter.qual.I18nConversionCategory.NUMBER;
import org.checkerframework.checker.i18nformatter.qual.I18nFormat;
public class ManualExampleI18nFormatter {
void m(boolean flag) {
@I18nFormat({NUMBER, DATE}) String f;
f = "{0, number, #.#} {1, date}"; // OK
f = "{0, number} {1}"; // OK, GENERAL is weaker (less restrictive) than DATE
f = "{0} {1, date}"; // OK, GENERAL is weaker (less restrictive) than NUMBER
// :: warning: (i18nformat.missing.arguments)
f = "{0, number}"; // warning: last argument is ignored
// :: warning: (i18nformat.missing.arguments)
f = "{0}"; // warning: last argument is ignored
// :: warning: (i18nformat.missing.arguments)
f = flag ? "{0, number} {1}" : "{0, number}";
if (flag) {
f = "{0, number} {1}";
} else {
// :: warning: (i18nformat.missing.arguments)
f = "{0, number}";
}
@I18nFormat({NUMBER, DATE}) String f2 = f;
// :: error: (assignment.type.incompatible)
f = "{0, number} {1, number}"; // error: NUMBER is stronger (more restrictive) than DATE
// :: error: (i18nformat.excess.arguments) :: error: (assignment.type.incompatible)
f = "{0} {1} {2}"; // error: too many arguments
}
}
|