@@ -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
@@ -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
}
@@ -327,8 +368,8 @@ private class OptionalGenMethod extends GenMethod {
327
368
OptionalGenMethod ( ) { this = "optionalgenmethod" }
328
369
329
370
override predicate appliesTo ( Type t , Content c ) {
330
- exists ( GenericType list | list .hasQualifiedName ( "java.util" , "List " ) |
331
- list .getAParameterizedType ( ) .getASupertype * ( ) = t
371
+ exists ( GenericType op | op .hasQualifiedName ( "java.util" , "Optional " ) |
372
+ op .getAParameterizedType ( ) .getASupertype * ( ) = t
332
373
) and
333
374
c instanceof CollectionContent
334
375
}
@@ -351,6 +392,25 @@ private class MapGenKeyMethod extends GenMethod {
351
392
override string getCall ( string arg ) { result = "Map.of(" + arg + ", null)" }
352
393
}
353
394
395
+ private class MapEntryGenKeyMethod extends GenMethod {
396
+ MapEntryGenKeyMethod ( ) { this = "mapentrygenkeymethod" }
397
+
398
+ override predicate appliesTo ( Type t , Content c ) {
399
+ exists ( GenericType map | map .hasQualifiedName ( "java.util" , "Map$Entry" ) |
400
+ map .getAParameterizedType ( ) .getASupertype * ( ) = t
401
+ ) and
402
+ c instanceof MapKeyContent
403
+ }
404
+
405
+ override string getDefinition ( ) {
406
+ result =
407
+ "<K> Map.Entry<K,?> newEntryWithMapKey(K key) { return Map.of(key, null).entrySet().iterator().next(); }"
408
+ }
409
+
410
+ bindingset [ arg]
411
+ override string getCall ( string arg ) { result = "newEntryWithMapKey(" + arg + ")" }
412
+ }
413
+
354
414
private class MapGenValueMethod extends GenMethod {
355
415
MapGenValueMethod ( ) { this = "mapvaluegenmethod" }
356
416
@@ -365,6 +425,25 @@ private class MapGenValueMethod extends GenMethod {
365
425
override string getCall ( string arg ) { result = "Map.of(null, " + arg + ")" }
366
426
}
367
427
428
+ private class MapEntryGenValueMethod extends GenMethod {
429
+ MapEntryGenValueMethod ( ) { this = "mapentrygenvaluemethod" }
430
+
431
+ override predicate appliesTo ( Type t , Content c ) {
432
+ exists ( GenericType map | map .hasQualifiedName ( "java.util" , "Map$Entry" ) |
433
+ map .getAParameterizedType ( ) .getASupertype * ( ) = t
434
+ ) and
435
+ c instanceof MapValueContent
436
+ }
437
+
438
+ override string getDefinition ( ) {
439
+ result =
440
+ "<V> Map.Entry<?,V> newEntryWithMapValue(V value) { return Map.of(null, value).entrySet().iterator().next(); }"
441
+ }
442
+
443
+ bindingset [ arg]
444
+ override string getCall ( string arg ) { result = "newEntryWithMapValue(" + arg + ")" }
445
+ }
446
+
368
447
/**
369
448
* Returns a cast to type `t` if `t` is not `java.lang.Object`, or an empty string otherwise.
370
449
*/
0 commit comments