Supported renaming default objects with default names.
This commit is contained in:
@@ -76,8 +76,16 @@ public class JetObjectDeclaration extends JetNamedDeclarationStub<KotlinObjectSt
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
|
public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
|
||||||
JetObjectDeclarationName nameAsDeclaration = getNameAsDeclaration();
|
JetObjectDeclarationName declarationName = getNameAsDeclaration();
|
||||||
return nameAsDeclaration == null ? null : nameAsDeclaration.setName(name);
|
if (declarationName == null) {
|
||||||
|
JetPsiFactory psiFactory = new JetPsiFactory(getProject());
|
||||||
|
PsiElement result = addAfter(psiFactory.createObjectDeclarationName(name), getObjectKeyword());
|
||||||
|
addAfter(psiFactory.createWhiteSpace(), getObjectKeyword());
|
||||||
|
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
return declarationName.setName(name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -195,6 +195,10 @@ public class JetPsiFactory(private val project: Project) {
|
|||||||
return createProperty(name, null, false, name).getInitializer() as JetSimpleNameExpression
|
return createProperty(name, null, false, name).getInitializer() as JetSimpleNameExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public fun createObjectDeclarationName(name: String): JetObjectDeclarationName {
|
||||||
|
return createDeclaration<JetObjectDeclaration>("object $name").getNameAsDeclaration()!!
|
||||||
|
}
|
||||||
|
|
||||||
public fun createIdentifier(name: String): PsiElement {
|
public fun createIdentifier(name: String): PsiElement {
|
||||||
return createSimpleName(name).getIdentifier()!!
|
return createSimpleName(name).getIdentifier()!!
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.Default.f();
|
||||||
|
Foo foo = new Foo(); // not usage of default object
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
class Foo {
|
||||||
|
default object {
|
||||||
|
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.Default.f()
|
||||||
|
val xx = Foo.Default
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"type": "KOTLIN_CLASS",
|
||||||
|
"classId": "/Foo.Default",
|
||||||
|
"oldName": "Default",
|
||||||
|
"newName": "Baz",
|
||||||
|
"mainFile": "toBeRenamed.kt"
|
||||||
|
}
|
||||||
@@ -42,6 +42,12 @@ public class RenameTestGenerated extends AbstractRenameTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("defaultObjectWithDefaultName/defaultObject.test")
|
||||||
|
public void testDefaultObjectWithDefaultName_DefaultObject() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/rename/defaultObjectWithDefaultName/defaultObject.test");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("renameCompareTo/compareTo.test")
|
@TestMetadata("renameCompareTo/compareTo.test")
|
||||||
public void testRenameCompareTo_CompareTo() throws Exception {
|
public void testRenameCompareTo_CompareTo() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameCompareTo/compareTo.test");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/rename/renameCompareTo/compareTo.test");
|
||||||
|
|||||||
Reference in New Issue
Block a user