New J2K: Support this qualifier in default arguments converter
This commit is contained in:
committed by
Ilya Kirillov
parent
b868214992
commit
38760a8b7c
@@ -20,12 +20,9 @@ class DefaultArgumentsConversion(private val context: ConversionContext) : Recur
|
|||||||
|
|
||||||
checkMethod@ for (method in methods) {
|
checkMethod@ for (method in methods) {
|
||||||
val block = method.block as? JKBlock ?: continue
|
val block = method.block as? JKBlock ?: continue
|
||||||
val singleStatement = block.statements.singleOrNull()
|
val singleStatement = block.statements.singleOrNull() ?: continue
|
||||||
|
|
||||||
val call =
|
val call = lookupCall(singleStatement) ?: continue
|
||||||
singleStatement.safeAs<JKExpressionStatement>()?.expression?.safeAs<JKMethodCallExpression>()
|
|
||||||
?: singleStatement.safeAs<JKReturnStatement>()?.expression?.safeAs()
|
|
||||||
?: continue
|
|
||||||
val callee = call.identifier as? JKUniverseMethodSymbol ?: continue
|
val callee = call.identifier as? JKUniverseMethodSymbol ?: continue
|
||||||
val calledMethod = callee.target
|
val calledMethod = callee.target
|
||||||
if (calledMethod.parent != method.parent
|
if (calledMethod.parent != method.parent
|
||||||
@@ -79,4 +76,20 @@ class DefaultArgumentsConversion(private val context: ConversionContext) : Recur
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private fun lookupCall(statement: JKStatement): JKMethodCallExpression? {
|
||||||
|
val expression = when (statement) {
|
||||||
|
is JKExpressionStatement -> statement.expression
|
||||||
|
is JKReturnStatement -> statement.expression
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
return when (expression) {
|
||||||
|
is JKMethodCallExpression -> expression
|
||||||
|
is JKQualifiedExpression -> {
|
||||||
|
if (expression.receiver !is JKThisExpression) return null
|
||||||
|
expression.selector.safeAs()
|
||||||
|
}
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user