This commit is contained in:
Valentin Kipyatkov
2015-05-26 22:56:12 +03:00
parent 697516cfdd
commit b6eda35345
2 changed files with 4 additions and 2 deletions
@@ -67,10 +67,13 @@ public class DeprecatedCallableAddReplaceWithIntention : JetSelfTargetingRangeIn
.replace("\\", "\\\\") .replace("\\", "\\\\")
.replace("\"", "\\\"") .replace("\"", "\\\"")
//TODO: escape $!
val argumentText = StringBuilder { val argumentText = StringBuilder {
append("kotlin.ReplaceWith(\"") append("kotlin.ReplaceWith(\"")
append(escapedText) append(escapedText)
append("\"") append("\"")
//TODO: who should escape keywords here?
replaceWith.imports.forEach { append(",\"").append(it).append("\"") } replaceWith.imports.forEach { append(",\"").append(it).append("\"") }
append(")") append(")")
}.toString() }.toString()
@@ -164,7 +167,7 @@ public class DeprecatedCallableAddReplaceWithIntention : JetSelfTargetingRangeIn
if (!hasBlockBody()) return body if (!hasBlockBody()) return body
val block = body as? JetBlockExpression ?: return null val block = body as? JetBlockExpression ?: return null
val statement = block.getStatements().singleOrNull() as? JetExpression ?: return null val statement = block.getStatements().singleOrNull() as? JetExpression ?: return null
val returnsUnit = (analyze()[BindingContext.DECLARATION_TO_DESCRIPTOR, this] as? FunctionDescriptor)?.getReturnType()?.isUnit() ?: true val returnsUnit = (analyze()[BindingContext.DECLARATION_TO_DESCRIPTOR, this] as? FunctionDescriptor)?.getReturnType()?.isUnit() ?: return null
return when (statement) { return when (statement) {
is JetReturnExpression -> statement.getReturnedExpression() is JetReturnExpression -> statement.getReturnedExpression()
else -> if (returnsUnit) statement else null else -> if (returnsUnit) statement else null
@@ -3,7 +3,6 @@
fun foo(p: Int) { fun foo(p: Int) {
if (p > 0) { if (p > 0) {
val v = p + 1 val v = p + 1
bar(v)
} }
} }