File: PuritySuggestionsClass.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 (164 lines) | stat: -rw-r--r-- 3,066 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import org.checkerframework.dataflow.qual.Deterministic;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.framework.test.*;
import testlib.util.*;

// various tests for the checker to automatically suggest pure methods (most methods have been
// copied from Purity.java)

class PuritySuggestionsClass {

    String f1, f2, f3;
    String[] a;

    // class with a (potentially) non-pure constructor
    private static class NonPureClass {
        String t;

        public NonPureClass() {
            t = "";
        }
    }

    // class with a pure constructor
    private static class PureClass {
        public PureClass() {}
    }

    // :: warning: (purity.more.pure)
    void nonpure() {}

    @Pure
    String pure() {
        return "";
    }

    String t3() {
        nonpure();
        return "";
    }

    // :: warning: (purity.more.pure)
    String t4() {
        pure();
        return "";
    }

    // :: warning: (purity.more.pure)
    int t5() {
        int i = 1;
        return i;
    }

    // :: warning: (purity.more.pure)
    int t6() {
        int j = 0;
        for (int i = 0; i < 10; i++) {
            j = j - i;
        }
        return j;
    }

    // :: warning: (purity.more.pure)
    String t7() {
        if (true) {
            return "a";
        }
        return "";
    }

    // :: warning: (purity.more.pure)
    int t8() {
        return 1 - 2 / 3 * 2 % 2;
    }

    // :: warning: (purity.more.pure)
    String t9() {
        return "b" + "a";
    }

    String t10() {
        f1 = "";
        f2 = "";
        return "";
    }

    String t11(PuritySuggestionsClass l) {
        l.a[0] = "";
        return "";
    }

    String t12(String[] s) {
        s[0] = "";
        return "";
    }

    String t13() {
        PureClass p = new PureClass();
        return "";
    }

    // :: warning: (purity.more.pure)
    String t14() {
        String i = "";
        i = "a";
        return i;
    }

    // :: warning: (purity.more.pure)
    String t15() {
        String[] s = new String[1];
        return s[0];
    }

    // :: warning: (purity.more.sideeffectfree)
    String t16() {
        try {
            int i = 1 / 0;
        } catch (Throwable t) {
            // ...
        }
        return "";
    }

    // :: warning: (purity.more.sideeffectfree)
    String t16b() {
        try {
            int i = 1 / 0;
        } catch (Throwable t) {
            // ...
        }
        return "";
    }

    // :: warning: (purity.more.sideeffectfree)
    String t16c() {
        try {
            int i = 1 / 0;
        } catch (Throwable t) {
            // ...
        }
        return "";
    }

    // :: warning: (purity.more.pure)
    String t17() {
        return "";
    }

    @Deterministic
    // :: warning: (purity.more.sideeffectfree)
    String t18() {
        return "";
    }

    // :: warning: (purity.more.deterministic)
    String t19() {
        return t18();
    }

    String t12() {
        NonPureClass p = new NonPureClass();
        return "";
    }
}