FIR IDE: Add reference shortening service which works over FIR

This commit is contained in:
Roman Golyshev
2020-12-21 15:22:12 +03:00
committed by Space
parent 108395fcfe
commit c1130f2010
4 changed files with 128 additions and 0 deletions
@@ -45,6 +45,7 @@ abstract class KtAnalysisSession(final override val token: ValidityToken) : Vali
protected abstract val callResolver: KtCallResolver
protected abstract val completionCandidateChecker: KtCompletionCandidateChecker
protected abstract val symbolDeclarationOverridesProvider: KtSymbolDeclarationOverridesProvider
protected abstract val referenceShortener: KtReferenceShortener
@Suppress("LeakingThis")
@@ -177,4 +178,6 @@ abstract class KtAnalysisSession(final override val token: ValidityToken) : Vali
fun KtReturnExpression.getReturnTargetSymbol(): KtCallableSymbol? =
expressionHandlingComponent.getReturnExpressionTargetSymbol(this)
fun collectPossibleReferenceShortenings(file: KtFile, from: Int, to: Int) = referenceShortener.collectShortenings(file, from, to)
}
@@ -0,0 +1,31 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.idea.frontend.api.components
import com.intellij.openapi.application.ApplicationManager
import com.intellij.psi.SmartPsiElementPointer
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.KtUserType
abstract class KtReferenceShortener : KtAnalysisSessionComponent() {
abstract fun collectShortenings(file: KtFile, from: Int, to: Int): ShortenCommand
}
class ShortenCommand(
val targetFile: KtFile,
val importsToAdd: List<FqName>,
val typesToShorten: List<SmartPsiElementPointer<KtUserType>>
) {
fun invokeShortening() {
ApplicationManager.getApplication().assertWriteAccessAllowed()
for (typePointer in typesToShorten) {
val type = typePointer.element ?: continue
type.deleteQualifier()
}
}
}