Rename: Process property accesor usages (Java) in comments and string literals
#KT-9435 Fixed (cherry picked from commit 911afee)
This commit is contained in:
@@ -237,6 +237,7 @@
|
|||||||
- [`KT-9156`](https://youtrack.jetbrains.com/issue/KT-9156) Quote non-identifier names in Kotlin references
|
- [`KT-9156`](https://youtrack.jetbrains.com/issue/KT-9156) Quote non-identifier names in Kotlin references
|
||||||
- [`KT-9157`](https://youtrack.jetbrains.com/issue/KT-9157) Fixed in-place rename of Kotlin expression referring Java declaration
|
- [`KT-9157`](https://youtrack.jetbrains.com/issue/KT-9157) Fixed in-place rename of Kotlin expression referring Java declaration
|
||||||
- [`KT-9241`](https://youtrack.jetbrains.com/issue/KT-9241) Do not replace Java references to synthetic component functions when renaming constructor parameter
|
- [`KT-9241`](https://youtrack.jetbrains.com/issue/KT-9241) Do not replace Java references to synthetic component functions when renaming constructor parameter
|
||||||
|
- [`KT-9435`](https://youtrack.jetbrains.com/issue/KT-9435) Process property accesor usages (Java) in comments and string literals
|
||||||
- [`KT-9444`](https://youtrack.jetbrains.com/issue/KT-9444) Rename dialog: Allow typing any identifier without backquotes
|
- [`KT-9444`](https://youtrack.jetbrains.com/issue/KT-9444) Rename dialog: Allow typing any identifier without backquotes
|
||||||
- [`KT-9446`](https://youtrack.jetbrains.com/issue/KT-9446) Warn about calls with default arguments if function to be renamed inherits default values from some base function which is excluded from rename
|
- [`KT-9446`](https://youtrack.jetbrains.com/issue/KT-9446) Warn about calls with default arguments if function to be renamed inherits default values from some base function which is excluded from rename
|
||||||
- [`KT-10713`](https://youtrack.jetbrains.com/issue/KT-10713) Skip read-only declarations when renaming parameters
|
- [`KT-10713`](https://youtrack.jetbrains.com/issue/KT-10713) Skip read-only declarations when renaming parameters
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.name.FqName
|
|||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
|
|
||||||
open class FakeFileForLightClass(
|
open class FakeFileForLightClass(
|
||||||
private val ktFile: KtFile,
|
protected val ktFile: KtFile,
|
||||||
private val lightClass: () -> KtLightClass,
|
private val lightClass: () -> KtLightClass,
|
||||||
private val stub: () -> PsiClassHolderFileStub<*>,
|
private val stub: () -> PsiClassHolderFileStub<*>,
|
||||||
private val packageFqName: FqName = ktFile.packageFqName
|
private val packageFqName: FqName = ktFile.packageFqName
|
||||||
|
|||||||
+2
@@ -185,6 +185,8 @@ open class KtLightClassForExplicitDeclaration(
|
|||||||
{ if (classOrObject.isTopLevel()) this else create(getOutermostClassOrObject(classOrObject))!! },
|
{ if (classOrObject.isTopLevel()) this else create(getOutermostClassOrObject(classOrObject))!! },
|
||||||
{ getJavaFileStub() }
|
{ getJavaFileStub() }
|
||||||
) {
|
) {
|
||||||
|
override fun findReferenceAt(offset: Int) = ktFile.findReferenceAt(offset)
|
||||||
|
|
||||||
override fun processDeclarations(
|
override fun processDeclarations(
|
||||||
processor: PsiScopeProcessor,
|
processor: PsiScopeProcessor,
|
||||||
state: ResolveState,
|
state: ResolveState,
|
||||||
|
|||||||
+14
@@ -245,7 +245,21 @@ class RenameKotlinPropertyProcessor : RenameKotlinPsiProcessor() {
|
|||||||
|
|
||||||
val newPropertyName = if (newName != null && element is KtLightMethod) propertyNameByAccessor(newName, element) else newName
|
val newPropertyName = if (newName != null && element is KtLightMethod) propertyNameByAccessor(newName, element) else newName
|
||||||
|
|
||||||
|
val (getterJvmName, setterJvmName) = getJvmNames(namedUnwrappedElement)
|
||||||
|
|
||||||
for (propertyMethod in propertyMethods) {
|
for (propertyMethod in propertyMethods) {
|
||||||
|
if (element is KtDeclaration && newPropertyName != null) {
|
||||||
|
val wrapper = object : PsiNamedElement by propertyMethod {
|
||||||
|
override fun setName(name: String) = this
|
||||||
|
override fun copy() = this
|
||||||
|
}
|
||||||
|
when {
|
||||||
|
JvmAbi.isGetterName(propertyMethod.name) && getterJvmName == null ->
|
||||||
|
allRenames[wrapper] = JvmAbi.getterName(newPropertyName)
|
||||||
|
JvmAbi.isSetterName(propertyMethod.name) && setterJvmName == null ->
|
||||||
|
allRenames[wrapper] = JvmAbi.setterName(newPropertyName)
|
||||||
|
}
|
||||||
|
}
|
||||||
addRenameElements(propertyMethod, (element as PsiNamedElement).name, newPropertyName, allRenames, scope)
|
addRenameElements(propertyMethod, (element as PsiNamedElement).name, newPropertyName, allRenames, scope)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
public class CommentUsage {
|
||||||
|
public void context() {
|
||||||
|
Used.usedVar2 = 0;
|
||||||
|
Used.setUsedVar2(0);
|
||||||
|
Used.getUsedVar2();
|
||||||
|
Used.INSTANCE.usedVar2 = 0;
|
||||||
|
Used.INSTANCE.setUsedVar2(0);
|
||||||
|
Used.INSTANCE.getUsedVar2();
|
||||||
|
// Used.usedVar2 = 0;
|
||||||
|
// Used.setUsedVar2(0);
|
||||||
|
// Used.getUsedVar2();
|
||||||
|
// Used.INSTANCE.usedVar2 = 0;
|
||||||
|
// Used.INSTANCE.setUsedVar2(0);
|
||||||
|
// Used.INSTANCE.getUsedVar2();
|
||||||
|
String v = "Used.usedVar2"
|
||||||
|
+ "Used.setUsedVar2(0)"
|
||||||
|
+ "Used.getUsedVar2()"
|
||||||
|
+ "Used.INSTANCE.usedVar2"
|
||||||
|
+ "Used.INSTANCE.setUsedVar2(0)"
|
||||||
|
+ "Used.INSTANCE.getUsedVar2()";
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
object Used {
|
||||||
|
@JvmStatic var usedVar2 = 0
|
||||||
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
public class CommentUsage {
|
||||||
|
public void context() {
|
||||||
|
Used.usedVar = 0;
|
||||||
|
Used.setUsedVar(0);
|
||||||
|
Used.getUsedVar();
|
||||||
|
Used.INSTANCE.usedVar = 0;
|
||||||
|
Used.INSTANCE.setUsedVar(0);
|
||||||
|
Used.INSTANCE.getUsedVar();
|
||||||
|
// Used.usedVar = 0;
|
||||||
|
// Used.setUsedVar(0);
|
||||||
|
// Used.getUsedVar();
|
||||||
|
// Used.INSTANCE.usedVar = 0;
|
||||||
|
// Used.INSTANCE.setUsedVar(0);
|
||||||
|
// Used.INSTANCE.getUsedVar();
|
||||||
|
String v = "Used.usedVar"
|
||||||
|
+ "Used.setUsedVar(0)"
|
||||||
|
+ "Used.getUsedVar()"
|
||||||
|
+ "Used.INSTANCE.usedVar"
|
||||||
|
+ "Used.INSTANCE.setUsedVar(0)"
|
||||||
|
+ "Used.INSTANCE.getUsedVar()";
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
object Used {
|
||||||
|
@JvmStatic var /*rename*/usedVar = 0
|
||||||
|
}
|
||||||
Vendored
+6
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"type": "MARKED_ELEMENT",
|
||||||
|
"mainFile": "test/Used.kt",
|
||||||
|
"newName": "usedVar2",
|
||||||
|
"withRuntime": "true"
|
||||||
|
}
|
||||||
@@ -203,6 +203,12 @@ public class RenameTestGenerated extends AbstractRenameTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nonCodePropertyAccessorUsages/nonCodePropertyAccessorUsages.test")
|
||||||
|
public void testNonCodePropertyAccessorUsages_NonCodePropertyAccessorUsages() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/nonCodePropertyAccessorUsages/nonCodePropertyAccessorUsages.test");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("parameterRedeclaration/parameterRedeclaration.test")
|
@TestMetadata("parameterRedeclaration/parameterRedeclaration.test")
|
||||||
public void testParameterRedeclaration_ParameterRedeclaration() throws Exception {
|
public void testParameterRedeclaration_ParameterRedeclaration() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/parameterRedeclaration/parameterRedeclaration.test");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/parameterRedeclaration/parameterRedeclaration.test");
|
||||||
|
|||||||
Reference in New Issue
Block a user