-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathA.java
More file actions
199 lines (159 loc) · 4.7 KB
/
A.java
File metadata and controls
199 lines (159 loc) · 4.7 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package my.callback.qltest;
import java.util.*;
public class A {
public interface Consumer1 {
void eat(Object o);
}
public interface Consumer2 {
void eat(Object o);
}
public interface Consumer3<T> {
void eat(T o);
}
static void applyConsumer1(Object x, Consumer1 con) {
// summary:
// con.eat(x);
}
static void applyConsumer2(Object x, Consumer2 con) {
// summary:
// con.eat(x);
}
static <T> void applyConsumer3(T x, Consumer3<T> con) {
// summary:
// con.eat(x);
}
static <T> T applyConsumer3_ret_postup(Consumer3<T> con) {
// summary:
// x = new T();
// con.eat(x);
// return x;
return null;
}
static <T> void forEach(T[] xs, Consumer3<T> con) {
// summary:
// x = xs[..];
// con.eat(x);
}
public interface Producer1<T> {
T make();
}
static <T> T applyProducer1(Producer1<T> prod) {
// summary:
// return prod.make();
return null;
}
static <T> T produceConsume(Producer1<T> prod, Consumer3<T> con) {
// summary:
// x = prod.make();
// con.eat(x);
// return x;
return null;
}
public interface Converter1<T1,T2> {
T2 conv(T1 x);
}
static <T1,T2> T2 applyConverter1(T1 x, Converter1<T1,T2> con) {
// summary:
// return con.conv(x);
return null;
}
public interface Producer1Consumer3<E> extends Producer1<E[]>, Consumer3<E[]> { }
static Object source(int i) { return null; }
static void sink(Object o) { }
void foo(boolean b1, boolean b2) {
applyConsumer1(source(1), p -> {
sink(p); // $ flow=1
});
Object handler;
if (b1) {
handler = (Consumer1)(p -> { sink(p); }); // $ flow=2
} else {
handler = (Consumer2)(p -> { sink(p); }); // $ flow=3
}
if (b2) {
applyConsumer1(source(2), (Consumer1)handler);
} else {
applyConsumer2(source(3), (Consumer2)handler);
}
applyConsumer1(source(4), new Consumer1() {
@Override public void eat(Object o) {
sink(o); // $ flow=4
}
});
applyConsumer1(source(5), A::sink); // $ flow=5
Consumer2 c = new MyConsumer2();
applyConsumer2(source(6), c);
}
static class MyConsumer2 implements Consumer2 {
@Override public void eat(Object o) {
sink(o); // $ MISSING: flow=6
}
}
void foo2() {
Consumer3<Integer> c = i -> sink(i); // $ flow=7
applyConsumer3((Integer)source(7), c);
sink(applyProducer1(() -> (Integer)source(8))); // $ flow=8
sink(applyConverter1((Integer)source(9), i -> i)); // $ flow=9
sink(applyConverter1((Integer)source(10), i -> new int[]{i})[0]); // $ flow=10
Producer1Consumer3<Integer> pc = new Producer1Consumer3<Integer>() {
@Override public Integer[] make() {
return new Integer[] { (Integer)source(11) };
}
@Override public void eat(Integer[] xs) {
sink(xs[0]); // $ flow=12
}
};
applyConsumer3(new Integer[] { (Integer)source(12) }, pc);
sink(applyProducer1(pc)[0]); // $ flow=11
Integer res = applyProducer1(new Producer1<Integer>() {
private Integer ii = (Integer)source(13);
@Override public Integer make() {
return this.ii;
}
});
sink(res); // $ flow=13
ArrayList<Object> list = new ArrayList<>();
applyConsumer3(list, l -> l.add(source(14)));
sink(list.get(0)); // $ flow=14
Consumer3<ArrayList<Object>> tainter = l -> l.add(source(15));
sink(applyConsumer3_ret_postup(tainter).get(0)); // $ flow=15
forEach(new Object[] {source(16)}, x -> sink(x)); // $ flow=16
forEach(new Object[2][], xs -> { sink(xs[0]); xs[0] = source(17); });
Object[][] xss = new Object[][] { { null } };
forEach(xss, x -> {x[0] = source(18);});
sink(xss[0][0]); // $ flow=18
Object res2 = produceConsume(() -> source(19), A::sink); // $ flow=19
sink(res2); // $ flow=19
}
static void applyConsumer1Field1Field2(A a1, A a2, Consumer1 con) {
// summary:
// con.eat(a1.field1);
// con.eat(a2.field2);
}
static void wrapSinkToAvoidFieldSsa(A a) { sink(a.field1); } // $ flow=20
void foo3() {
A a1 = new A();
a1.field1 = source(20);
A a2 = new A();
applyConsumer1Field1Field2(a1, a2, p -> {
sink(p); // $ flow=20
});
wrapSinkToAvoidFieldSsa(a1);
sink(a2.field2);
}
public Object field1;
public Object field2;
void foo4() {
Producer1Consumer3<Integer> pc = new Producer1Consumer3<Integer>() {
int cfield = 0;
@Override public Integer[] make() {
return new Integer[] { cfield };
}
@Override public void eat(Integer[] xs) {
cfield = xs[0];
}
};
applyConsumer3(new Integer[] { (Integer)source(21) }, pc);
sink(applyProducer1(pc)[0]); // $ flow=21
}
}