File: TestProgram.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 (80 lines) | stat: -rw-r--r-- 3,245 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import org.checkerframework.checker.guieffect.qual.AlwaysSafe;
import org.checkerframework.checker.guieffect.qual.UI;
import org.checkerframework.checker.guieffect.qual.UIEffect;
import packagetests.SafeByDecl;
import packagetests.UIByPackageDecl;

public class TestProgram {
    public void nonUIStuff(
            final UIElement e,
            final GenericTaskUIConsumer uicons,
            final GenericTaskSafeConsumer safecons) {
        // :: error: (call.invalid.ui)
        e.dangerous(); // should be bad
        e.runOnUIThread(
                new IAsyncUITask() {
                    final UIElement e2 = e;

                    @Override
                    public void doStuff() { // should inherit UI effect
                        e2.dangerous(); // should be okay
                    }
                });
        uicons.runAsync(
                new @UI IGenericTask() {
                    final UIElement e2 = e;

                    @Override
                    public void doGenericStuff() { // Should be inst. w/ @UI eff.
                        e2.dangerous(); // should be okay
                    }
                });
        safecons.runAsync(
                new @AlwaysSafe IGenericTask() {
                    final UIElement e2 = e;

                    @Override
                    public void doGenericStuff() { // Should be inst. w/ @AlwaysSafe
                        // :: error: (call.invalid.ui)
                        e2.dangerous(); // should be an error
                        safecons.runAsync(this); // Should be okay, this:@AlwaysSafe
                    }
                });
        safecons.runAsync(
                // :: error: (argument.type.incompatible)
                new @UI IGenericTask() {
                    final UIElement e2 = e;

                    @Override
                    public void doGenericStuff() { // Should be inst. w/ @UI
                        e2.dangerous(); // should be ok
                        // :: error: (argument.type.incompatible)
                        safecons.runAsync(this); // Should be error, this:@UI
                    }
                });
        // Test that the package annotation works
        // :: error: (call.invalid.ui)
        UIByPackageDecl.implicitlyUI();
        // Test that @SafeType works: SafeByDecl is inside a @UIPackage
        SafeByDecl.safeByTypeDespiteUIPackage();
        safecons.runAsync(
                // :: error: (argument.type.incompatible)
                new IGenericTask() {
                    @Override
                    public void doGenericStuff() {
                        // Safe here due to anonymous inner class effect inference, but will trigger
                        // an error above due to safecons.runAsync not taking an @UI IGenericTask.
                        UIByPackageDecl.implicitlyUI();
                    }
                });
        safecons.runAsync(
                new IGenericTask() {
                    @Override
                    @UIEffect
                    // :: error: (override.effect.invalid.nonui)
                    public void doGenericStuff() {
                        UIByPackageDecl.implicitlyUI();
                    }
                });
    }
}