Extract Function: Fix NPE caused by unmatched offset-to-reference maps

#KT-5001 Fixed
This commit is contained in:
Alexey Sedunov
2014-05-21 14:54:10 +04:00
parent f4c21d3a28
commit 240f033f4f
4 changed files with 34 additions and 1 deletions
@@ -739,7 +739,7 @@ fun ExtractionDescriptor.generateFunction(
body.getStatements().last?.let {
val newExpr = it.replaced(JetPsiFactory.createReturn(project, it.getText() ?: throw AssertionError("Return expression shouldn't be empty: code fragment = ${body.getText()}"))).getReturnedExpression()!!
val counterpartMap = createNameCounterpartMap(it, newExpr)
nameByOffset.entrySet().forEach { it.setValue(counterpartMap[it.getValue()]!!) }
nameByOffset.entrySet().forEach { e -> counterpartMap[e.getValue()]?.let { e.setValue(it) } }
}
}
}