@@ -29,10 +29,13 @@ string getZero(PrimitiveType t) {
29
29
t .hasName ( "long" ) and result = "0L"
30
30
}
31
31
32
- string getFiller ( Type t ) {
33
- t instanceof RefType and result = "null"
34
- or
35
- result = getZero ( t )
32
+ predicate mayBeAmbiguous ( Callable c ) {
33
+ exists ( Callable other , string package , string type , string name |
34
+ c .hasQualifiedName ( package , type , name ) and
35
+ other .hasQualifiedName ( package , type , name ) and
36
+ other .getNumberOfParameters ( ) = c .getNumberOfParameters ( ) and
37
+ other != c
38
+ )
36
39
}
37
40
38
41
Content getContent ( SummaryComponent component ) { component = SummaryComponent:: content ( result ) }
@@ -61,8 +64,16 @@ RefType getRootType(RefType t) {
61
64
else result = t
62
65
}
63
66
67
+ RefType replaceTypeVariable ( RefType t ) {
68
+ if t instanceof TypeVariable
69
+ then result = t .( TypeVariable ) .getFirstUpperBoundType ( )
70
+ else result = t
71
+ }
72
+
64
73
Type getRootSourceDeclaration ( Type t ) {
65
- if t instanceof RefType then result = getRootType ( t ) .getSourceDeclaration ( ) else result = t
74
+ if t instanceof RefType
75
+ then result = getRootType ( replaceTypeVariable ( t ) ) .getSourceDeclaration ( )
76
+ else result = t
66
77
}
67
78
68
79
newtype TRowTestSnippet =
@@ -94,6 +105,19 @@ class RowTestSnippet extends TRowTestSnippet {
94
105
baseOutput + " / " + preservesValue
95
106
}
96
107
108
+ string getFiller ( int argIdx ) {
109
+ exists ( Type t | t = callable .getParameterType ( argIdx ) |
110
+ t instanceof RefType and
111
+ (
112
+ if mayBeAmbiguous ( callable )
113
+ then result = "(" + getShortNameIfPossible ( t .( RefType ) .getSourceDeclaration ( ) ) + ")null"
114
+ else result = "null"
115
+ )
116
+ or
117
+ result = getZero ( t )
118
+ )
119
+ }
120
+
97
121
string getArgument ( int i ) {
98
122
( i = - 1 or exists ( callable .getParameter ( i ) ) ) and
99
123
if baseInput = SummaryComponentStack:: argument ( i )
@@ -102,7 +126,7 @@ class RowTestSnippet extends TRowTestSnippet {
102
126
if baseOutput = SummaryComponentStack:: argument ( i )
103
127
then result = "out"
104
128
else (
105
- if i = - 1 then result = "instance" else result = getFiller ( getParameterType ( callable , i ) )
129
+ if i = - 1 then result = "instance" else result = this . getFiller ( i )
106
130
)
107
131
)
108
132
}
@@ -238,6 +262,9 @@ class RowTestSnippet extends TRowTestSnippet {
238
262
getRootSourceDeclaration ( [
239
263
this .getOutputType ( ) , this .getInputType ( ) , callable .getDeclaringType ( )
240
264
] )
265
+ or
266
+ // Will refer to parameter types in disambiguating casts, like `(String)null`
267
+ mayBeAmbiguous ( callable ) and result = getRootSourceDeclaration ( callable .getAParamType ( ) )
241
268
}
242
269
243
270
string getATestSnippetForRow ( string row_ ) {
@@ -263,8 +290,16 @@ predicate isImportable(Type t) {
263
290
264
291
string getShortNameIfPossible ( Type t ) {
265
292
getRootSourceDeclaration ( t ) = any ( RowTestSnippet r ) .getADesiredImport ( ) and
266
- if t instanceof RefType and not isImportable ( getRootSourceDeclaration ( t ) )
267
- then result = t .( RefType ) .getPackage ( ) .getName ( ) + "." + t .getName ( )
293
+ if t instanceof RefType
294
+ then
295
+ exists ( RefType replaced , string nestedName |
296
+ replaced = replaceTypeVariable ( t ) and
297
+ nestedName = replaced .nestedName ( ) .replaceAll ( "$" , "." )
298
+ |
299
+ if isImportable ( getRootSourceDeclaration ( t ) )
300
+ then result = nestedName
301
+ else result = replaced .getPackage ( ) .getName ( ) + "." + nestedName
302
+ )
268
303
else result = t .getName ( )
269
304
}
270
305
0 commit comments