mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
[kotlin] Find internal usages for KDoc references
#KTIJ-30858 Fixed GitOrigin-RevId: 06936e333d9bb60fbf5156213d8873a503550e8e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b461a07bd9
commit
c160009477
@@ -179,6 +179,11 @@ public abstract class MoveTestGenerated extends AbstractMoveTest {
|
||||
runTest("testData/refactoring/moveFile/kotlin/moveClassWithExtensionFunction/moveClassWithExtensionFunction.test");
|
||||
}
|
||||
|
||||
@TestMetadata("kotlin/moveDetachedComment/moveDetachedComment.test")
|
||||
public void testKotlin_moveDetachedComment_MoveDetachedComment() throws Exception {
|
||||
runTest("testData/refactoring/moveFile/kotlin/moveDetachedComment/moveDetachedComment.test");
|
||||
}
|
||||
|
||||
@TestMetadata("kotlin/moveFileAndDirWithJavaFileReferringToPackageFragementWithUnmatchedDir/moveFileAndDirWithJavaFileReferringToPackageFragementWithUnmatchedDir.test")
|
||||
public void testKotlin_moveFileAndDirWithJavaFileReferringToPackageFragementWithUnmatchedDir_MoveFileAndDirWithJavaFileReferringToPackageFragementWithUnmatchedDir() throws Exception {
|
||||
runTest("testData/refactoring/moveFile/kotlin/moveFileAndDirWithJavaFileReferringToPackageFragementWithUnmatchedDir/moveFileAndDirWithJavaFileReferringToPackageFragementWithUnmatchedDir.test");
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
package a
|
||||
|
||||
class Other { }
|
||||
@@ -0,0 +1,10 @@
|
||||
package b
|
||||
|
||||
/**
|
||||
* [a.Other]
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Test { }
|
||||
@@ -0,0 +1,3 @@
|
||||
package a
|
||||
|
||||
class Other { }
|
||||
@@ -0,0 +1,10 @@
|
||||
package a
|
||||
|
||||
/**
|
||||
* [Other]
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Test { }
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"mainFile": "a/main.kt",
|
||||
"type": "MOVE_FILES",
|
||||
"targetPackage": "b",
|
||||
"withRuntime": "true",
|
||||
"enabledInK1": "false",
|
||||
"enabledInK2": "true"
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.idea.references.KtConstructorDelegationReference
|
||||
import org.jetbrains.kotlin.idea.references.KtReference
|
||||
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
|
||||
import org.jetbrains.kotlin.idea.references.mainReference
|
||||
import org.jetbrains.kotlin.kdoc.psi.impl.KDocName
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.forEachDescendantOfType
|
||||
@@ -228,13 +229,18 @@ sealed class K2MoveRenameUsageInfo(
|
||||
* @see restoreInternalUsages
|
||||
* @see K2MoveRenameUsageInfo.Source.refresh
|
||||
*/
|
||||
internal var KtReferenceExpression.internalUsageInfo: K2MoveRenameUsageInfo? by CopyablePsiUserDataProperty(Key.create("INTERNAL_USAGE_INFO"))
|
||||
internal var KtElement.internalUsageInfo: K2MoveRenameUsageInfo? by CopyablePsiUserDataProperty(Key.create("INTERNAL_USAGE_INFO"))
|
||||
|
||||
/**
|
||||
* Finds any usage inside [containing]. We need these usages because when moving [containing] to a different package references
|
||||
* that where previously imported by default might now require an explicit import.
|
||||
*/
|
||||
fun markInternalUsages(containing: KtElement) {
|
||||
containing.forEachDescendantOfType<KDocName> { name ->
|
||||
val reference = name.mainReference
|
||||
val resolved = reference.resolve() as? PsiNamedElement ?: return@forEachDescendantOfType
|
||||
name.internalUsageInfo = Source(name, reference, resolved, true)
|
||||
}
|
||||
containing.forEachDescendantOfType<KtReferenceExpression> { refExpr ->
|
||||
if (refExpr is KtEnumEntrySuperclassReferenceExpression) return@forEachDescendantOfType
|
||||
if (refExpr.parent is KtSuperExpression || refExpr.parent is KtThisExpression) return@forEachDescendantOfType
|
||||
@@ -310,18 +316,19 @@ sealed class K2MoveRenameUsageInfo(
|
||||
* @see internalUsageInfo
|
||||
*/
|
||||
private fun restoreInternalUsages(
|
||||
containingElement: KtElement,
|
||||
containingElem: KtElement,
|
||||
oldToNewMap: Map<PsiElement, PsiElement>,
|
||||
fromCopy: Boolean
|
||||
): List<UsageInfo> {
|
||||
return containingElement.collectDescendantsOfType<KtReferenceExpression>().mapNotNull { refExpr ->
|
||||
val usageInfo = refExpr.internalUsageInfo
|
||||
if (!fromCopy && usageInfo?.element != null) return@mapNotNull usageInfo
|
||||
val referencedElement = (usageInfo as? Source)?.referencedElement ?: return@mapNotNull null
|
||||
val newReferencedElement = oldToNewMap[referencedElement] ?: referencedElement
|
||||
if (!newReferencedElement.isValid || newReferencedElement !is PsiNamedElement) return@mapNotNull null
|
||||
usageInfo.refresh(refExpr, newReferencedElement)
|
||||
}
|
||||
return (containingElem.collectDescendantsOfType<KDocName>() + containingElem.collectDescendantsOfType<KtReferenceExpression>())
|
||||
.mapNotNull { refExpr ->
|
||||
val usageInfo = refExpr.internalUsageInfo
|
||||
if (!fromCopy && usageInfo?.element != null) return@mapNotNull usageInfo
|
||||
val referencedElement = (usageInfo as? Source)?.referencedElement ?: return@mapNotNull null
|
||||
val newReferencedElement = oldToNewMap[referencedElement] ?: referencedElement
|
||||
if (!newReferencedElement.isValid || newReferencedElement !is PsiNamedElement) return@mapNotNull null
|
||||
usageInfo.refresh(refExpr, newReferencedElement)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -75,6 +75,11 @@ public class K2MoveFileOrDirectoriesTestGenerated extends AbstractK2MoveFileOrDi
|
||||
runTest("../../idea/tests/testData/refactoring/moveFile/kotlin/moveClassWithExtensionFunction/moveClassWithExtensionFunction.test");
|
||||
}
|
||||
|
||||
@TestMetadata("kotlin/moveDetachedComment/moveDetachedComment.test")
|
||||
public void testKotlin_moveDetachedComment_MoveDetachedComment() throws Exception {
|
||||
runTest("../../idea/tests/testData/refactoring/moveFile/kotlin/moveDetachedComment/moveDetachedComment.test");
|
||||
}
|
||||
|
||||
@TestMetadata("kotlin/moveFileAndDirWithJavaFileReferringToPackageFragementWithUnmatchedDir/moveFileAndDirWithJavaFileReferringToPackageFragementWithUnmatchedDir.test")
|
||||
public void testKotlin_moveFileAndDirWithJavaFileReferringToPackageFragementWithUnmatchedDir_MoveFileAndDirWithJavaFileReferringToPackageFragementWithUnmatchedDir() throws Exception {
|
||||
runTest("../../idea/tests/testData/refactoring/moveFile/kotlin/moveFileAndDirWithJavaFileReferringToPackageFragementWithUnmatchedDir/moveFileAndDirWithJavaFileReferringToPackageFragementWithUnmatchedDir.test");
|
||||
|
||||
Reference in New Issue
Block a user