Rename: Fix exception on attempt to rename KtConstructorDelegationReference
#KT-21536 Fixed
This commit is contained in:
+9
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+13
@@ -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());
|
||||
}
|
||||
}
|
||||
Vendored
+20
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+13
@@ -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());
|
||||
}
|
||||
}
|
||||
Vendored
+20
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user