Light Classes: Replace accessor with property name when renaming KtProperty/KtParameter through its light methods
#KT-11880 Fixed
This commit is contained in:
@@ -179,6 +179,7 @@ Issues fixed:
|
||||
- Fix several issues leading to exceptions: [KT-11579](https://youtrack.jetbrains.com/issue/KT-11579), [KT-11580](https://youtrack.jetbrains.com/issue/KT-11580), [KT-11777](https://youtrack.jetbrains.com/issue/KT-11777), [KT-11868](https://youtrack.jetbrains.com/issue/KT-11868)
|
||||
- Fixed NoSuchFieldException in Kotlin module settings on IDEA Ultimate
|
||||
- [KT-11895](https://youtrack.jetbrains.com/issue/KT-11895) Fixed exception on highlighting of injected references
|
||||
- [KT-11880](https://youtrack.jetbrains.com/issue/KT-11880) Fixed renaming of Kotlin properties through SpEL references in XML files
|
||||
|
||||
#### Debugger
|
||||
|
||||
|
||||
@@ -24,6 +24,9 @@ import com.intellij.psi.scope.PsiScopeProcessor
|
||||
import com.intellij.psi.util.*
|
||||
import com.intellij.util.IncorrectOperationException
|
||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||
import org.jetbrains.kotlin.load.java.propertyNameByGetMethodName
|
||||
import org.jetbrains.kotlin.load.java.propertyNameBySetMethodName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKind
|
||||
|
||||
@@ -95,7 +98,19 @@ sealed class KtLightMethodImpl(
|
||||
|
||||
override fun setName(name: String): PsiElement? {
|
||||
val toRename = kotlinOrigin as? PsiNamedElement ?: throwCanNotModify()
|
||||
toRename.setName(name)
|
||||
|
||||
val newName = if (toRename is KtProperty || toRename is KtParameter) {
|
||||
val methodName = Name.guessByFirstCharacter(name)
|
||||
val propertyName = toRename.name ?: ""
|
||||
when {
|
||||
name.startsWith("get") -> propertyNameByGetMethodName(methodName)
|
||||
name.startsWith("set") -> propertyNameBySetMethodName(methodName, propertyName.startsWith("is"))
|
||||
else -> null
|
||||
}?.asString() ?: name
|
||||
}
|
||||
else name
|
||||
|
||||
toRename.setName(newName)
|
||||
return this
|
||||
}
|
||||
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package a;
|
||||
|
||||
public class J {
|
||||
static void test() {
|
||||
KotlinSpringBean bean = new KotlinSpringBean(1);
|
||||
bean.isFooNew();
|
||||
bean.setFooNew(true);
|
||||
}
|
||||
}
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
<bean class="a.KotlinSpringBean" name="xmlKotlinBean">
|
||||
<constructor-arg name="value" value="1"/>
|
||||
</bean>
|
||||
|
||||
<bean class="a.KotlinSpringBean" name="xmlKotlinBean2">
|
||||
<constructor-arg name="value" value="2"/>
|
||||
<property name="fooNew" value="#{xmlKotlinBean.fooNew}" />
|
||||
</bean>
|
||||
</beans>
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package a
|
||||
|
||||
class KotlinSpringBean(value: Int) {
|
||||
var isFooNew: Boolean = false
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val bean = KotlinSpringBean(1)
|
||||
bean.isFooNew
|
||||
bean.isFooNew = true
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package a;
|
||||
|
||||
public class J {
|
||||
static void test() {
|
||||
KotlinSpringBean bean = new KotlinSpringBean(1);
|
||||
bean.isFoo();
|
||||
bean.setFoo(true);
|
||||
}
|
||||
}
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
<bean class="a.KotlinSpringBean" name="xmlKotlinBean">
|
||||
<constructor-arg name="value" value="1"/>
|
||||
</bean>
|
||||
|
||||
<bean class="a.KotlinSpringBean" name="xmlKotlinBean2">
|
||||
<constructor-arg name="value" value="2"/>
|
||||
<property name="foo" value="#{xmlKotlinBean./*rename*/foo}" />
|
||||
</bean>
|
||||
</beans>
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package a
|
||||
|
||||
class KotlinSpringBean(value: Int) {
|
||||
var isFoo: Boolean = false
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val bean = KotlinSpringBean(1)
|
||||
bean.isFoo
|
||||
bean.isFoo = true
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"fixtureClasses": ["org.jetbrains.kotlin.idea.spring.tests.SpringTestFixtureExtension"],
|
||||
"type": "MARKED_ELEMENT",
|
||||
"mainFile": "a/spring-config.xml",
|
||||
"springFileSet": ["a/spring-config.xml"],
|
||||
"newName": "isFooNew",
|
||||
"byRef": "true",
|
||||
"injected": "true",
|
||||
"withRuntime": "true"
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package a;
|
||||
|
||||
public class J {
|
||||
static void test() {
|
||||
KotlinSpringBean bean = new KotlinSpringBean(1);
|
||||
bean.getFooNew();
|
||||
bean.setFooNew(2);
|
||||
}
|
||||
}
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
<bean class="a.KotlinSpringBean" name="xmlKotlinBean">
|
||||
<constructor-arg name="fooNew" value="1"/>
|
||||
</bean>
|
||||
|
||||
<bean class="a.KotlinSpringBean" name="xmlKotlinBean2">
|
||||
<constructor-arg name="fooNew" value="2"/>
|
||||
<property name="fooNew" value="#{xmlKotlinBean.fooNew}" />
|
||||
</bean>
|
||||
</beans>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package a
|
||||
|
||||
class KotlinSpringBean(var fooNew: Int)
|
||||
|
||||
fun test() {
|
||||
val bean = KotlinSpringBean(1)
|
||||
bean.fooNew
|
||||
bean.fooNew = 2
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package a;
|
||||
|
||||
public class J {
|
||||
static void test() {
|
||||
KotlinSpringBean bean = new KotlinSpringBean(1);
|
||||
bean.getFoo();
|
||||
bean.setFoo(2);
|
||||
}
|
||||
}
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
<bean class="a.KotlinSpringBean" name="xmlKotlinBean">
|
||||
<constructor-arg name="foo" value="1"/>
|
||||
</bean>
|
||||
|
||||
<bean class="a.KotlinSpringBean" name="xmlKotlinBean2">
|
||||
<constructor-arg name="foo" value="2"/>
|
||||
<property name="foo" value="#{xmlKotlinBean./*rename*/foo}" />
|
||||
</bean>
|
||||
</beans>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package a
|
||||
|
||||
class KotlinSpringBean(var foo: Int)
|
||||
|
||||
fun test() {
|
||||
val bean = KotlinSpringBean(1)
|
||||
bean.foo
|
||||
bean.foo = 2
|
||||
}
|
||||
ultimate/testData/spring/core/rename/parameterWithXmlRefsBySpelRef/parameterWithXmlRefBySpelRef.test
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"fixtureClasses": ["org.jetbrains.kotlin.idea.spring.tests.SpringTestFixtureExtension"],
|
||||
"type": "MARKED_ELEMENT",
|
||||
"mainFile": "a/spring-config.xml",
|
||||
"springFileSet": ["a/spring-config.xml"],
|
||||
"newName": "fooNew",
|
||||
"byRef": "true",
|
||||
"injected": "true",
|
||||
"withRuntime": "true"
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package a;
|
||||
|
||||
public class J {
|
||||
static void test() {
|
||||
KotlinSpringBean bean = new KotlinSpringBean(1);
|
||||
bean.getFooNew();
|
||||
bean.setFooNew(2);
|
||||
}
|
||||
}
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
<bean class="a.KotlinSpringBean" name="xmlKotlinBean">
|
||||
<constructor-arg name="value" value="1"/>
|
||||
</bean>
|
||||
|
||||
<bean class="a.KotlinSpringBean" name="xmlKotlinBean2">
|
||||
<constructor-arg name="value" value="2"/>
|
||||
<property name="fooNew" value="#{xmlKotlinBean.fooNew}" />
|
||||
</bean>
|
||||
</beans>
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package a
|
||||
|
||||
class KotlinSpringBean(value: Int) {
|
||||
var fooNew: Int = 0
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val bean = KotlinSpringBean(1)
|
||||
bean.fooNew
|
||||
bean.fooNew = 2
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package a;
|
||||
|
||||
public class J {
|
||||
static void test() {
|
||||
KotlinSpringBean bean = new KotlinSpringBean(1);
|
||||
bean.getFoo();
|
||||
bean.setFoo(2);
|
||||
}
|
||||
}
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
<bean class="a.KotlinSpringBean" name="xmlKotlinBean">
|
||||
<constructor-arg name="value" value="1"/>
|
||||
</bean>
|
||||
|
||||
<bean class="a.KotlinSpringBean" name="xmlKotlinBean2">
|
||||
<constructor-arg name="value" value="2"/>
|
||||
<property name="foo" value="#{xmlKotlinBean./*rename*/foo}" />
|
||||
</bean>
|
||||
</beans>
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package a
|
||||
|
||||
class KotlinSpringBean(value: Int) {
|
||||
var foo: Int = 0
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val bean = KotlinSpringBean(1)
|
||||
bean.foo
|
||||
bean.foo = 2
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"fixtureClasses": ["org.jetbrains.kotlin.idea.spring.tests.SpringTestFixtureExtension"],
|
||||
"type": "MARKED_ELEMENT",
|
||||
"mainFile": "a/spring-config.xml",
|
||||
"springFileSet": ["a/spring-config.xml"],
|
||||
"newName": "fooNew",
|
||||
"byRef": "true",
|
||||
"injected": "true",
|
||||
"withRuntime": "true"
|
||||
}
|
||||
+18
@@ -47,6 +47,12 @@ public class SpringRenameTestGenerated extends AbstractSpringRenameTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("isPropertyWithXmlRefsBySpelRef/isPropertyWithXmlRefBySpelRef.test")
|
||||
public void testIsPropertyWithXmlRefsBySpelRef_IsPropertyWithXmlRefBySpelRef() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("ultimate/testData/spring/core/rename/isPropertyWithXmlRefsBySpelRef/isPropertyWithXmlRefBySpelRef.test");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("javaSpelRefToJava/javaSpelRefToJava.test")
|
||||
public void testJavaSpelRefToJava_JavaSpelRefToJava() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("ultimate/testData/spring/core/rename/javaSpelRefToJava/javaSpelRefToJava.test");
|
||||
@@ -95,6 +101,12 @@ public class SpringRenameTestGenerated extends AbstractSpringRenameTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("parameterWithXmlRefsBySpelRef/parameterWithXmlRefBySpelRef.test")
|
||||
public void testParameterWithXmlRefsBySpelRef_ParameterWithXmlRefBySpelRef() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("ultimate/testData/spring/core/rename/parameterWithXmlRefsBySpelRef/parameterWithXmlRefBySpelRef.test");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("primaryConstructorArgWithXmlRefs/primaryConstructorArgWithXmlRef.test")
|
||||
public void testPrimaryConstructorArgWithXmlRefs_PrimaryConstructorArgWithXmlRef() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("ultimate/testData/spring/core/rename/primaryConstructorArgWithXmlRefs/primaryConstructorArgWithXmlRef.test");
|
||||
@@ -125,6 +137,12 @@ public class SpringRenameTestGenerated extends AbstractSpringRenameTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("propertyWithXmlRefsBySpelRef/propertyWithXmlRefBySpelRef.test")
|
||||
public void testPropertyWithXmlRefsBySpelRef_PropertyWithXmlRefBySpelRef() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("ultimate/testData/spring/core/rename/propertyWithXmlRefsBySpelRef/propertyWithXmlRefBySpelRef.test");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("setterFunWithXmlRefs/setterFunWithXmlRef.test")
|
||||
public void testSetterFunWithXmlRefs_SetterFunWithXmlRef() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("ultimate/testData/spring/core/rename/setterFunWithXmlRefs/setterFunWithXmlRef.test");
|
||||
|
||||
Reference in New Issue
Block a user