Extract Function: Fix NPE caused by unmatched offset-to-reference maps
#KT-5001 Fixed
This commit is contained in:
+1
-1
@@ -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) } }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
fun Int.bar(n: Int): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
// SIBLING:
|
||||
fun main(args: Array<String>) {
|
||||
val t = if (args.size > 0) {
|
||||
<selection>val al = 0
|
||||
al.bar(1)</selection>
|
||||
}
|
||||
else false
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
fun Int.bar(n: Int): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
// SIBLING:
|
||||
fun main(args: Array<String>) {
|
||||
val t = if (args.size > 0) {
|
||||
b()
|
||||
}
|
||||
else false
|
||||
}
|
||||
|
||||
fun b(): Boolean {
|
||||
val al = 0
|
||||
return al.bar(1)
|
||||
}
|
||||
+5
@@ -724,6 +724,11 @@ public class JetExtractionTestGenerated extends AbstractJetExtractionTest {
|
||||
doExtractFunctionTest("idea/testData/refactoring/extractFunction/parameters/misc/innerClassObject.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt5001.kt")
|
||||
public void testKt5001() throws Exception {
|
||||
doExtractFunctionTest("idea/testData/refactoring/extractFunction/parameters/misc/kt5001.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("multiDeclaration.kt")
|
||||
public void testMultiDeclaration() throws Exception {
|
||||
doExtractFunctionTest("idea/testData/refactoring/extractFunction/parameters/misc/multiDeclaration.kt");
|
||||
|
||||
Reference in New Issue
Block a user