Rename: Rename do-while loop variables in the loop condition
#KT-14157 Fixed
This commit is contained in:
@@ -235,6 +235,7 @@ These artifacts include extensions for the types available in the latter JDKs, s
|
|||||||
- [`KT-14004`](https://youtrack.jetbrains.com/issue/KT-14004) Introduce Variable: Fix exception on trying to extract variable of functional type
|
- [`KT-14004`](https://youtrack.jetbrains.com/issue/KT-14004) Introduce Variable: Fix exception on trying to extract variable of functional type
|
||||||
- [`KT-13726`](https://youtrack.jetbrains.com/issue/KT-13726) Move: Fix bogus conflicts due to references resolving to wrong library version
|
- [`KT-13726`](https://youtrack.jetbrains.com/issue/KT-13726) Move: Fix bogus conflicts due to references resolving to wrong library version
|
||||||
- [`KT-14114`](https://youtrack.jetbrains.com/issue/KT-14114) Move: Fix exception on moving Kotlin file without declarations
|
- [`KT-14114`](https://youtrack.jetbrains.com/issue/KT-14114) Move: Fix exception on moving Kotlin file without declarations
|
||||||
|
- [`KT-14157`](https://youtrack.jetbrains.com/issue/KT-14157) Rename: Rename do-while loop variables in the loop condition
|
||||||
|
|
||||||
##### New features
|
##### New features
|
||||||
|
|
||||||
|
|||||||
@@ -103,7 +103,18 @@ abstract class KtNamedDeclarationStub<T extends KotlinStubWithFqName<?>> extends
|
|||||||
@Override
|
@Override
|
||||||
public SearchScope getUseScope() {
|
public SearchScope getUseScope() {
|
||||||
KtElement enclosingBlock = KtPsiUtil.getEnclosingElementForLocalDeclaration(this, false);
|
KtElement enclosingBlock = KtPsiUtil.getEnclosingElementForLocalDeclaration(this, false);
|
||||||
if (enclosingBlock != null) return new LocalSearchScope(enclosingBlock);
|
if (enclosingBlock != null) {
|
||||||
|
PsiElement enclosingParent = enclosingBlock.getParent();
|
||||||
|
if (enclosingParent instanceof KtContainerNode) {
|
||||||
|
enclosingParent = enclosingParent.getParent();
|
||||||
|
}
|
||||||
|
if (enclosingBlock instanceof KtBlockExpression && enclosingParent instanceof KtDoWhileExpression) {
|
||||||
|
KtExpression condition = ((KtDoWhileExpression) enclosingParent).getCondition();
|
||||||
|
if (condition != null) return new LocalSearchScope(new PsiElement[] { enclosingBlock, condition });
|
||||||
|
}
|
||||||
|
|
||||||
|
return new LocalSearchScope(enclosingBlock);
|
||||||
|
}
|
||||||
|
|
||||||
if (hasModifier(KtTokens.PRIVATE_KEYWORD)) {
|
if (hasModifier(KtTokens.PRIVATE_KEYWORD)) {
|
||||||
KtElement containingClass = PsiTreeUtil.getParentOfType(this, KtClassOrObject.class);
|
KtElement containingClass = PsiTreeUtil.getParentOfType(this, KtClassOrObject.class);
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtProperty
|
||||||
|
// OPTIONS: usages
|
||||||
|
fun test() {
|
||||||
|
do {
|
||||||
|
val <caret>message = "test"
|
||||||
|
println(message)
|
||||||
|
} while (message.isEmpty())
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
Receiver 7 } while (message.isEmpty())
|
||||||
|
Value read 6 println(message)
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun test() {
|
||||||
|
do {
|
||||||
|
val message2 = "test"
|
||||||
|
println(message2)
|
||||||
|
} while (message2.isEmpty())
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun test() {
|
||||||
|
do {
|
||||||
|
val /*rename*/message = "test"
|
||||||
|
println(message)
|
||||||
|
} while (message.isEmpty())
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"type": "MARKED_ELEMENT",
|
||||||
|
"mainFile": "test.kt",
|
||||||
|
"newName": "message2",
|
||||||
|
"withRuntime": "true"
|
||||||
|
}
|
||||||
@@ -1347,6 +1347,12 @@ public class FindUsagesTestGenerated extends AbstractFindUsagesTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("varInDoWhile.0.kt")
|
||||||
|
public void testVarInDoWhile() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/variable/varInDoWhile.0.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("writeAccess.0.kt")
|
@TestMetadata("writeAccess.0.kt")
|
||||||
public void testWriteAccess() throws Exception {
|
public void testWriteAccess() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/variable/writeAccess.0.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/variable/writeAccess.0.kt");
|
||||||
|
|||||||
@@ -1102,4 +1102,10 @@ public class RenameTestGenerated extends AbstractRenameTest {
|
|||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/topLevelPropertyRedeclaration/topLevelPropertyRedeclaration.test");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/topLevelPropertyRedeclaration/topLevelPropertyRedeclaration.test");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("varInDoWhile/varInDoWhile.test")
|
||||||
|
public void testVarInDoWhile_VarInDoWhile() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/rename/varInDoWhile/varInDoWhile.test");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user