diff --git a/ChangeLog.md b/ChangeLog.md index 94bf6e4c8c7..3afa283d530 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -100,6 +100,7 @@ These artifacts include extensions for the types available in the latter JDKs, s #### Refactorings - [`KT-13535`](https://youtrack.jetbrains.com/issue/KT-13535) Pull Up: Remove visibility modifiers on adding 'override' +- [`KT-13216`](https://youtrack.jetbrains.com/issue/KT-13216) Move: Report separate conflicts for each property accessor ## 1.0.4 diff --git a/idea/src/org/jetbrains/kotlin/idea/findUsages/KotlinElementDescriptionProvider.kt b/idea/src/org/jetbrains/kotlin/idea/findUsages/KotlinElementDescriptionProvider.kt index 546997c25d1..2b03d6e0b80 100644 --- a/idea/src/org/jetbrains/kotlin/idea/findUsages/KotlinElementDescriptionProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/findUsages/KotlinElementDescriptionProvider.kt @@ -54,6 +54,7 @@ class KotlinElementDescriptionProvider : ElementDescriptionProvider { is KtClass -> if (targetElement.isInterface()) "interface" else "class" is KtObjectDeclaration -> "object" is KtNamedFunction -> "function" + is KtPropertyAccessor -> (if (targetElement.isGetter) "getter" else "setter") + " for property " is KtFunctionLiteral -> "lambda" is KtPrimaryConstructor, is KtSecondaryConstructor -> "constructor" is KtProperty -> if (targetElement.isLocal) "variable" else "property" @@ -67,17 +68,21 @@ class KotlinElementDescriptionProvider : ElementDescriptionProvider { else -> null } - if (targetElement !is PsiNamedElement || targetElement.language != KotlinLanguage.INSTANCE) return null + val namedElement = if (targetElement is KtPropertyAccessor) { + targetElement.parent as? KtProperty + } else targetElement as? PsiNamedElement + + if (namedElement == null || namedElement.language != KotlinLanguage.INSTANCE) return null return when(location) { is UsageViewTypeLocation -> elementKind() - is UsageViewShortNameLocation, is UsageViewLongNameLocation -> targetElement.name + is UsageViewShortNameLocation, is UsageViewLongNameLocation -> namedElement.name is RefactoringDescriptionLocation -> { val kind = elementKind() ?: return null - val descriptor = (targetElement as KtDeclaration).descriptor ?: return null + val descriptor = (namedElement as KtDeclaration).descriptor ?: return null val renderFqName = location.includeParent() && - targetElement !is KtTypeParameter && - targetElement !is KtParameter && - targetElement !is KtConstructor<*> + namedElement !is KtTypeParameter && + namedElement !is KtParameter && + namedElement !is KtConstructor<*> val desc = when (descriptor) { is FunctionDescriptor -> { val baseText = REFACTORING_RENDERER.render(descriptor) @@ -91,7 +96,7 @@ class KotlinElementDescriptionProvider : ElementDescriptionProvider { } is HighlightUsagesDescriptionLocation -> { val kind = elementKind() ?: return null - val descriptor = (targetElement as KtDeclaration).descriptor ?: return null + val descriptor = (namedElement as KtDeclaration).descriptor ?: return null "$kind ${descriptor.name.asString()}" } else -> null diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/kotlinRefactoringUtil.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/kotlinRefactoringUtil.kt index 45e8bb4355c..e873212564b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/kotlinRefactoringUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/kotlinRefactoringUtil.kt @@ -126,7 +126,7 @@ fun VirtualFile.toPsiDirectory(project: Project): PsiDirectory? = PsiManager.get fun PsiElement.getUsageContext(): PsiElement { return when (this) { - is KtElement -> PsiTreeUtil.getParentOfType(this, KtNamedDeclaration::class.java, KtFile::class.java)!! + is KtElement -> PsiTreeUtil.getParentOfType(this, KtPropertyAccessor::class.java, KtNamedDeclaration::class.java, KtFile::class.java)!! else -> ConflictsUtil.getContainer(this) } } diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePrivateClassWithUsagesInBothAccessors/after/target.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePrivateClassWithUsagesInBothAccessors/after/target.kt new file mode 100644 index 00000000000..761254b6c6f --- /dev/null +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePrivateClassWithUsagesInBothAccessors/after/target.kt @@ -0,0 +1 @@ +package test \ No newline at end of file diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePrivateClassWithUsagesInBothAccessors/after/test.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePrivateClassWithUsagesInBothAccessors/after/test.kt new file mode 100644 index 00000000000..a76463d61d3 --- /dev/null +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePrivateClassWithUsagesInBothAccessors/after/test.kt @@ -0,0 +1,7 @@ +package test + +private class TempY + +var tempY: Int = 0 + get() { TempY(); return field } + set(p: Int) { TempY(); field = p } \ No newline at end of file diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePrivateClassWithUsagesInBothAccessors/before/target.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePrivateClassWithUsagesInBothAccessors/before/target.kt new file mode 100644 index 00000000000..761254b6c6f --- /dev/null +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePrivateClassWithUsagesInBothAccessors/before/target.kt @@ -0,0 +1 @@ +package test \ No newline at end of file diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePrivateClassWithUsagesInBothAccessors/before/test.kt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePrivateClassWithUsagesInBothAccessors/before/test.kt new file mode 100644 index 00000000000..c2190e82f28 --- /dev/null +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePrivateClassWithUsagesInBothAccessors/before/test.kt @@ -0,0 +1,7 @@ +package test + +private class TempY + +var tempY: Int = 0 + get() { TempY(); return field } + set(p: Int) { TempY(); field = p } \ No newline at end of file diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePrivateClassWithUsagesInBothAccessors/conflicts.txt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePrivateClassWithUsagesInBothAccessors/conflicts.txt new file mode 100644 index 00000000000..f4a467a8b24 --- /dev/null +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePrivateClassWithUsagesInBothAccessors/conflicts.txt @@ -0,0 +1,2 @@ +Getter for property tempY uses class TempY which will be inaccessible after move +Setter for property tempY uses class TempY which will be inaccessible after move \ No newline at end of file diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePrivateClassWithUsagesInBothAccessors/movePrivateClassWithusagesInBothAccessors.test b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePrivateClassWithUsagesInBothAccessors/movePrivateClassWithusagesInBothAccessors.test new file mode 100644 index 00000000000..a781295bc94 --- /dev/null +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePrivateClassWithUsagesInBothAccessors/movePrivateClassWithusagesInBothAccessors.test @@ -0,0 +1,5 @@ +{ + "mainFile": "test.kt", + "type": "MOVE_KOTLIN_TOP_LEVEL_DECLARATIONS", + "targetFile": "target.kt" +} diff --git a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePrivateProperty/conflicts.txt b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePrivateProperty/conflicts.txt index 9d0b3192b08..94493c54c80 100644 --- a/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePrivateProperty/conflicts.txt +++ b/idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePrivateProperty/conflicts.txt @@ -1,2 +1,2 @@ -Property bar uses property foo which will be inaccessible after move +Getter for property bar uses property foo which will be inaccessible after move Property foo uses property bar which will be inaccessible after move \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/move/MoveTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/refactoring/move/MoveTestGenerated.java index 558b90e8b92..4d347e2ae96 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/move/MoveTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/move/MoveTestGenerated.java @@ -563,6 +563,12 @@ public class MoveTestGenerated extends AbstractMoveTest { doTest(fileName); } + @TestMetadata("kotlin/moveTopLevelDeclarations/movePrivateClassWithUsagesInBothAccessors/movePrivateClassWithusagesInBothAccessors.test") + public void testKotlin_moveTopLevelDeclarations_movePrivateClassWithUsagesInBothAccessors_MovePrivateClassWithusagesInBothAccessors() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePrivateClassWithUsagesInBothAccessors/movePrivateClassWithusagesInBothAccessors.test"); + doTest(fileName); + } + @TestMetadata("kotlin/moveTopLevelDeclarations/movePrivateFun/movePrivateFun.test") public void testKotlin_moveTopLevelDeclarations_movePrivateFun_MovePrivateFun() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/movePrivateFun/movePrivateFun.test");