diff --git a/plugins/kotlin/idea/tests/testData/refactoring/moveMultiModule/moveFileWithDeclarationsToUnrelatedModuleConflict/conflicts.k2.txt b/plugins/kotlin/idea/tests/testData/refactoring/moveMultiModule/moveFileWithDeclarationsToUnrelatedModuleConflict/conflicts.k2.txt new file mode 100644 index 000000000000..40e66ef29329 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/refactoring/moveMultiModule/moveFileWithDeclarationsToUnrelatedModuleConflict/conflicts.k2.txt @@ -0,0 +1,2 @@ +File internalSource.kt uses property internalTargetVal which will be inaccessible after move +Property sourceVal uses property internalTargetVal which will be inaccessible after move diff --git a/plugins/kotlin/idea/tests/testData/refactoring/moveMultiModule/moveFileWithDeclarationsToUnrelatedModuleConflict/conflicts.txt b/plugins/kotlin/idea/tests/testData/refactoring/moveMultiModule/moveFileWithDeclarationsToUnrelatedModuleConflict/conflicts.txt index 1ee9a8b6ceb8..8b9e91197405 100644 --- a/plugins/kotlin/idea/tests/testData/refactoring/moveMultiModule/moveFileWithDeclarationsToUnrelatedModuleConflict/conflicts.txt +++ b/plugins/kotlin/idea/tests/testData/refactoring/moveMultiModule/moveFileWithDeclarationsToUnrelatedModuleConflict/conflicts.txt @@ -1,2 +1,2 @@ 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 +Property a1.internalTargetVal, referenced in property a2.sourceVal, will not be accessible from module A diff --git a/plugins/kotlin/idea/tests/testData/refactoring/moveMultiModule/moveFileWithDeclarationsToUnrelatedModuleConflict/moveFileWithDeclarationsToUnrelatedModuleConflict.test b/plugins/kotlin/idea/tests/testData/refactoring/moveMultiModule/moveFileWithDeclarationsToUnrelatedModuleConflict/moveFileWithDeclarationsToUnrelatedModuleConflict.test index 8222083604e7..4d02fe8c98bb 100644 --- a/plugins/kotlin/idea/tests/testData/refactoring/moveMultiModule/moveFileWithDeclarationsToUnrelatedModuleConflict/moveFileWithDeclarationsToUnrelatedModuleConflict.test +++ b/plugins/kotlin/idea/tests/testData/refactoring/moveMultiModule/moveFileWithDeclarationsToUnrelatedModuleConflict/moveFileWithDeclarationsToUnrelatedModuleConflict.test @@ -4,5 +4,5 @@ "targetDirectory": "B/src/b", "withRuntime": "true", "enabledInK1": "true", - "enabledInK2": "false" + "enabledInK2": "true" } diff --git a/plugins/kotlin/idea/tests/testData/refactoring/moveMultiModule/moveInternalToAnotherModule/conflicts.k2.txt b/plugins/kotlin/idea/tests/testData/refactoring/moveMultiModule/moveInternalToAnotherModule/conflicts.k2.txt new file mode 100644 index 000000000000..9b71a5d4cb4a --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/refactoring/moveMultiModule/moveInternalToAnotherModule/conflicts.k2.txt @@ -0,0 +1,5 @@ +Class packA1.InternalContent, referenced in file InternalSource.kt, will not be accessible from module A +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 useInternal() uses function internalFunUser() which will be inaccessible after move +Function useInternal(InternalContent) uses function internalFun() which will be inaccessible after move diff --git a/plugins/kotlin/idea/tests/testData/refactoring/moveMultiModule/visibilityConflictInImport/conflicts.k2.txt b/plugins/kotlin/idea/tests/testData/refactoring/moveMultiModule/visibilityConflictInImport/conflicts.k2.txt index cb1bf0cffe47..901dac74c659 100644 --- a/plugins/kotlin/idea/tests/testData/refactoring/moveMultiModule/visibilityConflictInImport/conflicts.k2.txt +++ b/plugins/kotlin/idea/tests/testData/refactoring/moveMultiModule/visibilityConflictInImport/conflicts.k2.txt @@ -1,2 +1 @@ - File internalSource.kt uses property internalTargetVal which will be inaccessible after move -Property a1.internalTargetVal, referenced in file internalSource.kt, will not be accessible from module A +File internalSource.kt uses property internalTargetVal which will be inaccessible after move diff --git a/plugins/kotlin/idea/tests/testData/refactoring/moveMultiModule/visibilityConflictInImport/conflicts.txt b/plugins/kotlin/idea/tests/testData/refactoring/moveMultiModule/visibilityConflictInImport/conflicts.txt index d83af2cf9eff..0a2f7672ba3f 100644 --- a/plugins/kotlin/idea/tests/testData/refactoring/moveMultiModule/visibilityConflictInImport/conflicts.txt +++ b/plugins/kotlin/idea/tests/testData/refactoring/moveMultiModule/visibilityConflictInImport/conflicts.txt @@ -1 +1 @@ -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 diff --git a/plugins/kotlin/refactorings/kotlin.refactorings.move.k2/src/org/jetbrains/kotlin/idea/k2/refactoring/move/processor/moveConflictUtil.kt b/plugins/kotlin/refactorings/kotlin.refactorings.move.k2/src/org/jetbrains/kotlin/idea/k2/refactoring/move/processor/moveConflictUtil.kt index 6284e9c04adc..303f4abb14a7 100644 --- a/plugins/kotlin/refactorings/kotlin.refactorings.move.k2/src/org/jetbrains/kotlin/idea/k2/refactoring/move/processor/moveConflictUtil.kt +++ b/plugins/kotlin/refactorings/kotlin.refactorings.move.k2/src/org/jetbrains/kotlin/idea/k2/refactoring/move/processor/moveConflictUtil.kt @@ -28,6 +28,7 @@ import org.jetbrains.kotlin.asJava.toLightElements import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.idea.base.resources.KotlinBundle import org.jetbrains.kotlin.idea.base.util.quoteIfNeeded +import org.jetbrains.kotlin.idea.codeinsight.utils.toVisibility import org.jetbrains.kotlin.idea.k2.refactoring.move.processor.K2MoveRenameUsageInfo.Companion.internalUsageInfo import org.jetbrains.kotlin.idea.refactoring.getContainer import org.jetbrains.kotlin.idea.references.mainReference @@ -36,6 +37,7 @@ import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType import org.jetbrains.kotlin.psi.psiUtil.containingClass import org.jetbrains.kotlin.psi.psiUtil.isAncestor +import org.jetbrains.kotlin.psi.psiUtil.visibilityModifierTypeOrDefault import org.jetbrains.kotlin.resolve.calls.util.getCalleeExpressionIfAny import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeAsciiOnly @@ -143,6 +145,8 @@ private fun MoveRenameUsageInfo.willNotBeMoved(declarationsToMove: Set { return this to KotlinBundle.message( "text.0.uses.1.which.will.be.inaccessible.after.move", @@ -329,6 +333,7 @@ private fun checkModuleDependencyConflictsForNonMovedUsages( tryFindConflict { val usageElement = usage.element ?: return@tryFindConflict null val referencedDeclaration = usage.upToDateReferencedElement as? KtNamedDeclaration ?: return@tryFindConflict null + if (referencedDeclaration.isInternal) return@tryFindConflict null val declarationCopy = containingCopyDecl(referencedDeclaration, oldToNewMap) ?: return@tryFindConflict null val targetModule = declarationCopy.containingModule() ?: return@tryFindConflict null val resolveScope = usageElement.resolveScope @@ -350,6 +355,7 @@ fun checkModuleDependencyConflictsForInternalUsages( tryFindConflict { val usageElement = usageInfo.element ?: return@tryFindConflict null val referencedDeclaration = usageInfo.upToDateReferencedElement as? PsiNamedElement ?: return@tryFindConflict null + if (referencedDeclaration is KtNamedDeclaration && referencedDeclaration.isInternal) return@tryFindConflict null analyzeCopy(refExprCopy, KaDanglingFileResolutionMode.PREFER_SELF) { if (refExprCopy.mainReference.resolveToSymbol() == null) { val module = refExprCopy.containingModule() ?: return@analyzeCopy null