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() {
override val branchConditionText: String = callableId.asFqNameForDebugInfo().toString()
override val branchConditionText: String = callableId.asSingleFqName().toString()
override fun toString(): String {
return callableId.callableName.identifier
@@ -54,7 +54,10 @@ data class CallableId(
fun asFqNameForDebugInfo(): FqName {
if (pathToLocal != null) return pathToLocal.child(callableName)
return asSingleFqName()
}
fun asSingleFqName(): FqName {
return classId?.asSingleFqName()?.child(callableName) ?: packageName.child(callableName)
}
@@ -172,7 +172,7 @@ fun FqName.quoteSegmentsIfNeeded(): String {
fun FqName.quoteIfNeeded() = FqName(quoteSegmentsIfNeeded())
fun CallableId.asFqNameWithRootPrefixIfNeeded() =
asFqNameForDebugInfo().withRootPrefixIfNeeded()
asSingleFqName().withRootPrefixIfNeeded()
fun FqName.withRootPrefixIfNeeded(targetElement: KtElement? = null) =
if (canAddRootPrefix() && targetElement?.canAddRootPrefix() != false)
@@ -370,7 +370,7 @@ private fun addCallableImportIfRequired(targetFile: KtFile, nameToImport: Callab
}
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 {
analyse(file) {
@@ -42,7 +42,7 @@ object FirIdeDeserializedDeclarationSourceProvider {
): PsiElement? {
val candidates = if (function.isTopLevel) {
KotlinTopLevelFunctionFqnNameIndex.getInstance().get(
function.symbol.callableId.asFqNameForDebugInfo().asString(),
function.symbol.callableId.asSingleFqName().asString(),
project,
function.scope(project)
).filter(KtNamedFunction::isCompiled)
@@ -58,7 +58,7 @@ object FirIdeDeserializedDeclarationSourceProvider {
private fun provideSourceForProperty(property: FirProperty, project: Project): PsiElement? {
val candidates = if (property.isTopLevel) {
KotlinTopLevelFunctionFqnNameIndex.getInstance().get(
property.symbol.callableId.asFqNameForDebugInfo().asString(),
property.symbol.callableId.asSingleFqName().asString(),
project,
property.scope(project)
)
@@ -24,7 +24,7 @@ fun addImportToFile(
allUnder: Boolean = false,
alias: Name? = null
) {
addImportToFile(project, file, callableId.asFqNameForDebugInfo(), allUnder, alias)
addImportToFile(project, file, callableId.asSingleFqName(), allUnder, alias)
}
/**
@@ -100,7 +100,7 @@ class AddWhenRemainingBranchesFix(
} else {
"is "
} + 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()")
if (elseBranch != null) {