122
122
import java .util .Map ;
123
123
import java .util .Set ;
124
124
import java .util .Stack ;
125
- import java .util .stream .Collectors ;
126
- import java .util .stream .Stream ;
127
125
128
126
/**
129
127
* Extractor for intra-procedural expression-level control flow graphs.
@@ -187,21 +185,55 @@ public CFGExtractor(ASTExtractor astExtractor) {
187
185
}
188
186
189
187
private static Collection <Node > union (Node x , Node y ) {
190
- return union (Collections .singleton (x ), Collections .singleton (y ));
188
+ if (x == y ) {
189
+ if (x == null ) {
190
+ return Collections .emptySet ();
191
+ } else {
192
+ return Collections .singleton (x );
193
+ }
194
+ }
195
+
196
+ if (x == null ) {
197
+ return Collections .singleton (y );
198
+ }
199
+ if (y == null ) {
200
+ return Collections .singleton (x );
201
+ }
202
+
203
+ return Arrays .asList (x , y );
191
204
}
192
205
193
206
private static Collection <Node > union (Collection <Node > xs , Node y ) {
194
- return union (xs , Collections .singleton (y ));
207
+ if (y == null ) {
208
+ return xs ;
209
+ }
210
+ if (xs == null || xs .isEmpty ()) {
211
+ return Collections .singleton (y );
212
+ }
213
+ if (xs .contains (y )) {
214
+ return xs ;
215
+ }
216
+
217
+ return nonNullUnion (xs , Collections .singleton (y ));
195
218
}
196
219
197
220
private static Collection <Node > union (Node x , Collection <Node > ys ) {
198
- return union (Collections .singleton (x ), ys );
221
+ if (x == null ) {
222
+ return ys ;
223
+ }
224
+ if (ys == null || ys .isEmpty ()) {
225
+ return Collections .singleton (x );
226
+ }
227
+ if (ys .contains (x )) {
228
+ return ys ;
229
+ }
230
+
231
+ return nonNullUnion (Collections .singleton (x ), ys );
199
232
}
200
233
201
234
/**
202
235
* Creates an order preserving concatenation of the nodes in `xs` and `ys` without duplicates.
203
236
*/
204
- @ SuppressWarnings ("unchecked" )
205
237
private static Collection <Node > union (Collection <Node > xs , Collection <Node > ys ) {
206
238
if (xs == null || xs .size () == 0 ) {
207
239
return ys ;
@@ -210,8 +242,21 @@ private static Collection<Node> union(Collection<Node> xs, Collection<Node> ys)
210
242
return xs ;
211
243
}
212
244
213
- Set <Node > set = new HashSet <>();
214
- return Stream .concat (xs .stream (), ys .stream ()).filter (set ::add ).collect (Collectors .toList ());
245
+ return nonNullUnion (xs , ys );
246
+ }
247
+
248
+ /**
249
+ * Creates an order preserving concatenation of the nodes in `xs` and `ys` without duplicates.
250
+ * Where `xs` and `ys` have non null values, and are non-empty.
251
+ */
252
+ private static Collection <Node > nonNullUnion (Collection <Node > xs , Collection <Node > ys ) {
253
+ List <Node > result = new ArrayList <>(xs );
254
+ for (Node y : ys ) {
255
+ if (!result .contains (y )) {
256
+ result .add (y );
257
+ }
258
+ }
259
+ return result ;
215
260
}
216
261
217
262
/**
@@ -1167,12 +1212,12 @@ private List<Node> getDecoratorsOfClass(AClass ac) {
1167
1212
instanceDecorators .addAll (decorators );
1168
1213
}
1169
1214
}
1170
- return Arrays . asList (
1171
- instanceDecorators ,
1172
- staticDecorators ,
1173
- constructorParameterDecorators ,
1174
- classDecorators
1175
- ). stream (). flatMap ( list -> list . stream ()). collect ( Collectors . toList ()) ;
1215
+ List < Node > result = new ArrayList <>();
1216
+ result . addAll ( instanceDecorators );
1217
+ result . addAll ( staticDecorators );
1218
+ result . addAll ( constructorParameterDecorators );
1219
+ result . addAll ( classDecorators );
1220
+ return result ;
1176
1221
}
1177
1222
1178
1223
@ Override
0 commit comments