KT-62676 [AA] Rename ShortenOption -> ShortenStrategy
`Option` is going to refer to more global settings of the reference shortener (like shortening `this` or `Companion` references)
This commit is contained in:
+3
-3
@@ -10,7 +10,7 @@ import com.intellij.psi.SmartPointerManager
|
|||||||
import com.intellij.psi.SmartPsiElementPointer
|
import com.intellij.psi.SmartPsiElementPointer
|
||||||
import org.jetbrains.kotlin.analysis.api.components.KtReferenceShortener
|
import org.jetbrains.kotlin.analysis.api.components.KtReferenceShortener
|
||||||
import org.jetbrains.kotlin.analysis.api.components.ShortenCommand
|
import org.jetbrains.kotlin.analysis.api.components.ShortenCommand
|
||||||
import org.jetbrains.kotlin.analysis.api.components.ShortenOption
|
import org.jetbrains.kotlin.analysis.api.components.ShortenStrategy
|
||||||
import org.jetbrains.kotlin.analysis.api.descriptors.KtFe10AnalysisSession
|
import org.jetbrains.kotlin.analysis.api.descriptors.KtFe10AnalysisSession
|
||||||
import org.jetbrains.kotlin.analysis.api.descriptors.components.base.Fe10KtAnalysisSessionComponent
|
import org.jetbrains.kotlin.analysis.api.descriptors.components.base.Fe10KtAnalysisSessionComponent
|
||||||
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
import org.jetbrains.kotlin.analysis.api.lifetime.KtLifetimeToken
|
||||||
@@ -31,8 +31,8 @@ internal class KtFe10ReferenceShortener(
|
|||||||
override fun collectShortenings(
|
override fun collectShortenings(
|
||||||
file: KtFile,
|
file: KtFile,
|
||||||
selection: TextRange,
|
selection: TextRange,
|
||||||
classShortenOption: (KtClassLikeSymbol) -> ShortenOption,
|
classShortenStrategy: (KtClassLikeSymbol) -> ShortenStrategy,
|
||||||
callableShortenOption: (KtCallableSymbol) -> ShortenOption,
|
callableShortenStrategy: (KtCallableSymbol) -> ShortenStrategy,
|
||||||
): ShortenCommand {
|
): ShortenCommand {
|
||||||
// Compiler implementation does nothing.
|
// Compiler implementation does nothing.
|
||||||
// Descriptor-based shortening is implemented on the IDE plugin side.
|
// Descriptor-based shortening is implemented on the IDE plugin side.
|
||||||
|
|||||||
+39
-39
@@ -12,7 +12,7 @@ import com.intellij.psi.SmartPsiElementPointer
|
|||||||
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
import org.jetbrains.kotlin.KtFakeSourceElementKind
|
||||||
import org.jetbrains.kotlin.analysis.api.components.KtReferenceShortener
|
import org.jetbrains.kotlin.analysis.api.components.KtReferenceShortener
|
||||||
import org.jetbrains.kotlin.analysis.api.components.ShortenCommand
|
import org.jetbrains.kotlin.analysis.api.components.ShortenCommand
|
||||||
import org.jetbrains.kotlin.analysis.api.components.ShortenOption
|
import org.jetbrains.kotlin.analysis.api.components.ShortenStrategy
|
||||||
import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
|
||||||
import org.jetbrains.kotlin.analysis.api.fir.components.ElementsToShortenCollector.PartialOrderOfScope.Companion.toPartialOrder
|
import org.jetbrains.kotlin.analysis.api.fir.components.ElementsToShortenCollector.PartialOrderOfScope.Companion.toPartialOrder
|
||||||
import org.jetbrains.kotlin.analysis.api.fir.isImplicitDispatchReceiver
|
import org.jetbrains.kotlin.analysis.api.fir.isImplicitDispatchReceiver
|
||||||
@@ -78,8 +78,8 @@ internal class KtFirReferenceShortener(
|
|||||||
override fun collectShortenings(
|
override fun collectShortenings(
|
||||||
file: KtFile,
|
file: KtFile,
|
||||||
selection: TextRange,
|
selection: TextRange,
|
||||||
classShortenOption: (KtClassLikeSymbol) -> ShortenOption,
|
classShortenStrategy: (KtClassLikeSymbol) -> ShortenStrategy,
|
||||||
callableShortenOption: (KtCallableSymbol) -> ShortenOption
|
callableShortenStrategy: (KtCallableSymbol) -> ShortenStrategy
|
||||||
): ShortenCommand {
|
): ShortenCommand {
|
||||||
require(!file.isCompiled) { "No sense to collect references for shortening in compiled file $file" }
|
require(!file.isCompiled) { "No sense to collect references for shortening in compiled file $file" }
|
||||||
|
|
||||||
@@ -103,8 +103,8 @@ internal class KtFirReferenceShortener(
|
|||||||
context,
|
context,
|
||||||
towerContext,
|
towerContext,
|
||||||
selection,
|
selection,
|
||||||
classShortenOption = { classShortenOption(buildSymbol(it) as KtClassLikeSymbol) },
|
classShortenStrategy = { classShortenStrategy(buildSymbol(it) as KtClassLikeSymbol) },
|
||||||
callableShortenOption = { callableShortenOption(buildSymbol(it) as KtCallableSymbol) },
|
callableShortenStrategy = { callableShortenStrategy(buildSymbol(it) as KtCallableSymbol) },
|
||||||
firResolveSession,
|
firResolveSession,
|
||||||
)
|
)
|
||||||
firDeclaration.accept(collector)
|
firDeclaration.accept(collector)
|
||||||
@@ -118,11 +118,11 @@ internal class KtFirReferenceShortener(
|
|||||||
analysisSession,
|
analysisSession,
|
||||||
selection,
|
selection,
|
||||||
additionalImports,
|
additionalImports,
|
||||||
classShortenOption = {
|
classShortenStrategy = {
|
||||||
minOf(classShortenOption(buildSymbol(it) as KtClassLikeSymbol), ShortenOption.SHORTEN_IF_ALREADY_IMPORTED)
|
minOf(classShortenStrategy(buildSymbol(it) as KtClassLikeSymbol), ShortenStrategy.SHORTEN_IF_ALREADY_IMPORTED)
|
||||||
},
|
},
|
||||||
callableShortenOption = {
|
callableShortenStrategy = {
|
||||||
minOf(callableShortenOption(buildSymbol(it) as KtCallableSymbol), ShortenOption.SHORTEN_IF_ALREADY_IMPORTED)
|
minOf(callableShortenStrategy(buildSymbol(it) as KtCallableSymbol), ShortenStrategy.SHORTEN_IF_ALREADY_IMPORTED)
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
kDocCollector.visitElement(declarationToVisit)
|
kDocCollector.visitElement(declarationToVisit)
|
||||||
@@ -242,9 +242,9 @@ private enum class ImportKind {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun fromShortenOption(option: ShortenOption): ImportKind? = when (option) {
|
fun fromShortenOption(option: ShortenStrategy): ImportKind? = when (option) {
|
||||||
ShortenOption.SHORTEN_AND_IMPORT -> EXPLICIT
|
ShortenStrategy.SHORTEN_AND_IMPORT -> EXPLICIT
|
||||||
ShortenOption.SHORTEN_AND_STAR_IMPORT -> STAR
|
ShortenStrategy.SHORTEN_AND_STAR_IMPORT -> STAR
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -405,8 +405,8 @@ private class ElementsToShortenCollector(
|
|||||||
private val shorteningContext: FirShorteningContext,
|
private val shorteningContext: FirShorteningContext,
|
||||||
private val towerContextProvider: FirTowerContextProvider,
|
private val towerContextProvider: FirTowerContextProvider,
|
||||||
private val selection: TextRange,
|
private val selection: TextRange,
|
||||||
private val classShortenOption: (FirClassLikeSymbol<*>) -> ShortenOption,
|
private val classShortenStrategy: (FirClassLikeSymbol<*>) -> ShortenStrategy,
|
||||||
private val callableShortenOption: (FirCallableSymbol<*>) -> ShortenOption,
|
private val callableShortenStrategy: (FirCallableSymbol<*>) -> ShortenStrategy,
|
||||||
private val firResolveSession: LLFirResolveSession,
|
private val firResolveSession: LLFirResolveSession,
|
||||||
) : FirVisitorVoid() {
|
) : FirVisitorVoid() {
|
||||||
val typesToShorten: MutableList<ShortenType> = mutableListOf()
|
val typesToShorten: MutableList<ShortenType> = mutableListOf()
|
||||||
@@ -777,8 +777,8 @@ private class ElementsToShortenCollector(
|
|||||||
): ElementToShorten? {
|
): ElementToShorten? {
|
||||||
for ((classId, element) in allClassIds.zip(allQualifiedElements)) {
|
for ((classId, element) in allClassIds.zip(allQualifiedElements)) {
|
||||||
val classSymbol = shorteningContext.toClassSymbol(classId) ?: return null
|
val classSymbol = shorteningContext.toClassSymbol(classId) ?: return null
|
||||||
val option = classShortenOption(classSymbol)
|
val option = classShortenStrategy(classSymbol)
|
||||||
if (option == ShortenOption.DO_NOT_SHORTEN) continue
|
if (option == ShortenStrategy.DO_NOT_SHORTEN) continue
|
||||||
|
|
||||||
// If its parent has a type parameter, we do not shorten it ATM because it will lose its type parameter. See KTIJ-26072
|
// If its parent has a type parameter, we do not shorten it ATM because it will lose its type parameter. See KTIJ-26072
|
||||||
if (classSymbol.hasTypeParameterFromParent()) continue
|
if (classSymbol.hasTypeParameterFromParent()) continue
|
||||||
@@ -786,9 +786,9 @@ private class ElementsToShortenCollector(
|
|||||||
if (shortenClassifierIfAlreadyImported(classId, element, classSymbol, positionScopes)) {
|
if (shortenClassifierIfAlreadyImported(classId, element, classSymbol, positionScopes)) {
|
||||||
return createElementToShorten(element, null, false)
|
return createElementToShorten(element, null, false)
|
||||||
}
|
}
|
||||||
if (option == ShortenOption.SHORTEN_IF_ALREADY_IMPORTED) continue
|
if (option == ShortenStrategy.SHORTEN_IF_ALREADY_IMPORTED) continue
|
||||||
|
|
||||||
val importAllInParent = option == ShortenOption.SHORTEN_AND_STAR_IMPORT
|
val importAllInParent = option == ShortenStrategy.SHORTEN_AND_STAR_IMPORT
|
||||||
if (importAffectsUsagesOfClassesWithSameName(classId, element.containingKtFile, importAllInParent)) continue
|
if (importAffectsUsagesOfClassesWithSameName(classId, element.containingKtFile, importAllInParent)) continue
|
||||||
|
|
||||||
// Find class with the same name that's already available in this file.
|
// Find class with the same name that's already available in this file.
|
||||||
@@ -1032,8 +1032,8 @@ private class ElementsToShortenCollector(
|
|||||||
|
|
||||||
val propertySymbol = firPropertyAccess.referencedSymbol ?: return
|
val propertySymbol = firPropertyAccess.referencedSymbol ?: return
|
||||||
|
|
||||||
val option = callableShortenOption(propertySymbol)
|
val option = callableShortenStrategy(propertySymbol)
|
||||||
if (option == ShortenOption.DO_NOT_SHORTEN) return
|
if (option == ShortenStrategy.DO_NOT_SHORTEN) return
|
||||||
|
|
||||||
val scopes = shorteningContext.findScopesAtPosition(qualifiedProperty, getNamesToImport(), towerContextProvider) ?: return
|
val scopes = shorteningContext.findScopesAtPosition(qualifiedProperty, getNamesToImport(), towerContextProvider) ?: return
|
||||||
val availableCallables = shorteningContext.findPropertiesInScopes(scopes, propertySymbol.name)
|
val availableCallables = shorteningContext.findPropertiesInScopes(scopes, propertySymbol.name)
|
||||||
@@ -1041,7 +1041,7 @@ private class ElementsToShortenCollector(
|
|||||||
addElementToShorten(ShortenQualifier(qualifiedProperty))
|
addElementToShorten(ShortenQualifier(qualifiedProperty))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (option == ShortenOption.SHORTEN_IF_ALREADY_IMPORTED) return
|
if (option == ShortenStrategy.SHORTEN_IF_ALREADY_IMPORTED) return
|
||||||
|
|
||||||
processCallableQualifiedAccess(
|
processCallableQualifiedAccess(
|
||||||
propertySymbol,
|
propertySymbol,
|
||||||
@@ -1078,8 +1078,8 @@ private class ElementsToShortenCollector(
|
|||||||
val calleeReference = functionCall.calleeReference
|
val calleeReference = functionCall.calleeReference
|
||||||
val calledSymbol = findUnambiguousReferencedCallableId(calleeReference) ?: return
|
val calledSymbol = findUnambiguousReferencedCallableId(calleeReference) ?: return
|
||||||
|
|
||||||
val option = callableShortenOption(calledSymbol)
|
val option = callableShortenStrategy(calledSymbol)
|
||||||
if (option == ShortenOption.DO_NOT_SHORTEN) return
|
if (option == ShortenStrategy.DO_NOT_SHORTEN) return
|
||||||
|
|
||||||
val scopes = shorteningContext.findScopesAtPosition(callExpression, getNamesToImport(), towerContextProvider) ?: return
|
val scopes = shorteningContext.findScopesAtPosition(callExpression, getNamesToImport(), towerContextProvider) ?: return
|
||||||
val availableCallables = shorteningContext.findFunctionsInScopes(scopes, calledSymbol.name)
|
val availableCallables = shorteningContext.findFunctionsInScopes(scopes, calledSymbol.name)
|
||||||
@@ -1087,7 +1087,7 @@ private class ElementsToShortenCollector(
|
|||||||
addElementToShorten(ShortenQualifier(qualifiedCallExpression))
|
addElementToShorten(ShortenQualifier(qualifiedCallExpression))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (option == ShortenOption.SHORTEN_IF_ALREADY_IMPORTED) return
|
if (option == ShortenStrategy.SHORTEN_IF_ALREADY_IMPORTED) return
|
||||||
|
|
||||||
processCallableQualifiedAccess(
|
processCallableQualifiedAccess(
|
||||||
calledSymbol,
|
calledSymbol,
|
||||||
@@ -1099,11 +1099,11 @@ private class ElementsToShortenCollector(
|
|||||||
|
|
||||||
private fun processCallableQualifiedAccess(
|
private fun processCallableQualifiedAccess(
|
||||||
calledSymbol: FirCallableSymbol<*>,
|
calledSymbol: FirCallableSymbol<*>,
|
||||||
option: ShortenOption,
|
option: ShortenStrategy,
|
||||||
qualifiedCallExpression: KtDotQualifiedExpression,
|
qualifiedCallExpression: KtDotQualifiedExpression,
|
||||||
availableCallables: List<AvailableSymbol<FirCallableSymbol<*>>>,
|
availableCallables: List<AvailableSymbol<FirCallableSymbol<*>>>,
|
||||||
) {
|
) {
|
||||||
if (option == ShortenOption.DO_NOT_SHORTEN) return
|
if (option == ShortenStrategy.DO_NOT_SHORTEN) return
|
||||||
|
|
||||||
val nameToImport = shorteningContext.convertToImportableName(calledSymbol)
|
val nameToImport = shorteningContext.convertToImportableName(calledSymbol)
|
||||||
|
|
||||||
@@ -1116,15 +1116,15 @@ private class ElementsToShortenCollector(
|
|||||||
otherCallables.all { importKind.hasHigherPriorityThan(it.importKind) } -> {
|
otherCallables.all { importKind.hasHigherPriorityThan(it.importKind) } -> {
|
||||||
when {
|
when {
|
||||||
matchedCallables.isEmpty() -> {
|
matchedCallables.isEmpty() -> {
|
||||||
if (nameToImport == null || option == ShortenOption.SHORTEN_IF_ALREADY_IMPORTED) return
|
if (nameToImport == null || option == ShortenStrategy.SHORTEN_IF_ALREADY_IMPORTED) return
|
||||||
ShortenQualifier(
|
ShortenQualifier(
|
||||||
qualifiedCallExpression,
|
qualifiedCallExpression,
|
||||||
nameToImport,
|
nameToImport,
|
||||||
importAllInParent = option == ShortenOption.SHORTEN_AND_STAR_IMPORT
|
importAllInParent = option == ShortenStrategy.SHORTEN_AND_STAR_IMPORT
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// Respect caller's request to star import this symbol.
|
// Respect caller's request to star import this symbol.
|
||||||
matchedCallables.any { it.importKind == ImportKind.EXPLICIT } && option == ShortenOption.SHORTEN_AND_STAR_IMPORT ->
|
matchedCallables.any { it.importKind == ImportKind.EXPLICIT } && option == ShortenStrategy.SHORTEN_AND_STAR_IMPORT ->
|
||||||
ShortenQualifier(qualifiedCallExpression, nameToImport, importAllInParent = true)
|
ShortenQualifier(qualifiedCallExpression, nameToImport, importAllInParent = true)
|
||||||
else -> ShortenQualifier(qualifiedCallExpression)
|
else -> ShortenQualifier(qualifiedCallExpression)
|
||||||
}
|
}
|
||||||
@@ -1285,8 +1285,8 @@ private class KDocQualifiersToShortenCollector(
|
|||||||
private val analysisSession: KtFirAnalysisSession,
|
private val analysisSession: KtFirAnalysisSession,
|
||||||
private val selection: TextRange,
|
private val selection: TextRange,
|
||||||
private val additionalImports: AdditionalImports,
|
private val additionalImports: AdditionalImports,
|
||||||
private val classShortenOption: (FirClassLikeSymbol<*>) -> ShortenOption,
|
private val classShortenStrategy: (FirClassLikeSymbol<*>) -> ShortenStrategy,
|
||||||
private val callableShortenOption: (FirCallableSymbol<*>) -> ShortenOption,
|
private val callableShortenStrategy: (FirCallableSymbol<*>) -> ShortenStrategy,
|
||||||
) : KtVisitorVoid() {
|
) : KtVisitorVoid() {
|
||||||
val kDocQualifiersToShorten: MutableList<ShortenKDocQualifier> = mutableListOf()
|
val kDocQualifiersToShorten: MutableList<ShortenKDocQualifier> = mutableListOf()
|
||||||
override fun visitElement(element: PsiElement) {
|
override fun visitElement(element: PsiElement) {
|
||||||
@@ -1302,8 +1302,8 @@ private class KDocQualifiersToShortenCollector(
|
|||||||
val shouldShortenKDocQualifier = shouldShortenKDocQualifier(
|
val shouldShortenKDocQualifier = shouldShortenKDocQualifier(
|
||||||
element,
|
element,
|
||||||
additionalImports,
|
additionalImports,
|
||||||
classShortenOption = { classShortenOption(it) },
|
classShortenStrategy = { classShortenStrategy(it) },
|
||||||
callableShortenOption = { callableShortenOption(it) },
|
callableShortenStrategy = { callableShortenStrategy(it) },
|
||||||
)
|
)
|
||||||
if (shouldShortenKDocQualifier) {
|
if (shouldShortenKDocQualifier) {
|
||||||
addKDocQualifierToShorten(element)
|
addKDocQualifierToShorten(element)
|
||||||
@@ -1319,8 +1319,8 @@ private class KDocQualifiersToShortenCollector(
|
|||||||
private fun shouldShortenKDocQualifier(
|
private fun shouldShortenKDocQualifier(
|
||||||
kDocName: KDocName,
|
kDocName: KDocName,
|
||||||
additionalImports: AdditionalImports,
|
additionalImports: AdditionalImports,
|
||||||
classShortenOption: (FirClassLikeSymbol<*>) -> ShortenOption,
|
classShortenStrategy: (FirClassLikeSymbol<*>) -> ShortenStrategy,
|
||||||
callableShortenOption: (FirCallableSymbol<*>) -> ShortenOption,
|
callableShortenStrategy: (FirCallableSymbol<*>) -> ShortenStrategy,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val fqName = kDocName.getQualifiedNameAsFqName().dropFakeRootPrefixIfPresent()
|
val fqName = kDocName.getQualifiedNameAsFqName().dropFakeRootPrefixIfPresent()
|
||||||
|
|
||||||
@@ -1335,18 +1335,18 @@ private class KDocQualifiersToShortenCollector(
|
|||||||
}
|
}
|
||||||
|
|
||||||
resolvedSymbols.firstIsInstanceOrNull<KtCallableSymbol>()?.firSymbol?.let { availableCallable ->
|
resolvedSymbols.firstIsInstanceOrNull<KtCallableSymbol>()?.firSymbol?.let { availableCallable ->
|
||||||
return canShorten(fqName, availableCallable.callableId.asSingleFqName()) { callableShortenOption(availableCallable) }
|
return canShorten(fqName, availableCallable.callableId.asSingleFqName()) { callableShortenStrategy(availableCallable) }
|
||||||
}
|
}
|
||||||
|
|
||||||
resolvedSymbols.firstIsInstanceOrNull<KtClassLikeSymbol>()?.firSymbol?.let { availableClassifier ->
|
resolvedSymbols.firstIsInstanceOrNull<KtClassLikeSymbol>()?.firSymbol?.let { availableClassifier ->
|
||||||
return canShorten(fqName, availableClassifier.classId.asSingleFqName()) { classShortenOption(availableClassifier) }
|
return canShorten(fqName, availableClassifier.classId.asSingleFqName()) { classShortenStrategy(availableClassifier) }
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun canShorten(fqNameToShorten: FqName, fqNameOfAvailableSymbol: FqName, getShortenOption: () -> ShortenOption): Boolean =
|
private fun canShorten(fqNameToShorten: FqName, fqNameOfAvailableSymbol: FqName, getShortenStrategy: () -> ShortenStrategy): Boolean =
|
||||||
fqNameToShorten == fqNameOfAvailableSymbol && getShortenOption() != ShortenOption.DO_NOT_SHORTEN
|
fqNameToShorten == fqNameOfAvailableSymbol && getShortenStrategy() != ShortenStrategy.DO_NOT_SHORTEN
|
||||||
|
|
||||||
private fun FqName.isInNewImports(additionalImports: AdditionalImports): Boolean =
|
private fun FqName.isInNewImports(additionalImports: AdditionalImports): Boolean =
|
||||||
this in additionalImports.simpleImports || this.parent() in additionalImports.starImports
|
this in additionalImports.simpleImports || this.parent() in additionalImports.starImports
|
||||||
|
|||||||
+2
-2
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.analysis.api.impl.base.test.cases.references
|
package org.jetbrains.kotlin.analysis.api.impl.base.test.cases.references
|
||||||
|
|
||||||
import org.jetbrains.kotlin.analysis.api.components.ShortenOption
|
import org.jetbrains.kotlin.analysis.api.components.ShortenStrategy
|
||||||
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.references.ShorteningResultsRenderer.renderShorteningResults
|
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.references.ShorteningResultsRenderer.renderShorteningResults
|
||||||
import org.jetbrains.kotlin.analysis.test.framework.base.AbstractAnalysisApiBasedSingleModuleTest
|
import org.jetbrains.kotlin.analysis.test.framework.base.AbstractAnalysisApiBasedSingleModuleTest
|
||||||
import org.jetbrains.kotlin.analysis.test.framework.utils.executeOnPooledThreadInReadAction
|
import org.jetbrains.kotlin.analysis.test.framework.utils.executeOnPooledThreadInReadAction
|
||||||
@@ -20,7 +20,7 @@ abstract class AbstractReferenceShortenerForWholeFileTest : AbstractAnalysisApiB
|
|||||||
|
|
||||||
val shortenings = executeOnPooledThreadInReadAction {
|
val shortenings = executeOnPooledThreadInReadAction {
|
||||||
analyseForTest(file) {
|
analyseForTest(file) {
|
||||||
ShortenOption.values().map { option ->
|
ShortenStrategy.values().map { option ->
|
||||||
val shorteningsForOption = collectPossibleReferenceShortenings(file, file.textRange, { option }, { option })
|
val shorteningsForOption = collectPossibleReferenceShortenings(file, file.textRange, { option }, { option })
|
||||||
|
|
||||||
Pair(option.name, shorteningsForOption)
|
Pair(option.name, shorteningsForOption)
|
||||||
|
|||||||
+2
-2
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.analysis.api.impl.base.test.cases.references
|
package org.jetbrains.kotlin.analysis.api.impl.base.test.cases.references
|
||||||
|
|
||||||
import org.jetbrains.kotlin.analysis.api.components.ShortenOption
|
import org.jetbrains.kotlin.analysis.api.components.ShortenStrategy
|
||||||
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.references.ShorteningResultsRenderer.renderShorteningResults
|
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.references.ShorteningResultsRenderer.renderShorteningResults
|
||||||
import org.jetbrains.kotlin.analysis.test.framework.base.AbstractAnalysisApiBasedSingleModuleTest
|
import org.jetbrains.kotlin.analysis.test.framework.base.AbstractAnalysisApiBasedSingleModuleTest
|
||||||
import org.jetbrains.kotlin.analysis.test.framework.services.expressionMarkerProvider
|
import org.jetbrains.kotlin.analysis.test.framework.services.expressionMarkerProvider
|
||||||
@@ -27,7 +27,7 @@ abstract class AbstractReferenceShortenerTest : AbstractAnalysisApiBasedSingleMo
|
|||||||
|
|
||||||
val shortenings = executeOnPooledThreadInReadAction {
|
val shortenings = executeOnPooledThreadInReadAction {
|
||||||
analyseForTest(element) {
|
analyseForTest(element) {
|
||||||
ShortenOption.values().map { option ->
|
ShortenStrategy.values().map { option ->
|
||||||
Pair(option.name, collectPossibleReferenceShorteningsInElement(element, { option }, { option }))
|
Pair(option.name, collectPossibleReferenceShorteningsInElement(element, { option }, { option }))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-15
@@ -7,8 +7,8 @@ package org.jetbrains.kotlin.analysis.api.components
|
|||||||
|
|
||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
import com.intellij.psi.SmartPsiElementPointer
|
import com.intellij.psi.SmartPsiElementPointer
|
||||||
import org.jetbrains.kotlin.analysis.api.components.ShortenOption.Companion.defaultCallableShortenOption
|
import org.jetbrains.kotlin.analysis.api.components.ShortenStrategy.Companion.defaultCallableShortenStrategy
|
||||||
import org.jetbrains.kotlin.analysis.api.components.ShortenOption.Companion.defaultClassShortenOption
|
import org.jetbrains.kotlin.analysis.api.components.ShortenStrategy.Companion.defaultClassShortenStrategy
|
||||||
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
|
||||||
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
|
||||||
import org.jetbrains.kotlin.analysis.api.symbols.KtClassLikeSymbol
|
import org.jetbrains.kotlin.analysis.api.symbols.KtClassLikeSymbol
|
||||||
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.psi.KtElement
|
|||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import org.jetbrains.kotlin.psi.KtUserType
|
import org.jetbrains.kotlin.psi.KtUserType
|
||||||
|
|
||||||
public enum class ShortenOption {
|
public enum class ShortenStrategy {
|
||||||
/** Skip shortening references to this symbol. */
|
/** Skip shortening references to this symbol. */
|
||||||
DO_NOT_SHORTEN,
|
DO_NOT_SHORTEN,
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ public enum class ShortenOption {
|
|||||||
SHORTEN_AND_STAR_IMPORT;
|
SHORTEN_AND_STAR_IMPORT;
|
||||||
|
|
||||||
public companion object {
|
public companion object {
|
||||||
public val defaultClassShortenOption: (KtClassLikeSymbol) -> ShortenOption = {
|
public val defaultClassShortenStrategy: (KtClassLikeSymbol) -> ShortenStrategy = {
|
||||||
if (it.classIdIfNonLocal?.isNestedClass == true) {
|
if (it.classIdIfNonLocal?.isNestedClass == true) {
|
||||||
SHORTEN_IF_ALREADY_IMPORTED
|
SHORTEN_IF_ALREADY_IMPORTED
|
||||||
} else {
|
} else {
|
||||||
@@ -67,7 +67,7 @@ public enum class ShortenOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public val defaultCallableShortenOption: (KtCallableSymbol) -> ShortenOption = { symbol ->
|
public val defaultCallableShortenStrategy: (KtCallableSymbol) -> ShortenStrategy = { symbol ->
|
||||||
if (symbol is KtEnumEntrySymbol) DO_NOT_SHORTEN
|
if (symbol is KtEnumEntrySymbol) DO_NOT_SHORTEN
|
||||||
else SHORTEN_AND_IMPORT
|
else SHORTEN_AND_IMPORT
|
||||||
}
|
}
|
||||||
@@ -78,8 +78,8 @@ public abstract class KtReferenceShortener : KtAnalysisSessionComponent() {
|
|||||||
public abstract fun collectShortenings(
|
public abstract fun collectShortenings(
|
||||||
file: KtFile,
|
file: KtFile,
|
||||||
selection: TextRange,
|
selection: TextRange,
|
||||||
classShortenOption: (KtClassLikeSymbol) -> ShortenOption,
|
classShortenStrategy: (KtClassLikeSymbol) -> ShortenStrategy,
|
||||||
callableShortenOption: (KtCallableSymbol) -> ShortenOption
|
callableShortenStrategy: (KtCallableSymbol) -> ShortenStrategy
|
||||||
): ShortenCommand
|
): ShortenCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,15 +97,15 @@ public interface KtReferenceShortenerMixIn : KtAnalysisSessionMixIn {
|
|||||||
public fun collectPossibleReferenceShortenings(
|
public fun collectPossibleReferenceShortenings(
|
||||||
file: KtFile,
|
file: KtFile,
|
||||||
selection: TextRange = file.textRange,
|
selection: TextRange = file.textRange,
|
||||||
classShortenOption: (KtClassLikeSymbol) -> ShortenOption = defaultClassShortenOption,
|
classShortenStrategy: (KtClassLikeSymbol) -> ShortenStrategy = defaultClassShortenStrategy,
|
||||||
callableShortenOption: (KtCallableSymbol) -> ShortenOption = defaultCallableShortenOption
|
callableShortenStrategy: (KtCallableSymbol) -> ShortenStrategy = defaultCallableShortenStrategy
|
||||||
): ShortenCommand =
|
): ShortenCommand =
|
||||||
withValidityAssertion {
|
withValidityAssertion {
|
||||||
analysisSession.referenceShortener.collectShortenings(
|
analysisSession.referenceShortener.collectShortenings(
|
||||||
file,
|
file,
|
||||||
selection,
|
selection,
|
||||||
classShortenOption,
|
classShortenStrategy,
|
||||||
callableShortenOption
|
callableShortenStrategy
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,15 +120,15 @@ public interface KtReferenceShortenerMixIn : KtAnalysisSessionMixIn {
|
|||||||
*/
|
*/
|
||||||
public fun collectPossibleReferenceShorteningsInElement(
|
public fun collectPossibleReferenceShorteningsInElement(
|
||||||
element: KtElement,
|
element: KtElement,
|
||||||
classShortenOption: (KtClassLikeSymbol) -> ShortenOption = defaultClassShortenOption,
|
classShortenStrategy: (KtClassLikeSymbol) -> ShortenStrategy = defaultClassShortenStrategy,
|
||||||
callableShortenOption: (KtCallableSymbol) -> ShortenOption = defaultCallableShortenOption
|
callableShortenStrategy: (KtCallableSymbol) -> ShortenStrategy = defaultCallableShortenStrategy
|
||||||
): ShortenCommand =
|
): ShortenCommand =
|
||||||
withValidityAssertion {
|
withValidityAssertion {
|
||||||
analysisSession.referenceShortener.collectShortenings(
|
analysisSession.referenceShortener.collectShortenings(
|
||||||
element.containingKtFile,
|
element.containingKtFile,
|
||||||
element.textRange,
|
element.textRange,
|
||||||
classShortenOption,
|
classShortenStrategy,
|
||||||
callableShortenOption
|
callableShortenStrategy
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user