File: ManualExampleFormatter.java

package info (click to toggle)
checker-framework-java 3.2.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,104 kB
  • sloc: java: 145,916; xml: 839; sh: 518; makefile: 404; perl: 26
file content (36 lines) | stat: -rw-r--r-- 1,081 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
// Example from the manual

import static org.checkerframework.checker.formatter.qual.ConversionCategory.FLOAT;
import static org.checkerframework.checker.formatter.qual.ConversionCategory.INT;

import org.checkerframework.checker.formatter.qual.Format;

public class ManualExampleFormatter {

    void m(boolean flag) {

        @Format({FLOAT, INT}) String f;

        f = "%f %d"; // OK
        f = "%s %d"; // OK, %s is weaker than %f
        // :: warning: (format.missing.arguments)
        f = "%f"; // warning: last argument is ignored
        // :: warning: (format.missing.arguments)
        f = flag ? "%f %d" : "%f";

        if (flag) {
            f = "%f %d";
        } else {
            // :: warning: (format.missing.arguments)
            f = "%f";
        }
        @Format({FLOAT, INT}) String f2 = f;

        // :: error: (assignment.type.incompatible)
        f = "%f %d %s"; // error: too many arguments
        // :: error: (assignment.type.incompatible)
        f = "%d %d"; // error: %d is not weaker than %f

        String.format(f, 0.8, 42);
    }
}