Supported renaming of default object. Named only objects are supported
yet.
This commit is contained in:
@@ -174,4 +174,12 @@ public abstract class KotlinLightField<T extends JetDeclaration, D extends PsiFi
|
||||
public Language getLanguage() {
|
||||
return JetLanguage.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEquivalentTo(PsiElement another) {
|
||||
if (another instanceof KotlinLightField && origin.isEquivalentTo(((KotlinLightField) another).getOrigin())) {
|
||||
return true;
|
||||
}
|
||||
return super.isEquivalentTo(another);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,6 +149,20 @@ public class LightClassUtil {
|
||||
return getPsiMethodWrapper(accessor);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiField getLightFieldForDefaultObject(@NotNull JetClassOrObject defaultObject) {
|
||||
PsiClass outerPsiClass = getWrappingClass(defaultObject);
|
||||
if (outerPsiClass != null) {
|
||||
for (PsiField fieldOfParent : outerPsiClass.getFields()) {
|
||||
if (((KotlinLightElement<?, ?>) fieldOfParent).getOrigin() == defaultObject &&
|
||||
fieldOfParent.getName().equals(defaultObject.getName())) { // TODO this check is relevant while light class has deprecated OBJECT$ field
|
||||
return fieldOfParent;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PropertyAccessorsPsiMethods getLightClassPropertyMethods(@NotNull JetProperty property) {
|
||||
JetPropertyAccessor getter = property.getGetter();
|
||||
|
||||
+13
-3
@@ -25,9 +25,7 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.Processor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.asJava.AsJavaPackage;
|
||||
import org.jetbrains.kotlin.asJava.KotlinLightMethod;
|
||||
import org.jetbrains.kotlin.asJava.LightClassUtil;
|
||||
import org.jetbrains.kotlin.asJava.*;
|
||||
import org.jetbrains.kotlin.idea.search.usagesSearch.*;
|
||||
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
@@ -46,6 +44,18 @@ public class KotlinReferencesSearcher extends QueryExecutorBase<PsiReference, Re
|
||||
});
|
||||
if (lightClass != null) {
|
||||
searchNamedElement(queryParameters, lightClass, className);
|
||||
|
||||
if (element instanceof JetObjectDeclaration && ((JetObjectDeclaration) element).isDefault()) {
|
||||
PsiField fieldForDefaultObject = ApplicationManager.getApplication().runReadAction(new Computable<PsiField>() {
|
||||
@Override
|
||||
public PsiField compute() {
|
||||
return LightClassUtil.getLightFieldForDefaultObject(element);
|
||||
}
|
||||
});
|
||||
if (fieldForDefaultObject != null) {
|
||||
searchNamedElement(queryParameters, fieldForDefaultObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
class JavaUsage {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(Foo.CONST);
|
||||
Foo.s();
|
||||
Foo.Baz.f();
|
||||
Foo foo = new Foo(); // not usage of default object
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class Foo {
|
||||
default object Baz {
|
||||
fun f() {
|
||||
}
|
||||
|
||||
platformStatic fun s() {
|
||||
}
|
||||
|
||||
val CONST = 42
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun main(args: Array<String>) {
|
||||
// class object usages
|
||||
Foo.f()
|
||||
val x = Foo
|
||||
|
||||
Foo.Baz.f()
|
||||
val xx = Foo.Baz
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
class JavaUsage {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(Foo.CONST);
|
||||
Foo.s();
|
||||
Foo.Bar.f();
|
||||
Foo foo = new Foo(); // not usage of default object
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class Foo {
|
||||
default object Bar {
|
||||
fun f() {
|
||||
}
|
||||
|
||||
platformStatic fun s() {
|
||||
}
|
||||
|
||||
val CONST = 42
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun main(args: Array<String>) {
|
||||
// class object usages
|
||||
Foo.f()
|
||||
val x = Foo
|
||||
|
||||
Foo.Bar.f()
|
||||
val xx = Foo.Bar
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "KOTLIN_CLASS",
|
||||
"classId": "/Foo.Bar",
|
||||
"oldName": "Bar",
|
||||
"newName": "Baz",
|
||||
"mainFile": "toBeRenamed.kt"
|
||||
}
|
||||
@@ -36,6 +36,12 @@ public class RenameTestGenerated extends AbstractRenameTest {
|
||||
JetTestUtils.assertAllTestsPresentInSingleGeneratedClass(this.getClass(), new File("idea/testData/refactoring/rename"), Pattern.compile("^(.+)\\.test$"));
|
||||
}
|
||||
|
||||
@TestMetadata("defaultObject/defaultObject.test")
|
||||
public void testDefaultObject_DefaultObject() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/rename/defaultObject/defaultObject.test");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("renameCompareTo/compareTo.test")
|
||||
public void testRenameCompareTo_CompareTo() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameCompareTo/compareTo.test");
|
||||
|
||||
Reference in New Issue
Block a user