Rename: Fix exception on attempt to rename KtConstructorDelegationReference

#KT-21536 Fixed
This commit is contained in:
Alexey Sedunov
2017-12-04 16:14:29 +03:00
parent ec85b708c9
commit e1ed74008f
7 changed files with 86 additions and 0 deletions
@@ -17,7 +17,9 @@
package org.jetbrains.kotlin.idea.references;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.psi.KtConstructorDelegationReferenceExpression;
@@ -39,4 +41,11 @@ public class KtConstructorDelegationReference extends KtSimpleReference<KtConstr
public Collection<Name> getResolvesByNames() {
return Collections.emptyList();
}
@Nullable
@Override
public PsiElement handleElementRename(@Nullable String newElementName) {
// Class rename never affects this reference, so there is no need to fail with exception
return getExpression();
}
}
@@ -0,0 +1,13 @@
import java.util.function.Supplier;
public class Banana2 {
final Supplier<String> f;
Banana2(Supplier<String> f) {this.f = f;}
Banana2() {this(() -> "Default");}
void goCrazy() {
System.out.println(f.get());
}
}
@@ -0,0 +1,20 @@
class DoesntWork : Banana2 {
constructor() : super()
constructor(f: () -> String) : super(f)
companion object {
@JvmStatic fun main(args: Array<String>) {
val inst = DoesntWork {"Hi there"}
inst.goCrazy()
}
}
}
class ThisWorks(f: () -> String) : Banana2(f) {
companion object {
@JvmStatic fun main(args: Array<String>) {
val inst = ThisWorks {"Hi there"}
inst.goCrazy()
}
}
}
@@ -0,0 +1,13 @@
import java.util.function.Supplier;
public class Banana {
final Supplier<String> f;
Banana(Supplier<String> f) {this.f = f;}
Banana() {this(() -> "Default");}
void goCrazy() {
System.out.println(f.get());
}
}
@@ -0,0 +1,20 @@
class DoesntWork : Banana {
constructor() : super()
constructor(f: () -> String) : super(f)
companion object {
@JvmStatic fun main(args: Array<String>) {
val inst = DoesntWork {"Hi there"}
inst.goCrazy()
}
}
}
class ThisWorks(f: () -> String) : Banana(f) {
companion object {
@JvmStatic fun main(args: Array<String>) {
val inst = ThisWorks {"Hi there"}
inst.goCrazy()
}
}
}
@@ -0,0 +1,5 @@
{
"type": "JAVA_CLASS",
"classId": "Banana",
"newName": "Banana2"
}
@@ -684,6 +684,12 @@ public class RenameTestGenerated extends AbstractRenameTest {
doTest(fileName);
}
@TestMetadata("renameJavaClassWithKtConstructorDelegation/renameJavaClassWithKtConstructorDelegation.test")
public void testRenameJavaClassWithKtConstructorDelegation_RenameJavaClassWithKtConstructorDelegation() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameJavaClassWithKtConstructorDelegation/renameJavaClassWithKtConstructorDelegation.test");
doTest(fileName);
}
@TestMetadata("renameJavaInterface/renameJavaInterface.test")
public void testRenameJavaInterface_RenameJavaInterface() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameJavaInterface/renameJavaInterface.test");