diff --git a/idea/src/org/jetbrains/kotlin/idea/findUsages/KotlinElementDescriptionProvider.kt b/idea/src/org/jetbrains/kotlin/idea/findUsages/KotlinElementDescriptionProvider.kt index f99187135eb..1e8e295cf36 100644 --- a/idea/src/org/jetbrains/kotlin/idea/findUsages/KotlinElementDescriptionProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/findUsages/KotlinElementDescriptionProvider.kt @@ -34,7 +34,9 @@ import org.jetbrains.kotlin.idea.refactoring.rename.RenameJavaSyntheticPropertyH import org.jetbrains.kotlin.idea.refactoring.rename.RenameKotlinPropertyProcessor import org.jetbrains.kotlin.idea.util.string.collapseSpaces import org.jetbrains.kotlin.name.FqNameUnsafe +import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType class KotlinElementDescriptionProvider : ElementDescriptionProvider { @@ -44,7 +46,16 @@ class KotlinElementDescriptionProvider : ElementDescriptionProvider { return parent } + private fun KtNamedDeclaration.name() = nameAsName ?: Name.special("") + private fun KtNamedDeclaration.fqName(): FqNameUnsafe { + containingClassOrObject?.let { + if (it is KtObjectDeclaration && it.isCompanion()) { + return it.fqName().child(name()) + } + return FqNameUnsafe("${it.name()}.${name()}") + } + val internalSegments = generateSequence(this) { it.parentForFqName() } .filterIsInstance() .map { it.name ?: "" } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/kotlinRefactoringUtil.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/kotlinRefactoringUtil.kt index 531f7c1e0df..b99d080b0a2 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/kotlinRefactoringUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/kotlinRefactoringUtil.kt @@ -142,7 +142,13 @@ fun VirtualFile.toPsiFileOrDirectory(project: Project): PsiFileSystemItem? = if fun PsiElement.getUsageContext(): PsiElement { return when (this) { - is KtElement -> PsiTreeUtil.getParentOfType(this, KtPropertyAccessor::class.java, KtNamedDeclaration::class.java, KtFile::class.java)!! + is KtElement -> PsiTreeUtil.getParentOfType( + this, + KtPropertyAccessor::class.java, + KtProperty::class.java, + KtFunction::class.java, + KtClassOrObject::class.java + ) ?: containingFile else -> ConflictsUtil.getContainer(this) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/moveConflictUtils.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/moveConflictUtils.kt index 55b16c8ae1b..55bc2f3044f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/moveConflictUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/moveConflictUtils.kt @@ -170,8 +170,7 @@ class MoveConflictChecker( val usageFile = element.containingFile val usageVFile = usageFile.virtualFile ?: continue val usageModule = ModuleUtilCore.findModuleForFile(usageVFile, project) ?: continue - val container = if (usageFile is PsiJavaFile) ConflictsUtil.getContainer(element) else usageFile - val scopeDescription = RefactoringUIUtil.getDescription(container, true) + val scopeDescription = RefactoringUIUtil.getDescription(element.getUsageContext(), true) val referencedElement = (if (usage is MoveRenameUsageInfo) usage.referencedElement else usage.element) ?: error(usage) val message = if (usageModule == targetModule && isInTestSources) { RefactoringBundle.message("0.referenced.in.1.will.not.be.accessible.from.production.of.module.2", diff --git a/idea/testData/codeInsight/breadcrumbs/AnonymousObjects.txt b/idea/testData/codeInsight/breadcrumbs/AnonymousObjects.txt index 3a6f29eba4a..3e40ff2d060 100644 --- a/idea/testData/codeInsight/breadcrumbs/AnonymousObjects.txt +++ b/idea/testData/codeInsight/breadcrumbs/AnonymousObjects.txt @@ -11,10 +11,10 @@ Crumbs: Tooltips: property v object : java.lang.Runnable - property v.<no name provided>.v2 + property <no name provided>.v2 object : A, B - function v.<no name provided>.v2.<no name provided>.f() + function <no name provided>.f() object : java.io.Serializable, XXX - property v.<no name provided>.v2.<no name provided>.f.<no name provided>.o + property <no name provided>.o object - function v.<no name provided>.v2.<no name provided>.f.<no name provided>.o.<no name provided>.equals(Any?) \ No newline at end of file + function <no name provided>.equals(Any?) \ No newline at end of file diff --git a/idea/testData/codeInsight/breadcrumbs/Declarations.txt b/idea/testData/codeInsight/breadcrumbs/Declarations.txt index 9555b599f11..3a04ef87116 100644 --- a/idea/testData/codeInsight/breadcrumbs/Declarations.txt +++ b/idea/testData/codeInsight/breadcrumbs/Declarations.txt @@ -11,8 +11,8 @@ Tooltips: class Outer companion object Outer.Companion class Outer.Companion.SomeClass - companion object Outer.Companion.SomeClass.CompanionName - object Outer.Companion.SomeClass.CompanionName.SomeObject - function Outer.Companion.SomeClass.CompanionName.SomeObject.someFun(Int, Boolean) on String + companion object SomeClass.CompanionName + object SomeClass.CompanionName.SomeObject + function SomeObject.someFun(Int, Boolean) on String function Outer.Companion.SomeClass.CompanionName.SomeObject.someFun.localFun() fun(x: Int, y: Char) \ No newline at end of file diff --git a/idea/testData/refactoring/moveMultiModule/moveDirectoryToUnrelatedModuleConflict/conflicts.txt b/idea/testData/refactoring/moveMultiModule/moveDirectoryToUnrelatedModuleConflict/conflicts.txt index f7f22eafb96..e7a83da56cb 100644 --- a/idea/testData/refactoring/moveMultiModule/moveDirectoryToUnrelatedModuleConflict/conflicts.txt +++ b/idea/testData/refactoring/moveMultiModule/moveDirectoryToUnrelatedModuleConflict/conflicts.txt @@ -1,3 +1,3 @@ -Class test2.J, referenced in property test2.pack.Bar.j, will not be accessible in module A -Class test2.J, referenced in property test2.pack.Foo.j, will not be accessible in module A +Class test2.J, referenced in property Bar.j, will not be accessible in module A +Class test2.J, referenced in property Foo.j, will not be accessible in module A Class test2.pack.Foo, referenced in field J.foo, will not be accessible from module B \ No newline at end of file diff --git a/idea/testData/refactoring/moveMultiModule/moveFileWithDeclarationsToUnrelatedModuleConflict/conflicts.txt b/idea/testData/refactoring/moveMultiModule/moveFileWithDeclarationsToUnrelatedModuleConflict/conflicts.txt index d83af2cf9ef..1ee9a8b6ceb 100644 --- a/idea/testData/refactoring/moveMultiModule/moveFileWithDeclarationsToUnrelatedModuleConflict/conflicts.txt +++ b/idea/testData/refactoring/moveMultiModule/moveFileWithDeclarationsToUnrelatedModuleConflict/conflicts.txt @@ -1 +1,2 @@ -Property a1.internalTargetVal, referenced in file internalSource.kt, will not be accessible from module A \ No newline at end of file +Property a1.internalTargetVal, referenced in file internalSource.kt, will not be accessible from module A +Property a1.internalTargetVal, referenced in property a2.sourceVal, will not be accessible from module A \ No newline at end of file diff --git a/idea/testData/refactoring/moveMultiModule/moveFromJsModuleToJvmModule/conflicts.txt b/idea/testData/refactoring/moveMultiModule/moveFromJsModuleToJvmModule/conflicts.txt index 796c63826ee..e3eafcb969f 100644 --- a/idea/testData/refactoring/moveMultiModule/moveFromJsModuleToJvmModule/conflicts.txt +++ b/idea/testData/refactoring/moveMultiModule/moveFromJsModuleToJvmModule/conflicts.txt @@ -1 +1 @@ -Constructor JsName(String), referenced in function packJs.ClassUsageJs.foo(), will not be accessible in module A +Constructor JsName(String), referenced in function ClassUsageJs.foo(), will not be accessible in module A diff --git a/idea/testData/refactoring/moveMultiModule/moveFromJvmModuleToJsModule/conflicts.txt b/idea/testData/refactoring/moveMultiModule/moveFromJvmModuleToJsModule/conflicts.txt index b0c74b69e4d..ce68ad95d41 100644 --- a/idea/testData/refactoring/moveMultiModule/moveFromJvmModuleToJsModule/conflicts.txt +++ b/idea/testData/refactoring/moveMultiModule/moveFromJvmModuleToJsModule/conflicts.txt @@ -1 +1 @@ -Constructor JvmStatic(), referenced in function packJvm.ClassUsageJvm.Companion.foo(), will not be accessible in module B \ No newline at end of file +Constructor JvmStatic(), referenced in function ClassUsageJvm.Companion.foo(), will not be accessible in module B \ No newline at end of file diff --git a/idea/testData/refactoring/moveMultiModule/moveInternalToAnotherModule/conflicts.txt b/idea/testData/refactoring/moveMultiModule/moveInternalToAnotherModule/conflicts.txt index 125f1b49fdb..8115cd94ef9 100644 --- a/idea/testData/refactoring/moveMultiModule/moveInternalToAnotherModule/conflicts.txt +++ b/idea/testData/refactoring/moveMultiModule/moveInternalToAnotherModule/conflicts.txt @@ -1,5 +1,6 @@ Class InternalContent uses function internalFun() which will be inaccessible after move Class packA1.InternalContent, referenced in file InternalSource.kt, will not be accessible from module A -Class packA2.InternalContentUser, referenced in function packA1.InternalContent.useInternal(), will not be accessible in module B -Function packA2.InternalContentUser.internalFun(), referenced in function packA1.InternalContent.useInternal(), will not be accessible in module B +Class packA1.InternalContent, referenced in function InternalContentUser.useInternal(InternalContent), will not be accessible from module A +Class packA2.InternalContentUser, referenced in function InternalContent.useInternal(), will not be accessible in module B +Function InternalContentUser.internalFun(), referenced in function InternalContent.useInternal(), will not be accessible in module B Function useInternal(InternalContent) uses internal function internalFun() which will be inaccessible after move \ No newline at end of file diff --git a/idea/testData/refactoring/moveMultiModule/moveMultipleFilesToUnrelatedModuleConflict/conflicts.txt b/idea/testData/refactoring/moveMultiModule/moveMultipleFilesToUnrelatedModuleConflict/conflicts.txt index 7d2731dc0f6..21295a92695 100644 --- a/idea/testData/refactoring/moveMultiModule/moveMultipleFilesToUnrelatedModuleConflict/conflicts.txt +++ b/idea/testData/refactoring/moveMultiModule/moveMultipleFilesToUnrelatedModuleConflict/conflicts.txt @@ -1,4 +1,4 @@ Class test.Bar, referenced in field J.bar, will not be accessible from module A Class test.Foo, referenced in field J.foo, will not be accessible from module A -Class test.J, referenced in property test.Bar.j, will not be accessible in module B -Class test.J, referenced in property test.Foo.j, will not be accessible in module B \ No newline at end of file +Class test.J, referenced in property Bar.j, will not be accessible in module B +Class test.J, referenced in property Foo.j, will not be accessible in module B \ No newline at end of file diff --git a/idea/testData/refactoring/moveMultiModule/movePackageToUnrelatedModuleConflict/conflicts.txt b/idea/testData/refactoring/moveMultiModule/movePackageToUnrelatedModuleConflict/conflicts.txt index f7f22eafb96..e7a83da56cb 100644 --- a/idea/testData/refactoring/moveMultiModule/movePackageToUnrelatedModuleConflict/conflicts.txt +++ b/idea/testData/refactoring/moveMultiModule/movePackageToUnrelatedModuleConflict/conflicts.txt @@ -1,3 +1,3 @@ -Class test2.J, referenced in property test2.pack.Bar.j, will not be accessible in module A -Class test2.J, referenced in property test2.pack.Foo.j, will not be accessible in module A +Class test2.J, referenced in property Bar.j, will not be accessible in module A +Class test2.J, referenced in property Foo.j, will not be accessible in module A Class test2.pack.Foo, referenced in field J.foo, will not be accessible from module B \ No newline at end of file diff --git a/idea/testData/refactoring/moveMultiModule/moveToUnrelatedModuleConflict/conflicts.txt b/idea/testData/refactoring/moveMultiModule/moveToUnrelatedModuleConflict/conflicts.txt index 9ffc4da0557..d8eca2123ed 100644 --- a/idea/testData/refactoring/moveMultiModule/moveToUnrelatedModuleConflict/conflicts.txt +++ b/idea/testData/refactoring/moveMultiModule/moveToUnrelatedModuleConflict/conflicts.txt @@ -1 +1 @@ -Property a.val1, referenced in file test.kt, will not be accessible from module A +Property a.val1, referenced in property a.val2, will not be accessible from module A \ No newline at end of file diff --git a/idea/testData/refactoring/safeDelete/deleteClass/kotlinClass/nestedClass2.kt.messages b/idea/testData/refactoring/safeDelete/deleteClass/kotlinClass/nestedClass2.kt.messages index 00b52f628bb..6958f3738bd 100644 --- a/idea/testData/refactoring/safeDelete/deleteClass/kotlinClass/nestedClass2.kt.messages +++ b/idea/testData/refactoring/safeDelete/deleteClass/kotlinClass/nestedClass2.kt.messages @@ -1 +1 @@ -class test.A.C has 1 usage that is not safe to delete. \ No newline at end of file +class A.C has 1 usage that is not safe to delete. \ No newline at end of file diff --git a/idea/testData/refactoring/safeDelete/deleteObject/kotlinObject/nestedObject2.kt.messages b/idea/testData/refactoring/safeDelete/deleteObject/kotlinObject/nestedObject2.kt.messages index 84f072b7092..c90df212926 100644 --- a/idea/testData/refactoring/safeDelete/deleteObject/kotlinObject/nestedObject2.kt.messages +++ b/idea/testData/refactoring/safeDelete/deleteObject/kotlinObject/nestedObject2.kt.messages @@ -1 +1 @@ -object test.A.O has 1 usage that is not safe to delete. \ No newline at end of file +object A.O has 1 usage that is not safe to delete. \ No newline at end of file diff --git a/idea/testData/refactoring/safeDelete/deleteProperty/kotlinProperty/propertyInLocalObject.kt.messages b/idea/testData/refactoring/safeDelete/deleteProperty/kotlinProperty/propertyInLocalObject.kt.messages index 2d77a2bf313..e4162e7cc87 100644 --- a/idea/testData/refactoring/safeDelete/deleteProperty/kotlinProperty/propertyInLocalObject.kt.messages +++ b/idea/testData/refactoring/safeDelete/deleteProperty/kotlinProperty/propertyInLocalObject.kt.messages @@ -1 +1 @@ -property context.<no name provided>.addition has 1 usage that is not safe to delete. \ No newline at end of file +property <no name provided>.addition has 1 usage that is not safe to delete. \ No newline at end of file