Move: Report separate conflicts for each property accessor

#KT-13216 Fixed
This commit is contained in:
Alexey Sedunov
2016-08-19 18:16:27 +03:00
parent 9607fd0620
commit 6480118da6
11 changed files with 44 additions and 9 deletions
+1
View File
@@ -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
@@ -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
@@ -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)
}
}
@@ -0,0 +1,7 @@
package test
private class TempY
var tempY: Int = 0
get() { TempY(); return field }
set(p: Int) { TempY(); field = p }
@@ -0,0 +1,7 @@
package test
private class <caret>TempY
var tempY: Int = 0
get() { TempY(); return field }
set(p: Int) { TempY(); field = p }
@@ -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
@@ -0,0 +1,5 @@
{
"mainFile": "test.kt",
"type": "MOVE_KOTLIN_TOP_LEVEL_DECLARATIONS",
"targetFile": "target.kt"
}
@@ -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
@@ -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");