Debian Codegraph @

framework/tests/purity-suggestions/PuritySuggestionsClass.java

raw
1 import org.checkerframework.dataflow.qual.Deterministic;
2 import org.checkerframework.dataflow.qual.Pure;
3 import org.checkerframework.framework.test.*;
4 import testlib.util.*;
5
6 // various tests for the checker to automatically suggest pure methods (most methods have been
7 // copied from Purity.java)
8
9 class PuritySuggestionsClass {
10
11 String f1, f2, f3;
12 String[] a;
13
14 // class with a (potentially) non-pure constructor
15 private static class NonPureClass {
16 String t;
17
18 public NonPureClass() {
19 t = "";
20 }
21 }
22
23 // class with a pure constructor
24 private static class PureClass {
25 public PureClass() {}
26 }
27
28 // :: warning: (purity.more.pure)
29 void nonpure() {}
30
31 @Pure
32 String pure() {
33 return "";
34 }
35
36 String t3() {
37 nonpure();
38 return "";
39 }
40
41 // :: warning: (purity.more.pure)
42 String t4() {
43 pure();
44 return "";
45 }
46
47 // :: warning: (purity.more.pure)
48 int t5() {
49 int i = 1;
50 return i;
51 }
52
53 // :: warning: (purity.more.pure)
54 int t6() {
55 int j = 0;
56 for (int i = 0; i < 10; i++) {
57 j = j - i;
58 }
59 return j;
60 }
61
62 // :: warning: (purity.more.pure)
63 String t7() {
64 if (true) {
65 return "a";
66 }
67 return "";
68 }
69
70 // :: warning: (purity.more.pure)
71 int t8() {
72 return 1 - 2 / 3 * 2 % 2;
73 }
74
75 // :: warning: (purity.more.pure)
76 String t9() {
77 return "b" + "a";
78 }
79
80 String t10() {
81 f1 = "";
82 f2 = "";
83 return "";
84 }
85
86 String t11(PuritySuggestionsClass l) {
87 l.a[0] = "";
88 return "";
89 }
90
91 String t12(String[] s) {
92 s[0] = "";
93 return "";
94 }
95
96 String t13() {
97 PureClass p = new PureClass();
98 return "";
99 }
100
101 // :: warning: (purity.more.pure)
102 String t14() {
103 String i = "";
104 i = "a";
105 return i;
106 }
107
108 // :: warning: (purity.more.pure)
109 String t15() {
110 String[] s = new String[1];
111 return s[0];
112 }
113
114 // :: warning: (purity.more.sideeffectfree)
115 String t16() {
116 try {
117 int i = 1 / 0;
118 } catch (Throwable t) {
119 // ...
120 }
121 return "";
122 }
123
124 // :: warning: (purity.more.sideeffectfree)
125 String t16b() {
126 try {
127 int i = 1 / 0;
128 } catch (Throwable t) {
129 // ...
130 }
131 return "";
132 }
133
134 // :: warning: (purity.more.sideeffectfree)
135 String t16c() {
136 try {
137 int i = 1 / 0;
138 } catch (Throwable t) {
139 // ...
140 }
141 return "";
142 }
143
144 // :: warning: (purity.more.pure)
145 String t17() {
146 return "";
147 }
148
149 @Deterministic
150 // :: warning: (purity.more.sideeffectfree)
151 String t18() {
152 return "";
153 }
154
155 // :: warning: (purity.more.deterministic)
156 String t19() {
157 return t18();
158 }
159
160 String t12() {
161 NonPureClass p = new NonPureClass();
162 return "";
163 }
164 }