[Analysis API] Add KtReferenceMutateService...
and delegate renaming and rebinding to this new service for `KtReference`. In addition, CliKtFe10XXXReference are all removed because it seems they are not necessary because the IDE flavor differs only by handling renaming, which is moved to a separate service.
This commit is contained in:
committed by
Ilya Kirillov
parent
213e7154c2
commit
b5139c958b
+1
-8
@@ -9,7 +9,6 @@ import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.Fe10AnalysisFacade.AnalysisMode
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.KtFe10AnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.references.base.CliKtFe10Reference
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.references.base.KtFe10Reference
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.toKtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
@@ -17,7 +16,7 @@ import org.jetbrains.kotlin.idea.references.KtArrayAccessReference
|
||||
import org.jetbrains.kotlin.psi.KtArrayAccessExpression
|
||||
import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall
|
||||
|
||||
abstract class KtFe10ArrayAccessReference(expression: KtArrayAccessExpression) : KtArrayAccessReference(expression), KtFe10Reference {
|
||||
class KtFe10ArrayAccessReference(expression: KtArrayAccessExpression) : KtArrayAccessReference(expression), KtFe10Reference {
|
||||
override fun KtAnalysisSession.resolveToSymbols(): Collection<KtSymbol> {
|
||||
require(this is KtFe10AnalysisSession)
|
||||
|
||||
@@ -25,10 +24,4 @@ abstract class KtFe10ArrayAccessReference(expression: KtArrayAccessExpression) :
|
||||
val descriptor = expression.getResolvedCall(bindingContext)?.resultingDescriptor
|
||||
return listOfNotNull(descriptor?.toKtCallableSymbol(analysisContext))
|
||||
}
|
||||
}
|
||||
|
||||
class CliKtFe10ArrayAccessReference(expression: KtArrayAccessExpression) : KtFe10ArrayAccessReference(expression), CliKtFe10Reference {
|
||||
override fun handleElementRename(newElementName: String): PsiElement? {
|
||||
throw NotImplementedError("Renaming is not supported")
|
||||
}
|
||||
}
|
||||
+1
-6
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.analysis.api.descriptors.references
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.Fe10AnalysisFacade.AnalysisMode
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.KtFe10AnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.references.base.CliKtFe10Reference
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.references.base.KtFe10Reference
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.toKtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
@@ -16,7 +15,7 @@ import org.jetbrains.kotlin.idea.references.KtCollectionLiteralReference
|
||||
import org.jetbrains.kotlin.psi.KtCollectionLiteralExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
|
||||
abstract class KtFe10CollectionLiteralReference(
|
||||
class KtFe10CollectionLiteralReference(
|
||||
expression: KtCollectionLiteralExpression
|
||||
) : KtCollectionLiteralReference(expression), KtFe10Reference {
|
||||
override fun KtAnalysisSession.resolveToSymbols(): Collection<KtSymbol> {
|
||||
@@ -27,7 +26,3 @@ abstract class KtFe10CollectionLiteralReference(
|
||||
return listOfNotNull(descriptor?.toKtCallableSymbol(analysisContext))
|
||||
}
|
||||
}
|
||||
|
||||
internal class CliKtFe10CollectionLiteralReference(
|
||||
expression: KtCollectionLiteralExpression
|
||||
) : KtFe10CollectionLiteralReference(expression), CliKtFe10Reference
|
||||
+2
-7
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.analysis.api.descriptors.references
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.Fe10AnalysisFacade.AnalysisMode
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.KtFe10AnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.references.base.CliKtFe10Reference
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.references.base.KtFe10Reference
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.toKtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
@@ -16,7 +15,7 @@ import org.jetbrains.kotlin.idea.references.KtConstructorDelegationReference
|
||||
import org.jetbrains.kotlin.psi.KtConstructorDelegationReferenceExpression
|
||||
import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall
|
||||
|
||||
abstract class KtFe10ConstructorDelegationReference(
|
||||
class KtFe10ConstructorDelegationReference(
|
||||
expression: KtConstructorDelegationReferenceExpression
|
||||
) : KtConstructorDelegationReference(expression), KtFe10Reference {
|
||||
override fun KtAnalysisSession.resolveToSymbols(): Collection<KtSymbol> {
|
||||
@@ -26,8 +25,4 @@ abstract class KtFe10ConstructorDelegationReference(
|
||||
val descriptor = expression.getResolvedCall(bindingContext)?.resultingDescriptor
|
||||
return listOfNotNull(descriptor?.toKtCallableSymbol(analysisContext))
|
||||
}
|
||||
}
|
||||
|
||||
internal class CliKtFe10ConstructorDelegationReference(
|
||||
expression: KtConstructorDelegationReferenceExpression
|
||||
) : KtFe10ConstructorDelegationReference(expression), CliKtFe10Reference
|
||||
}
|
||||
+1
-10
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.analysis.api.descriptors.references
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.Fe10AnalysisFacade.AnalysisMode
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.KtFe10AnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.references.base.CliKtFe10Reference
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.references.base.KtFe10Reference
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.toKtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
@@ -16,7 +15,7 @@ import org.jetbrains.kotlin.idea.references.KtDestructuringDeclarationReference
|
||||
import org.jetbrains.kotlin.psi.KtDestructuringDeclarationEntry
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
|
||||
abstract class KtFe10DestructuringDeclarationEntry(
|
||||
class KtFe10DestructuringDeclarationEntry(
|
||||
element: KtDestructuringDeclarationEntry
|
||||
) : KtDestructuringDeclarationReference(element), KtFe10Reference {
|
||||
override fun KtAnalysisSession.resolveToSymbols(): Collection<KtSymbol> {
|
||||
@@ -27,11 +26,3 @@ abstract class KtFe10DestructuringDeclarationEntry(
|
||||
return listOfNotNull(descriptor?.toKtCallableSymbol(analysisContext))
|
||||
}
|
||||
}
|
||||
|
||||
internal class CliKtFe10DestructuringDeclarationEntry(
|
||||
element: KtDestructuringDeclarationEntry
|
||||
) : KtFe10DestructuringDeclarationEntry(element), CliKtFe10Reference {
|
||||
override fun canRename(): Boolean {
|
||||
return false
|
||||
}
|
||||
}
|
||||
+2
-5
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.analysis.api.descriptors.references
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.KtFe10AnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.references.base.CliKtFe10Reference
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.references.base.KtFe10Reference
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.toKtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
@@ -15,7 +14,7 @@ import org.jetbrains.kotlin.idea.references.KtForLoopInReference
|
||||
import org.jetbrains.kotlin.psi.KtForExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
|
||||
abstract class KtFe10ForLoopInReference(expression: KtForExpression) : KtForLoopInReference(expression), KtFe10Reference {
|
||||
class KtFe10ForLoopInReference(expression: KtForExpression) : KtForLoopInReference(expression), KtFe10Reference {
|
||||
override fun KtAnalysisSession.resolveToSymbols(): Collection<KtSymbol> {
|
||||
check(this is KtFe10AnalysisSession)
|
||||
|
||||
@@ -28,6 +27,4 @@ abstract class KtFe10ForLoopInReference(expression: KtForExpression) : KtForLoop
|
||||
BindingContext.LOOP_RANGE_NEXT_RESOLVED_CALL
|
||||
).mapNotNull { slice -> bindingContext[slice, loopRange]?.resultingDescriptor?.toKtCallableSymbol(analysisContext) }
|
||||
}
|
||||
}
|
||||
|
||||
internal class CliKtFe10ForLoopInReference(expression: KtForExpression) : KtFe10ForLoopInReference(expression), CliKtFe10Reference
|
||||
}
|
||||
+1
-10
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.analysis.api.descriptors.references
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.Fe10AnalysisFacade.AnalysisMode
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.KtFe10AnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.references.base.CliKtFe10Reference
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.references.base.KtFe10Reference
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.toKtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
@@ -20,7 +19,7 @@ import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.util.getCall
|
||||
import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall
|
||||
|
||||
abstract class KtFe10InvokeFunctionReference(expression: KtCallExpression) : KtInvokeFunctionReference(expression), KtFe10Reference {
|
||||
class KtFe10InvokeFunctionReference(expression: KtCallExpression) : KtInvokeFunctionReference(expression), KtFe10Reference {
|
||||
override fun KtAnalysisSession.resolveToSymbols(): Collection<KtSymbol> {
|
||||
require(this is KtFe10AnalysisSession)
|
||||
|
||||
@@ -38,11 +37,3 @@ abstract class KtFe10InvokeFunctionReference(expression: KtCallExpression) : KtI
|
||||
return descriptors.mapNotNull { it.toKtCallableSymbol(analysisContext) }
|
||||
}
|
||||
}
|
||||
|
||||
internal class CliKtFe10InvokeFunctionReference(
|
||||
expression: KtCallExpression
|
||||
) : KtFe10InvokeFunctionReference(expression), CliKtFe10Reference {
|
||||
override fun doRenameImplicitConventionalCall(newName: String?): KtExpression {
|
||||
throw NotImplementedError("Renaming is not supported")
|
||||
}
|
||||
}
|
||||
|
||||
+2
-7
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.analysis.api.descriptors.references
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.KtFe10AnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.references.base.CliKtFe10Reference
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.references.base.KtFe10Reference
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.toKtCallableSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
@@ -17,7 +16,7 @@ import org.jetbrains.kotlin.psi.KtProperty
|
||||
import org.jetbrains.kotlin.psi.KtPropertyDelegate
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
|
||||
abstract class KtFe10PropertyDelegationMethodsReference(
|
||||
class KtFe10PropertyDelegationMethodsReference(
|
||||
expression: KtPropertyDelegate
|
||||
) : KtPropertyDelegationMethodsReference(expression), KtFe10Reference {
|
||||
override fun KtAnalysisSession.resolveToSymbols(): Collection<KtSymbol> {
|
||||
@@ -41,8 +40,4 @@ abstract class KtFe10PropertyDelegationMethodsReference(
|
||||
|
||||
return emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
internal class CliKtFe10PropertyDelegationMethodsReference(
|
||||
expression: KtPropertyDelegate
|
||||
) : KtFe10PropertyDelegationMethodsReference(expression), CliKtFe10Reference
|
||||
}
|
||||
+2
-22
@@ -9,18 +9,16 @@ import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.Fe10AnalysisFacade.AnalysisMode
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.KtFe10AnalysisSession
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.references.base.CliKtFe10Reference
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.references.base.KtFe10Reference
|
||||
import org.jetbrains.kotlin.analysis.api.descriptors.symbols.descriptorBased.base.toKtSymbol
|
||||
import org.jetbrains.kotlin.analysis.api.symbols.KtSymbol
|
||||
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.KtImportAlias
|
||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall
|
||||
|
||||
abstract class KtFe10SimpleNameReference(expression: KtSimpleNameExpression) : KtSimpleNameReference(expression), KtFe10Reference {
|
||||
class KtFe10SimpleNameReference(expression: KtSimpleNameExpression) : KtSimpleNameReference(expression), KtFe10Reference {
|
||||
override fun KtAnalysisSession.resolveToSymbols(): Collection<KtSymbol> {
|
||||
require(this is KtFe10AnalysisSession)
|
||||
|
||||
@@ -31,26 +29,8 @@ abstract class KtFe10SimpleNameReference(expression: KtSimpleNameExpression) : K
|
||||
|
||||
return listOfNotNull(descriptor?.toKtSymbol(analysisContext))
|
||||
}
|
||||
}
|
||||
|
||||
internal class CliKtFe10SimpleNameReference(
|
||||
expression: KtSimpleNameExpression
|
||||
) : KtFe10SimpleNameReference(expression), CliKtFe10Reference {
|
||||
override fun isReferenceToViaExtension(element: PsiElement): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun handleElementRename(newElementName: String): PsiElement? {
|
||||
throw NotImplementedError("Renaming is not supported")
|
||||
}
|
||||
|
||||
override fun bindToElement(element: PsiElement, shorteningMode: ShorteningMode): PsiElement {
|
||||
throw NotImplementedError("Binding is not supported")
|
||||
}
|
||||
|
||||
override fun bindToFqName(fqName: FqName, shorteningMode: ShorteningMode, targetElement: PsiElement?): PsiElement {
|
||||
throw NotImplementedError("Binding is not supported")
|
||||
}
|
||||
override fun isReferenceToViaExtension(element: PsiElement): Boolean = false
|
||||
|
||||
override fun getImportAlias(): KtImportAlias? {
|
||||
return null
|
||||
|
||||
+8
-8
@@ -12,14 +12,14 @@ import org.jetbrains.kotlin.idea.references.KotlinReferenceProviderContributor
|
||||
class KtFe10KotlinReferenceProviderContributor : KotlinReferenceProviderContributor {
|
||||
override fun registerReferenceProviders(registrar: KotlinPsiReferenceRegistrar) {
|
||||
with(registrar) {
|
||||
registerProvider(factory = ::CliKtFe10SimpleNameReference)
|
||||
registerProvider(factory = ::CliKtFe10ForLoopInReference)
|
||||
registerProvider(factory = ::CliKtFe10InvokeFunctionReference)
|
||||
registerProvider(factory = ::CliKtFe10PropertyDelegationMethodsReference)
|
||||
registerProvider(factory = ::CliKtFe10DestructuringDeclarationEntry)
|
||||
registerProvider(factory = ::CliKtFe10ArrayAccessReference)
|
||||
registerProvider(factory = ::CliKtFe10ConstructorDelegationReference)
|
||||
registerProvider(factory = ::CliKtFe10CollectionLiteralReference)
|
||||
registerProvider(factory = ::KtFe10SimpleNameReference)
|
||||
registerProvider(factory = ::KtFe10ForLoopInReference)
|
||||
registerProvider(factory = ::KtFe10InvokeFunctionReference)
|
||||
registerProvider(factory = ::KtFe10PropertyDelegationMethodsReference)
|
||||
registerProvider(factory = ::KtFe10DestructuringDeclarationEntry)
|
||||
registerProvider(factory = ::KtFe10ArrayAccessReference)
|
||||
registerProvider(factory = ::KtFe10ConstructorDelegationReference)
|
||||
registerProvider(factory = ::KtFe10CollectionLiteralReference)
|
||||
}
|
||||
}
|
||||
}
|
||||
-5
@@ -21,11 +21,6 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.source.getPsi
|
||||
|
||||
internal interface CliKtFe10Reference : KtReference {
|
||||
override val resolver: ResolveCache.PolyVariantResolver<KtReference>
|
||||
get() = KtFe10PolyVariantResolver
|
||||
}
|
||||
|
||||
object KtFe10PolyVariantResolver : ResolveCache.PolyVariantResolver<KtReference> {
|
||||
@OptIn(KtAllowAnalysisOnEdt::class)
|
||||
override fun resolve(reference: KtReference, incompleteCode: Boolean): Array<ResolveResult> {
|
||||
|
||||
+5
-1
@@ -5,7 +5,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.analysis.api.descriptors.references.base
|
||||
|
||||
import com.intellij.psi.impl.source.resolve.ResolveCache
|
||||
import org.jetbrains.kotlin.analysis.api.KtSymbolBasedReference
|
||||
import org.jetbrains.kotlin.idea.references.KtReference
|
||||
|
||||
interface KtFe10Reference : KtReference, KtSymbolBasedReference
|
||||
interface KtFe10Reference : KtReference, KtSymbolBasedReference {
|
||||
override val resolver: ResolveCache.PolyVariantResolver<KtReference>
|
||||
get() = KtFe10PolyVariantResolver
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user