@@ -8,7 +8,13 @@ import org.jetbrains.kotlin.analysis.api.resolution.KaSuccessCallInfo
8
8
import org.jetbrains.kotlin.analysis.api.resolution.symbol
9
9
import org.jetbrains.kotlin.analysis.api.symbols.KaFunctionSymbol
10
10
import org.jetbrains.kotlin.analysis.api.types.KaType
11
+ import org.jetbrains.kotlin.analysis.api.types.KaTypeNullability
12
+ import org.jetbrains.kotlin.analysis.api.types.symbol
11
13
import org.jetbrains.kotlin.lexer.KtTokens
14
+ import org.jetbrains.kotlin.name.CallableId
15
+ import org.jetbrains.kotlin.name.ClassId
16
+ import org.jetbrains.kotlin.name.FqName
17
+ import org.jetbrains.kotlin.name.Name
12
18
import org.jetbrains.kotlin.parsing.parseNumericLiteral
13
19
import org.jetbrains.kotlin.psi.*
14
20
@@ -215,25 +221,57 @@ OLD: KE1
215
221
}
216
222
*/
217
223
218
- private fun isFunction (
224
+ private fun isFunctionMatchingNames (
225
+ symbol : KaFunctionSymbol ,
226
+ name : CallableId ,
227
+ isExtension : Boolean = false,
228
+ nullability : KaTypeNullability = KaTypeNullability .UNKNOWN ,
229
+ extensionReceiverClassName : ClassId ? = null
230
+ ): Boolean {
231
+
232
+ if (symbol.callableId != name)
233
+ return false
234
+
235
+ if (! isExtension)
236
+ return true
237
+
238
+ val receiverType = symbol.receiverParameter?.type
239
+ if (receiverType == null )
240
+ return false
241
+
242
+ if (receiverType.nullability != nullability)
243
+ return false
244
+
245
+ if (receiverType.symbol?.classId != extensionReceiverClassName)
246
+ return false
247
+
248
+ return true
249
+ }
250
+
251
+ private fun isFunctionMatchingName (
219
252
symbol : KaFunctionSymbol ,
220
253
packageName : String ,
221
- className : String ,
254
+ className : String? ,
222
255
functionName : String
223
256
): Boolean {
224
257
225
- return symbol.callableId?.packageName?.asString() == packageName &&
226
- symbol.callableId?.className?.asString() == className &&
227
- symbol.callableId?.callableName?.asString() == functionName
258
+ return isFunctionMatchingNames(
259
+ symbol,
260
+ CallableId (
261
+ FqName (packageName),
262
+ if (className == null ) null else FqName (className),
263
+ Name .identifier(functionName)
264
+ )
265
+ )
228
266
}
229
267
230
- private fun isNumericFunction (target : KaFunctionSymbol , fName : String ): Boolean {
231
- return isFunction (target, " kotlin" , " Int" , fName ) ||
232
- isFunction (target, " kotlin" , " Byte" , fName ) ||
233
- isFunction (target, " kotlin" , " Short" , fName ) ||
234
- isFunction (target, " kotlin" , " Long" , fName ) ||
235
- isFunction (target, " kotlin" , " Float" , fName ) ||
236
- isFunction (target, " kotlin" , " Double" , fName )
268
+ private fun isNumericFunction (target : KaFunctionSymbol , functionName : String ): Boolean {
269
+ return isFunctionMatchingName (target, " kotlin" , " Int" , functionName ) ||
270
+ isFunctionMatchingName (target, " kotlin" , " Byte" , functionName ) ||
271
+ isFunctionMatchingName (target, " kotlin" , " Short" , functionName ) ||
272
+ isFunctionMatchingName (target, " kotlin" , " Long" , functionName ) ||
273
+ isFunctionMatchingName (target, " kotlin" , " Float" , functionName ) ||
274
+ isFunctionMatchingName (target, " kotlin" , " Double" , functionName )
237
275
}
238
276
239
277
/* *
@@ -267,7 +305,16 @@ private fun KotlinFileExtractor.extractBinaryExpression(
267
305
TODO ()
268
306
}
269
307
270
- if (isNumericFunction(target, " plus" )) {
308
+ if (isNumericFunction(target, " plus" ) ||
309
+ isFunctionMatchingName(target, " kotlin" , " String" , " plus" ) ||
310
+ isFunctionMatchingNames(
311
+ target,
312
+ CallableId (FqName (" kotlin" ), null , Name .identifier(" plus" )),
313
+ isExtension = true ,
314
+ nullability = KaTypeNullability .NULLABLE ,
315
+ ClassId (FqName (" kotlin" ), Name .identifier(" String" ))
316
+ )
317
+ ) {
271
318
val id = tw.getFreshIdLabel<DbAddexpr >()
272
319
val type = useType(expression.expressionType)
273
320
val exprParent = parent.expr(expression, callable)
@@ -278,7 +325,7 @@ private fun KotlinFileExtractor.extractBinaryExpression(
278
325
extractExpressionExpr(expression.left!! , callable, id, 0 , exprParent.enclosingStmt)
279
326
extractExpressionExpr(expression.right!! , callable, id, 1 , exprParent.enclosingStmt)
280
327
} else {
281
- TODO ()
328
+ TODO (" Extract as method call " )
282
329
}
283
330
}
284
331
0 commit comments