[Analysis API] extract the data from the ShortenCommandImpl to the base class
^KT-58992
This commit is contained in:
committed by
Space Team
parent
fffc921d42
commit
95cf892eec
+12
-7
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.analysis.api.descriptors.components
|
||||
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.SmartPointerManager
|
||||
import com.intellij.psi.SmartPsiElementPointer
|
||||
import org.jetbrains.kotlin.analysis.api.components.KtReferenceShortener
|
||||
import org.jetbrains.kotlin.analysis.api.components.ShortenCommand
|
||||
@@ -15,13 +16,14 @@ import org.jetbrains.kotlin.analysis.api.descriptors.components.base.Fe10KtAnaly
|
||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassLikeSymbol
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtUserType
|
||||
|
||||
internal class KtFe10ReferenceShortener(
|
||||
override val analysisSession: KtFe10AnalysisSession
|
||||
override val analysisSession: KtFe10AnalysisSession,
|
||||
) : KtReferenceShortener(), Fe10KtAnalysisSessionComponent {
|
||||
override val token: KtLifetimeToken
|
||||
get() = analysisSession.token
|
||||
@@ -30,17 +32,20 @@ internal class KtFe10ReferenceShortener(
|
||||
file: KtFile,
|
||||
selection: TextRange,
|
||||
classShortenOption: (KtClassLikeSymbol) -> ShortenOption,
|
||||
callableShortenOption: (KtCallableSymbol) -> ShortenOption
|
||||
callableShortenOption: (KtCallableSymbol) -> ShortenOption,
|
||||
): ShortenCommand {
|
||||
// Compiler implementation does nothing.
|
||||
// Descriptor-based shortening is implemented on the IDE plugin side.
|
||||
val ktFilePointer = SmartPointerManager.createPointer(file)
|
||||
|
||||
return object : ShortenCommand {
|
||||
override val isEmpty: Boolean
|
||||
get() = true
|
||||
override val targetFile: SmartPsiElementPointer<KtFile> get() = ktFilePointer
|
||||
override val importsToAdd: List<FqName> get() = emptyList()
|
||||
override val starImportsToAdd: List<FqName> get() = emptyList()
|
||||
override val typesToShorten: List<SmartPsiElementPointer<KtUserType>> get() = emptyList()
|
||||
override val qualifiersToShorten: List<SmartPsiElementPointer<KtDotQualifiedExpression>> get() = emptyList()
|
||||
|
||||
override fun getTypesToShorten(): List<SmartPsiElementPointer<KtUserType>> = emptyList()
|
||||
|
||||
override fun getQualifiersToShorten(): List<SmartPsiElementPointer<KtDotQualifiedExpression>> = emptyList()
|
||||
override val isEmpty: Boolean get() = true
|
||||
|
||||
override fun invokeShortening(): List<KtElement> = emptyList()
|
||||
}
|
||||
|
||||
+5
-11
@@ -1060,11 +1060,11 @@ private class ElementsToShortenCollector(
|
||||
}
|
||||
|
||||
private class ShortenCommandImpl(
|
||||
private val targetFile: SmartPsiElementPointer<KtFile>,
|
||||
private val importsToAdd: List<FqName>,
|
||||
private val starImportsToAdd: List<FqName>,
|
||||
private val typesToShorten: List<SmartPsiElementPointer<KtUserType>>,
|
||||
private val qualifiersToShorten: List<SmartPsiElementPointer<KtDotQualifiedExpression>>,
|
||||
override val targetFile: SmartPsiElementPointer<KtFile>,
|
||||
override val importsToAdd: List<FqName>,
|
||||
override val starImportsToAdd: List<FqName>,
|
||||
override val typesToShorten: List<SmartPsiElementPointer<KtUserType>>,
|
||||
override val qualifiersToShorten: List<SmartPsiElementPointer<KtDotQualifiedExpression>>,
|
||||
) : ShortenCommand {
|
||||
|
||||
override fun invokeShortening(): List<KtElement> {
|
||||
@@ -1095,12 +1095,6 @@ private class ShortenCommandImpl(
|
||||
// }
|
||||
return shorteningResults
|
||||
}
|
||||
|
||||
override val isEmpty: Boolean get() = typesToShorten.isEmpty() && qualifiersToShorten.isEmpty()
|
||||
|
||||
override fun getTypesToShorten(): List<SmartPsiElementPointer<KtUserType>> = typesToShorten
|
||||
|
||||
override fun getQualifiersToShorten(): List<SmartPsiElementPointer<KtDotQualifiedExpression>> = qualifiersToShorten
|
||||
}
|
||||
|
||||
private fun KtUserType.hasFakeRootPrefix(): Boolean =
|
||||
|
||||
+2
-2
@@ -14,12 +14,12 @@ internal object ShorteningResultsRenderer {
|
||||
return
|
||||
}
|
||||
|
||||
shortening.getTypesToShorten().forEach { userType ->
|
||||
shortening.typesToShorten.forEach { userType ->
|
||||
userType.element?.text?.let {
|
||||
appendLine("[type] $it")
|
||||
}
|
||||
}
|
||||
shortening.getQualifiersToShorten().forEach { qualifier ->
|
||||
shortening.qualifiersToShorten.forEach { qualifier ->
|
||||
qualifier.element?.text?.let {
|
||||
appendLine("[qualifier] $it")
|
||||
}
|
||||
|
||||
+9
-6
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassLikeSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtEnumEntrySymbol
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
@@ -118,12 +119,14 @@ public interface KtReferenceShortenerMixIn : KtAnalysisSessionMixIn {
|
||||
}
|
||||
|
||||
public interface ShortenCommand {
|
||||
/**
|
||||
* Shortens target elements, adds necessary import, and returns a list of the shortened result elements.
|
||||
*/
|
||||
public fun invokeShortening(): List<KtElement>
|
||||
public val targetFile: SmartPsiElementPointer<KtFile>
|
||||
public val importsToAdd: List<FqName>
|
||||
public val starImportsToAdd: List<FqName>
|
||||
public val typesToShorten: List<SmartPsiElementPointer<KtUserType>>
|
||||
public val qualifiersToShorten: List<SmartPsiElementPointer<KtDotQualifiedExpression>>
|
||||
|
||||
public val isEmpty: Boolean
|
||||
public fun getTypesToShorten(): List<SmartPsiElementPointer<KtUserType>>
|
||||
public fun getQualifiersToShorten(): List<SmartPsiElementPointer<KtDotQualifiedExpression>>
|
||||
get() = typesToShorten.isEmpty() && qualifiersToShorten.isEmpty()
|
||||
|
||||
public fun invokeShortening(): List<KtElement>
|
||||
}
|
||||
Reference in New Issue
Block a user