@@ -145,7 +145,7 @@ private class DefaultGetMethod extends GetMethod {
145
145
146
146
DefaultGetMethod ( ) { this = "DefaultGet" + contentToken ( c ) }
147
147
148
- string getName ( ) { result = "get" + contentToken ( c ) }
148
+ string getName ( ) { result = "get" + contentToken ( c ) + "Default" }
149
149
150
150
override int getPriority ( ) { result = 999 }
151
151
@@ -159,12 +159,12 @@ private class DefaultGetMethod extends GetMethod {
159
159
override string getCall ( string arg ) { result = this .getName ( ) + "(" + arg + ")" }
160
160
161
161
override string getDefinition ( ) {
162
- result = "Object get" + contentToken ( c ) + "(Object container) { return null; }"
162
+ result = "Object get" + contentToken ( c ) + "Default (Object container) { return null; }"
163
163
}
164
164
165
165
override string getCsvModel ( ) {
166
166
result =
167
- "generatedtest;Test;false;" + this .getName ( ) + ";;;" +
167
+ "generatedtest;Test;false;" + this .getName ( ) + ";(Object) ;;" +
168
168
getComponentSpec ( SummaryComponent:: content ( c ) ) + " of Argument[0];ReturnValue;value"
169
169
}
170
170
}
@@ -201,6 +201,22 @@ private class IteratorGetMethod extends GetMethod {
201
201
override string getCall ( string arg ) { result = "getElement(" + arg + ")" }
202
202
}
203
203
204
+ private class EnumerationGetMethod extends GetMethod {
205
+ EnumerationGetMethod ( ) { this = "enumerationgetmethod" }
206
+
207
+ override predicate appliesTo ( Type t , Content c ) {
208
+ t .( RefType ) .getASourceSupertype * ( ) .hasQualifiedName ( "java.util" , "Enumeration" ) and
209
+ c instanceof CollectionContent
210
+ }
211
+
212
+ override string getDefinition ( ) {
213
+ result = "<T> T getElement(Enumeration<T> it) { return it.nextElement(); }"
214
+ }
215
+
216
+ bindingset [ arg]
217
+ override string getCall ( string arg ) { result = "getElement(" + arg + ")" }
218
+ }
219
+
204
220
private class OptionalGetMethod extends GetMethod {
205
221
OptionalGetMethod ( ) { this = "optionalgetmethod" }
206
222
@@ -215,8 +231,8 @@ private class OptionalGetMethod extends GetMethod {
215
231
override string getCall ( string arg ) { result = "getElement(" + arg + ")" }
216
232
}
217
233
218
- private class MapGetKeyMethod extends GetMethod {
219
- MapGetKeyMethod ( ) { this = "mapgetkeymethod" }
234
+ private class MapGetKeytMethod extends GetMethod {
235
+ MapGetKeytMethod ( ) { this = "mapgetkeymethod" }
220
236
221
237
override predicate appliesTo ( Type t , Content c ) {
222
238
t .( RefType ) .getASourceSupertype * ( ) .hasQualifiedName ( "java.util" , "Map" ) and
@@ -231,8 +247,20 @@ private class MapGetKeyMethod extends GetMethod {
231
247
override string getCall ( string arg ) { result = "getMapKey(" + arg + ")" }
232
248
}
233
249
234
- private class MapValueGetMethod extends GetMethod {
235
- MapValueGetMethod ( ) { this = "MapValueGetMethod" }
250
+ private class MapEntryGetKeyMethod extends GetMethod {
251
+ MapEntryGetKeyMethod ( ) { this = "mapentrygetkeymethod" }
252
+
253
+ override predicate appliesTo ( Type t , Content c ) {
254
+ t .( RefType ) .getASourceSupertype * ( ) .hasQualifiedName ( "java.util" , "Map$Entry" ) and
255
+ c instanceof MapKeyContent
256
+ }
257
+
258
+ bindingset [ arg]
259
+ override string getCall ( string arg ) { result = arg + ".getKey()" }
260
+ }
261
+
262
+ private class MapGetValueMethod extends GetMethod {
263
+ MapGetValueMethod ( ) { this = "MapGetValueMethod" }
236
264
237
265
override predicate appliesTo ( Type t , Content c ) {
238
266
t .( RefType ) .getASourceSupertype * ( ) .hasQualifiedName ( "java.util" , "Map" ) and
@@ -247,6 +275,18 @@ private class MapValueGetMethod extends GetMethod {
247
275
override string getCall ( string arg ) { result = "getMapValue(" + arg + ")" }
248
276
}
249
277
278
+ private class MapEntryGetValueMethod extends GetMethod {
279
+ MapEntryGetValueMethod ( ) { this = "mapentrygetvaluemethod" }
280
+
281
+ override predicate appliesTo ( Type t , Content c ) {
282
+ t .( RefType ) .getASourceSupertype * ( ) .hasQualifiedName ( "java.util" , "Map$Entry" ) and
283
+ c instanceof MapValueContent
284
+ }
285
+
286
+ bindingset [ arg]
287
+ override string getCall ( string arg ) { result = arg + ".getValue()" }
288
+ }
289
+
250
290
private class ArrayGetMethod extends GetMethod {
251
291
ArrayGetMethod ( ) { this = "arraygetmethod" }
252
292
@@ -285,7 +325,7 @@ private class DefaultGenMethod extends GenMethod {
285
325
286
326
DefaultGenMethod ( ) { this = "DefaultGen" + contentToken ( c ) }
287
327
288
- string getName ( ) { result = "newWith" + contentToken ( c ) }
328
+ string getName ( ) { result = "newWith" + contentToken ( c ) + "Default" }
289
329
290
330
override int getPriority ( ) { result = 999 }
291
331
@@ -299,12 +339,12 @@ private class DefaultGenMethod extends GenMethod {
299
339
override string getCall ( string arg ) { result = this .getName ( ) + "(" + arg + ")" }
300
340
301
341
override string getDefinition ( ) {
302
- result = "Object newWith" + contentToken ( c ) + "(Object element) { return null; }"
342
+ result = "Object newWith" + contentToken ( c ) + "Default (Object element) { return null; }"
303
343
}
304
344
305
345
override string getCsvModel ( ) {
306
346
result =
307
- "generatedtest;Test;false;" + this .getName ( ) + ";;;Argument[0];" +
347
+ "generatedtest;Test;false;" + this .getName ( ) + ";(Object) ;;Argument[0];" +
308
348
getComponentSpec ( SummaryComponent:: content ( c ) ) + " of ReturnValue;value"
309
349
}
310
350
}
@@ -314,7 +354,8 @@ private class ListGenMethod extends GenMethod {
314
354
315
355
override predicate appliesTo ( Type t , Content c ) {
316
356
exists ( GenericType list | list .hasQualifiedName ( "java.util" , "List" ) |
317
- t = list or list .getAParameterizedType ( ) .getASupertype * ( ) = t
357
+ t .getErasure ( ) = list .getASourceSupertype * ( ) .getErasure ( ) or // cover things like Iterable and Collection
358
+ list .getAParameterizedType ( ) .getASupertype * ( ) = t
318
359
) and
319
360
c instanceof CollectionContent
320
361
}
@@ -323,12 +364,40 @@ private class ListGenMethod extends GenMethod {
323
364
override string getCall ( string arg ) { result = "List.of(" + arg + ")" }
324
365
}
325
366
367
+ private class SetGenMethod extends GenMethod {
368
+ SetGenMethod ( ) { this = "SetGenMethod" }
369
+
370
+ override predicate appliesTo ( Type t , Content c ) {
371
+ exists ( GenericType set | set .hasQualifiedName ( "java.util" , "Set" ) |
372
+ t .getErasure ( ) = set .getErasure ( )
373
+ ) and
374
+ c instanceof CollectionContent
375
+ }
376
+
377
+ bindingset [ arg]
378
+ override string getCall ( string arg ) { result = "Set.of(" + arg + ")" }
379
+ }
380
+
381
+ private class IteratorGenMethod extends GenMethod {
382
+ IteratorGenMethod ( ) { this = "IteratorGenMethod" }
383
+
384
+ override predicate appliesTo ( Type t , Content c ) {
385
+ exists ( GenericType set | set .hasQualifiedName ( "java.util" , "Iterator" ) |
386
+ t .getErasure ( ) = set .getErasure ( )
387
+ ) and
388
+ c instanceof CollectionContent
389
+ }
390
+
391
+ bindingset [ arg]
392
+ override string getCall ( string arg ) { result = "List.of(" + arg + ").iterator()" }
393
+ }
394
+
326
395
private class OptionalGenMethod extends GenMethod {
327
396
OptionalGenMethod ( ) { this = "optionalgenmethod" }
328
397
329
398
override predicate appliesTo ( Type t , Content c ) {
330
- exists ( GenericType list | list .hasQualifiedName ( "java.util" , "List " ) |
331
- list .getAParameterizedType ( ) .getASupertype * ( ) = t
399
+ exists ( GenericType op | op .hasQualifiedName ( "java.util" , "Optional " ) |
400
+ op .getAParameterizedType ( ) .getASupertype * ( ) = t
332
401
) and
333
402
c instanceof CollectionContent
334
403
}
@@ -351,6 +420,25 @@ private class MapGenKeyMethod extends GenMethod {
351
420
override string getCall ( string arg ) { result = "Map.of(" + arg + ", null)" }
352
421
}
353
422
423
+ private class MapEntryGenKeyMethod extends GenMethod {
424
+ MapEntryGenKeyMethod ( ) { this = "mapentrygenkeymethod" }
425
+
426
+ override predicate appliesTo ( Type t , Content c ) {
427
+ exists ( GenericType map | map .hasQualifiedName ( "java.util" , "Map$Entry" ) |
428
+ map .getAParameterizedType ( ) .getASupertype * ( ) = t
429
+ ) and
430
+ c instanceof MapKeyContent
431
+ }
432
+
433
+ override string getDefinition ( ) {
434
+ result =
435
+ "<K> Map.Entry<K,?> newEntryWithMapKey(K key) { return Map.of(key, null).entrySet().iterator().next(); }"
436
+ }
437
+
438
+ bindingset [ arg]
439
+ override string getCall ( string arg ) { result = "newEntryWithMapKey(" + arg + ")" }
440
+ }
441
+
354
442
private class MapGenValueMethod extends GenMethod {
355
443
MapGenValueMethod ( ) { this = "mapvaluegenmethod" }
356
444
@@ -365,6 +453,25 @@ private class MapGenValueMethod extends GenMethod {
365
453
override string getCall ( string arg ) { result = "Map.of(null, " + arg + ")" }
366
454
}
367
455
456
+ private class MapEntryGenValueMethod extends GenMethod {
457
+ MapEntryGenValueMethod ( ) { this = "mapentrygenvaluemethod" }
458
+
459
+ override predicate appliesTo ( Type t , Content c ) {
460
+ exists ( GenericType map | map .hasQualifiedName ( "java.util" , "Map$Entry" ) |
461
+ map .getAParameterizedType ( ) .getASupertype * ( ) = t
462
+ ) and
463
+ c instanceof MapValueContent
464
+ }
465
+
466
+ override string getDefinition ( ) {
467
+ result =
468
+ "<V> Map.Entry<?,V> newEntryWithMapValue(V value) { return Map.of(null, value).entrySet().iterator().next(); }"
469
+ }
470
+
471
+ bindingset [ arg]
472
+ override string getCall ( string arg ) { result = "newEntryWithMapValue(" + arg + ")" }
473
+ }
474
+
368
475
/**
369
476
* Returns a cast to type `t` if `t` is not `java.lang.Object`, or an empty string otherwise.
370
477
*/
0 commit comments