File: ManualExampleI18nFormatter.java

package info (click to toggle)
checker-framework-java 3.2.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 22,840 kB
  • sloc: java: 145,910; xml: 839; sh: 518; makefile: 401; perl: 26
file content (37 lines) | stat: -rw-r--r-- 1,482 bytes parent folder | download | duplicates (3)
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
    }
}