Introduce CallableId.asSingleFqName and use it instead CallableId.asFqNameForDebugInfo

This commit is contained in:
Ilya Kirillov
2021-03-24 11:52:24 +01:00
parent 6f887896ff
commit 6e31ff4fb1
7 changed files with 10 additions and 7 deletions
@@ -51,7 +51,7 @@ sealed class WhenMissingCase {
} }
class EnumCheckIsMissing(val callableId: CallableId) : WhenMissingCase() { class EnumCheckIsMissing(val callableId: CallableId) : WhenMissingCase() {
override val branchConditionText: String = callableId.asFqNameForDebugInfo().toString() override val branchConditionText: String = callableId.asSingleFqName().toString()
override fun toString(): String { override fun toString(): String {
return callableId.callableName.identifier return callableId.callableName.identifier
@@ -54,7 +54,10 @@ data class CallableId(
fun asFqNameForDebugInfo(): FqName { fun asFqNameForDebugInfo(): FqName {
if (pathToLocal != null) return pathToLocal.child(callableName) if (pathToLocal != null) return pathToLocal.child(callableName)
return asSingleFqName()
}
fun asSingleFqName(): FqName {
return classId?.asSingleFqName()?.child(callableName) ?: packageName.child(callableName) return classId?.asSingleFqName()?.child(callableName) ?: packageName.child(callableName)
} }
@@ -172,7 +172,7 @@ fun FqName.quoteSegmentsIfNeeded(): String {
fun FqName.quoteIfNeeded() = FqName(quoteSegmentsIfNeeded()) fun FqName.quoteIfNeeded() = FqName(quoteSegmentsIfNeeded())
fun CallableId.asFqNameWithRootPrefixIfNeeded() = fun CallableId.asFqNameWithRootPrefixIfNeeded() =
asFqNameForDebugInfo().withRootPrefixIfNeeded() asSingleFqName().withRootPrefixIfNeeded()
fun FqName.withRootPrefixIfNeeded(targetElement: KtElement? = null) = fun FqName.withRootPrefixIfNeeded(targetElement: KtElement? = null) =
if (canAddRootPrefix() && targetElement?.canAddRootPrefix() != false) if (canAddRootPrefix() && targetElement?.canAddRootPrefix() != false)
@@ -370,7 +370,7 @@ private fun addCallableImportIfRequired(targetFile: KtFile, nameToImport: Callab
} }
private fun alreadyHasImport(file: KtFile, nameToImport: CallableId): Boolean { private fun alreadyHasImport(file: KtFile, nameToImport: CallableId): Boolean {
if (file.importDirectives.any { it.importPath?.fqName == nameToImport.asFqNameForDebugInfo() }) return true if (file.importDirectives.any { it.importPath?.fqName == nameToImport.asSingleFqName() }) return true
withAllowedResolve { withAllowedResolve {
analyse(file) { analyse(file) {
@@ -42,7 +42,7 @@ object FirIdeDeserializedDeclarationSourceProvider {
): PsiElement? { ): PsiElement? {
val candidates = if (function.isTopLevel) { val candidates = if (function.isTopLevel) {
KotlinTopLevelFunctionFqnNameIndex.getInstance().get( KotlinTopLevelFunctionFqnNameIndex.getInstance().get(
function.symbol.callableId.asFqNameForDebugInfo().asString(), function.symbol.callableId.asSingleFqName().asString(),
project, project,
function.scope(project) function.scope(project)
).filter(KtNamedFunction::isCompiled) ).filter(KtNamedFunction::isCompiled)
@@ -58,7 +58,7 @@ object FirIdeDeserializedDeclarationSourceProvider {
private fun provideSourceForProperty(property: FirProperty, project: Project): PsiElement? { private fun provideSourceForProperty(property: FirProperty, project: Project): PsiElement? {
val candidates = if (property.isTopLevel) { val candidates = if (property.isTopLevel) {
KotlinTopLevelFunctionFqnNameIndex.getInstance().get( KotlinTopLevelFunctionFqnNameIndex.getInstance().get(
property.symbol.callableId.asFqNameForDebugInfo().asString(), property.symbol.callableId.asSingleFqName().asString(),
project, project,
property.scope(project) property.scope(project)
) )
@@ -24,7 +24,7 @@ fun addImportToFile(
allUnder: Boolean = false, allUnder: Boolean = false,
alias: Name? = null alias: Name? = null
) { ) {
addImportToFile(project, file, callableId.asFqNameForDebugInfo(), allUnder, alias) addImportToFile(project, file, callableId.asSingleFqName(), allUnder, alias)
} }
/** /**
@@ -100,7 +100,7 @@ class AddWhenRemainingBranchesFix(
} else { } else {
"is " "is "
} + case.classId.asSingleFqName().quoteIfNeeded().asString() } + case.classId.asSingleFqName().quoteIfNeeded().asString()
is WhenMissingCase.EnumCheckIsMissing -> case.callableId.asFqNameForDebugInfo().quoteIfNeeded().asString() is WhenMissingCase.EnumCheckIsMissing -> case.callableId.asSingleFqName().quoteIfNeeded().asString()
} }
val entry = psiFactory.createWhenEntry("$branchConditionText -> TODO()") val entry = psiFactory.createWhenEntry("$branchConditionText -> TODO()")
if (elseBranch != null) { if (elseBranch != null) {