@@ -290,37 +290,60 @@ private fun KotlinFileExtractor.extractBinaryExpression(
290
290
val op = expression.operationToken
291
291
val target = ((expression.resolveToCall() as ? KaSuccessCallInfo )?.call as ? KaSimpleFunctionCall )?.symbol
292
292
293
- when (op) {
294
- KtTokens .PLUS -> {
295
- if (target == null ) {
296
- TODO ()
297
- }
298
-
299
- if (target.isNumericWithName(" plus" ) ||
300
- target.hasName(" kotlin" , " String" , " plus" ) ||
301
- target.hasMatchingNames(
302
- CallableId (FqName (" kotlin" ), null , Name .identifier(" plus" )),
303
- ClassId (FqName (" kotlin" ), Name .identifier(" String" )),
304
- nullability = KaTypeNullability .NULLABLE ,
305
- )
306
- ) {
307
- val id = tw.getFreshIdLabel<DbAddexpr >()
308
- val type = useType(expression.expressionType)
309
- val exprParent = parent.expr(expression, callable)
310
- tw.writeExprs_addexpr(id, type.javaResult.id, exprParent.parent, exprParent.idx)
311
- tw.writeExprsKotlinType(id, type.kotlinResult.id)
293
+ if (target == null ) {
294
+ TODO ()
295
+ }
312
296
313
- extractExprContext(id, tw.getLocation(expression), callable, exprParent.enclosingStmt)
314
- extractExpressionExpr(expression.left!! , callable, id, 0 , exprParent.enclosingStmt)
315
- extractExpressionExpr(expression.right!! , callable, id, 1 , exprParent.enclosingStmt)
316
- } else {
317
- TODO (" Extract as method call" )
318
- }
297
+ if (op == KtTokens .PLUS && target.isBinaryPlus()) {
298
+ extractBinaryExpression(expression, callable, parent, tw::writeExprs_addexpr)
299
+ } else if (op == KtTokens .MINUS && target.isNumericWithName(" minus" )) {
300
+ extractBinaryExpression(expression, callable, parent, tw::writeExprs_subexpr)
301
+ } else if (op == KtTokens .MUL && target.isNumericWithName(" times" )) {
302
+ extractBinaryExpression(expression, callable, parent, tw::writeExprs_mulexpr)
303
+ } else if (op == KtTokens .DIV && target.isNumericWithName(" div" )) {
304
+ extractBinaryExpression(expression, callable, parent, tw::writeExprs_divexpr)
305
+ } else if (op == KtTokens .PERC && target.isNumericWithName(" rem" )) {
306
+ extractBinaryExpression(expression, callable, parent, tw::writeExprs_remexpr)
307
+ } else {
308
+ if (op !in listOf (KtTokens .PLUS , KtTokens .MINUS , KtTokens .MUL , KtTokens .DIV , KtTokens .PERC )) {
309
+ TODO (" Unhandled binary op" )
319
310
}
320
311
321
- else -> TODO ()
312
+ TODO (" Extract as method call " )
322
313
}
314
+ }
323
315
316
+ private fun KaFunctionSymbol.isBinaryPlus (): Boolean {
317
+ return this .isNumericWithName(" plus" ) ||
318
+ this .hasName(" kotlin" , " String" , " plus" ) ||
319
+ this .hasMatchingNames(
320
+ CallableId (FqName (" kotlin" ), null , Name .identifier(" plus" )),
321
+ ClassId (FqName (" kotlin" ), Name .identifier(" String" )),
322
+ nullability = KaTypeNullability .NULLABLE ,
323
+ )
324
+ }
325
+
326
+ context(KaSession )
327
+ private fun <T : DbBinaryexpr > KotlinFileExtractor.extractBinaryExpression (
328
+ expression : KtBinaryExpression ,
329
+ callable : Label <out DbCallable >,
330
+ parent : StmtExprParent ,
331
+ extractExpression : (
332
+ id: Label <out T >,
333
+ typeid: Label <out DbType >,
334
+ parent: Label <out DbExprparent >,
335
+ idx: Int
336
+ ) -> Unit
337
+ ) {
338
+ val id = tw.getFreshIdLabel<T >()
339
+ val type = useType(expression.expressionType)
340
+ val exprParent = parent.expr(expression, callable)
341
+ extractExpression(id, type.javaResult.id, exprParent.parent, exprParent.idx)
342
+ tw.writeExprsKotlinType(id, type.kotlinResult.id)
343
+
344
+ extractExprContext(id, tw.getLocation(expression), callable, exprParent.enclosingStmt)
345
+ extractExpressionExpr(expression.left!! , callable, id, 0 , exprParent.enclosingStmt)
346
+ extractExpressionExpr(expression.right!! , callable, id, 1 , exprParent.enclosingStmt)
324
347
}
325
348
326
349
context(KaSession )
0 commit comments