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