File: HasFormat.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 (62 lines) | stat: -rw-r--r-- 2,249 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import java.text.MessageFormat;
import java.util.Date;
import org.checkerframework.checker.i18nformatter.I18nFormatUtil;
import org.checkerframework.checker.i18nformatter.qual.I18nConversionCategory;

public class HasFormat {

    void test1(String format) {
        if (I18nFormatUtil.hasFormat(
                format, I18nConversionCategory.GENERAL, I18nConversionCategory.NUMBER)) {
            MessageFormat.format(format, "S", 1);
            // :: warning: (i18nformat.missing.arguments)
            MessageFormat.format(format, "S");
            // :: error: (argument.type.incompatible)
            MessageFormat.format(format, "S", "S");
            // :: warning: (i18nformat.excess.arguments)
            MessageFormat.format(format, "S", 1, 2);
        }
    }

    void test2(String format) {
        if (!I18nFormatUtil.hasFormat(
                format, I18nConversionCategory.GENERAL, I18nConversionCategory.NUMBER)) {
            // :: error: (i18nformat.string.invalid)
            MessageFormat.format(format, "S", 1);
        }
    }

    void test3(String format) {
        if (I18nFormatUtil.hasFormat(
                format,
                I18nConversionCategory.GENERAL,
                I18nConversionCategory.UNUSED,
                I18nConversionCategory.GENERAL)) {
            // :: warning: (i18nformat.argument.unused)
            MessageFormat.format(format, "S", 1, "S");
        }
    }

    void test4(String format) throws Exception {
        // :: error: (i18nformat.string.invalid)
        MessageFormat.format(format, "S");
        if (I18nFormatUtil.hasFormat(format, I18nConversionCategory.GENERAL)) {
            MessageFormat.format(format, "S");
            MessageFormat.format(format, new Date());
            MessageFormat.format(format, 1);
        } else {
            throw new Exception();
        }
    }

    void tes5(String format) {
        if (I18nFormatUtil.hasFormat(format, I18nConversionCategory.NUMBER)) {
            // :: error: (argument.type.incompatible)
            MessageFormat.format(format, "S");
            MessageFormat.format(format, 1);
        } else {
            // :: error: (i18nformat.string.invalid)
            MessageFormat.format(format, 1);
        }
    }
}