Move KtReference interface to psi module
This commit is contained in:
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2021 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.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 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.references
|
||||||
|
|
||||||
|
import com.intellij.openapi.components.ServiceManager
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import com.intellij.psi.PsiReference
|
||||||
|
import com.intellij.util.containers.MultiMap
|
||||||
|
import org.jetbrains.kotlin.psi.KtElement
|
||||||
|
|
||||||
|
interface KotlinPsiReferenceProvider {
|
||||||
|
fun getReferencesByElement(element: PsiElement): Array<PsiReference>
|
||||||
|
}
|
||||||
|
|
||||||
|
interface KotlinReferenceProviderContributor {
|
||||||
|
fun registerReferenceProviders(registrar: KotlinPsiReferenceRegistrar)
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun getInstance(): KotlinReferenceProviderContributor =
|
||||||
|
ServiceManager.getService(KotlinReferenceProviderContributor::class.java)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class KotlinPsiReferenceRegistrar {
|
||||||
|
val providers: MultiMap<Class<out PsiElement>, KotlinPsiReferenceProvider> = MultiMap.create()
|
||||||
|
|
||||||
|
inline fun <reified E : KtElement> registerProvider(crossinline factory: (E) -> PsiReference?) {
|
||||||
|
registerMultiProvider<E> { element ->
|
||||||
|
factory(element)?.let { reference -> arrayOf(reference) } ?: PsiReference.EMPTY_ARRAY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <reified E : KtElement> registerMultiProvider(crossinline factory: (E) -> Array<PsiReference>) {
|
||||||
|
val provider: KotlinPsiReferenceProvider = object : KotlinPsiReferenceProvider {
|
||||||
|
override fun getReferencesByElement(element: PsiElement): Array<PsiReference> {
|
||||||
|
return factory(element as E)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
registerMultiProvider(E::class.java, provider)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun registerMultiProvider(klass: Class<out PsiElement>, provider: KotlinPsiReferenceProvider) {
|
||||||
|
providers.putValue(klass, provider)
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-3
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2021 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.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.idea.references
|
|||||||
import com.google.common.collect.Lists
|
import com.google.common.collect.Lists
|
||||||
import com.intellij.psi.MultiRangeReference
|
import com.intellij.psi.MultiRangeReference
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.idea.core.replaced
|
|
||||||
import org.jetbrains.kotlin.lexer.KtToken
|
import org.jetbrains.kotlin.lexer.KtToken
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
@@ -48,7 +47,7 @@ abstract class KtArrayAccessReference(
|
|||||||
appendExpressions(arrayAccessExpression.indexExpressions, ",")
|
appendExpressions(arrayAccessExpression.indexExpressions, ",")
|
||||||
appendFixedText(")")
|
appendFixedText(")")
|
||||||
}
|
}
|
||||||
val fullCallExpression = arrayAccessExpression.replaced(replacement)
|
val fullCallExpression = arrayAccessExpression.replace(replacement) as KtExpression
|
||||||
val callExpression = fullCallExpression.getPossiblyQualifiedCallExpression()
|
val callExpression = fullCallExpression.getPossiblyQualifiedCallExpression()
|
||||||
if (callExpression != null && canMoveLambdaOutsideParentheses(callExpression)) {
|
if (callExpression != null && canMoveLambdaOutsideParentheses(callExpression)) {
|
||||||
moveFunctionLiteralOutsideParentheses(callExpression)
|
moveFunctionLiteralOutsideParentheses(callExpression)
|
||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2021 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.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ import com.intellij.openapi.util.TextRange
|
|||||||
import com.intellij.psi.MultiRangeReference
|
import com.intellij.psi.MultiRangeReference
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi.KtCollectionLiteralExpression
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.resolve.ArrayFqNames
|
import org.jetbrains.kotlin.resolve.ArrayFqNames
|
||||||
|
|
||||||
abstract class KtCollectionLiteralReference(expression: KtCollectionLiteralExpression) :
|
abstract class KtCollectionLiteralReference(expression: KtCollectionLiteralExpression) :
|
||||||
+3
-2
@@ -1,13 +1,14 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2021 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.
|
* 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.references
|
package org.jetbrains.kotlin.idea.references
|
||||||
|
|
||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi.KtConstructorDelegationReferenceExpression
|
import org.jetbrains.kotlin.psi.*
|
||||||
|
|
||||||
abstract class KtConstructorDelegationReference(
|
abstract class KtConstructorDelegationReference(
|
||||||
expression: KtConstructorDelegationReferenceExpression
|
expression: KtConstructorDelegationReferenceExpression
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2021 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.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2021 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.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.idea.references
|
|||||||
|
|
||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi.KtForExpression
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||||
|
|
||||||
abstract class KtForLoopInReference(element: KtForExpression) : KtMultiReference<KtForExpression>(element) {
|
abstract class KtForLoopInReference(element: KtForExpression) : KtMultiReference<KtForExpression>(element) {
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2021 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.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2021 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.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2021 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.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
+1
-16
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2021 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.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -8,31 +8,16 @@ package org.jetbrains.kotlin.idea.references
|
|||||||
import com.intellij.openapi.extensions.Extensions
|
import com.intellij.openapi.extensions.Extensions
|
||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.PsiReference
|
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.plugin.references.SimpleNameReferenceExtension
|
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypeAndBranch
|
import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypeAndBranch
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||||
|
|
||||||
abstract class KtSimpleNameReference(expression: KtSimpleNameExpression) : KtSimpleReference<KtSimpleNameExpression>(expression) {
|
abstract class KtSimpleNameReference(expression: KtSimpleNameExpression) : KtSimpleReference<KtSimpleNameExpression>(expression) {
|
||||||
override fun isReferenceTo(element: PsiElement): Boolean {
|
|
||||||
if (!doCanBeReferenceTo(element)) return false
|
|
||||||
|
|
||||||
|
|
||||||
@Suppress("DEPRECATION") // compatibility with 191
|
|
||||||
for (extension in Extensions.getArea(element.project).getExtensionPoint(SimpleNameReferenceExtension.EP_NAME).extensions) {
|
|
||||||
if (extension.isReferenceTo(this, element)) return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return isReferenceToWithoutExtensionChecking(element)
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract fun doCanBeReferenceTo(candidateTarget: PsiElement): Boolean
|
protected abstract fun doCanBeReferenceTo(candidateTarget: PsiElement): Boolean
|
||||||
protected abstract fun isReferenceToWithoutExtensionChecking(candidateTarget: PsiElement): Boolean
|
|
||||||
|
|
||||||
override fun getRangeInElement(): TextRange {
|
override fun getRangeInElement(): TextRange {
|
||||||
val element = element.getReferencedNameElement()
|
val element = element.getReferencedNameElement()
|
||||||
+2
-9
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2021 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.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -15,16 +15,9 @@ abstract class SyntheticPropertyAccessorReference(
|
|||||||
expression: KtNameReferenceExpression,
|
expression: KtNameReferenceExpression,
|
||||||
val getter: Boolean
|
val getter: Boolean
|
||||||
) : KtSimpleReference<KtNameReferenceExpression>(expression) {
|
) : KtSimpleReference<KtNameReferenceExpression>(expression) {
|
||||||
|
|
||||||
override fun isReferenceTo(element: PsiElement): Boolean {
|
|
||||||
if (element !is PsiMethod || !isAccessorName(element.name)) return false
|
|
||||||
if (!getter && expression.readWriteAccess(true) == ReferenceAccess.READ) return false
|
|
||||||
return additionalIsReferenceToChecker(element)
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract fun additionalIsReferenceToChecker(element: PsiElement): Boolean
|
protected abstract fun additionalIsReferenceToChecker(element: PsiElement): Boolean
|
||||||
|
|
||||||
private fun isAccessorName(name: String): Boolean {
|
protected fun isAccessorName(name: String): Boolean {
|
||||||
if (getter) {
|
if (getter) {
|
||||||
return name.startsWith("get") || name.startsWith("is")
|
return name.startsWith("get") || name.startsWith("is")
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2021 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.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
+1
-3
@@ -42,12 +42,10 @@ import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
|||||||
class KtSimpleNameReferenceDescriptorsImpl(
|
class KtSimpleNameReferenceDescriptorsImpl(
|
||||||
expression: KtSimpleNameExpression
|
expression: KtSimpleNameExpression
|
||||||
) : KtSimpleNameReference(expression), KtDescriptorsBasedReference {
|
) : KtSimpleNameReference(expression), KtDescriptorsBasedReference {
|
||||||
|
|
||||||
override fun doCanBeReferenceTo(candidateTarget: PsiElement): Boolean =
|
override fun doCanBeReferenceTo(candidateTarget: PsiElement): Boolean =
|
||||||
canBeReferenceTo(candidateTarget)
|
canBeReferenceTo(candidateTarget)
|
||||||
|
|
||||||
override fun isReferenceToWithoutExtensionChecking(candidateTarget: PsiElement): Boolean =
|
|
||||||
matchesTarget(candidateTarget)
|
|
||||||
|
|
||||||
override fun getTargetDescriptors(context: BindingContext): Collection<DeclarationDescriptor> {
|
override fun getTargetDescriptors(context: BindingContext): Collection<DeclarationDescriptor> {
|
||||||
return SmartList<DeclarationDescriptor>().apply {
|
return SmartList<DeclarationDescriptor>().apply {
|
||||||
// Replace Java property with its accessor(s)
|
// Replace Java property with its accessor(s)
|
||||||
|
|||||||
+7
-2
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.idea.references
|
package org.jetbrains.kotlin.idea.references
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
|
import com.intellij.psi.PsiMethod
|
||||||
import com.intellij.util.SmartList
|
import com.intellij.util.SmartList
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
@@ -29,8 +30,12 @@ class SyntheticPropertyAccessorReferenceDescriptorImpl(
|
|||||||
expression: KtNameReferenceExpression,
|
expression: KtNameReferenceExpression,
|
||||||
getter: Boolean
|
getter: Boolean
|
||||||
) : SyntheticPropertyAccessorReference(expression, getter), KtDescriptorsBasedReference {
|
) : SyntheticPropertyAccessorReference(expression, getter), KtDescriptorsBasedReference {
|
||||||
override fun isReferenceTo(element: PsiElement): Boolean =
|
|
||||||
super<SyntheticPropertyAccessorReference>.isReferenceTo(element)
|
override fun isReferenceTo(element: PsiElement): Boolean {
|
||||||
|
if (element !is PsiMethod || !isAccessorName(element.name)) return false
|
||||||
|
if (!getter && expression.readWriteAccess(true) == ReferenceAccess.READ) return false
|
||||||
|
return additionalIsReferenceToChecker(element)
|
||||||
|
}
|
||||||
|
|
||||||
override fun additionalIsReferenceToChecker(element: PsiElement): Boolean = matchesTarget(element)
|
override fun additionalIsReferenceToChecker(element: PsiElement): Boolean = matchesTarget(element)
|
||||||
|
|
||||||
|
|||||||
-2
@@ -7,9 +7,7 @@ package org.jetbrains.kotlin.idea.frontend.api.components
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.idea.frontend.api.KtSymbolBasedReference
|
import org.jetbrains.kotlin.idea.frontend.api.KtSymbolBasedReference
|
||||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbol
|
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbol
|
||||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.pointers.KtSymbolPointer
|
|
||||||
import org.jetbrains.kotlin.idea.references.KtReference
|
import org.jetbrains.kotlin.idea.references.KtReference
|
||||||
import org.jetbrains.kotlin.idea.references.KtSimpleReference
|
|
||||||
|
|
||||||
interface KtReferenceResolveMixIn : KtAnalysisSessionMixIn {
|
interface KtReferenceResolveMixIn : KtAnalysisSessionMixIn {
|
||||||
fun KtReference.resolveToSymbols(): Collection<KtSymbol> {
|
fun KtReference.resolveToSymbols(): Collection<KtSymbol> {
|
||||||
|
|||||||
+3
-2
@@ -47,8 +47,9 @@ internal class KtFirSimpleNameReference(
|
|||||||
return true // TODO
|
return true // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun isReferenceToWithoutExtensionChecking(candidateTarget: PsiElement): Boolean {
|
|
||||||
return resolve() == candidateTarget //todo
|
override fun isReferenceTo(element: PsiElement): Boolean {
|
||||||
|
return resolve() == element //todo
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handleElementRename(newElementName: String): PsiElement? {
|
override fun handleElementRename(newElementName: String): PsiElement? {
|
||||||
|
|||||||
-40
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.references
|
package org.jetbrains.kotlin.idea.references
|
||||||
|
|
||||||
import com.intellij.openapi.components.service
|
|
||||||
import com.intellij.openapi.project.IndexNotReadyException
|
import com.intellij.openapi.project.IndexNotReadyException
|
||||||
import com.intellij.psi.ContributedReferenceHost
|
import com.intellij.psi.ContributedReferenceHost
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
@@ -16,49 +15,10 @@ import com.intellij.psi.util.CachedValueProvider
|
|||||||
import com.intellij.psi.util.CachedValuesManager
|
import com.intellij.psi.util.CachedValuesManager
|
||||||
import com.intellij.psi.util.PsiModificationTracker
|
import com.intellij.psi.util.PsiModificationTracker
|
||||||
import com.intellij.util.containers.ConcurrentFactoryMap
|
import com.intellij.util.containers.ConcurrentFactoryMap
|
||||||
import com.intellij.util.containers.ContainerUtil
|
|
||||||
import com.intellij.util.containers.MultiMap
|
import com.intellij.util.containers.MultiMap
|
||||||
import org.jetbrains.kotlin.psi.KotlinReferenceProvidersService
|
import org.jetbrains.kotlin.psi.KotlinReferenceProvidersService
|
||||||
import org.jetbrains.kotlin.psi.KtElement
|
|
||||||
import org.jetbrains.kotlin.utils.SmartList
|
import org.jetbrains.kotlin.utils.SmartList
|
||||||
|
|
||||||
interface KotlinPsiReferenceProvider {
|
|
||||||
fun getReferencesByElement(element: PsiElement): Array<PsiReference>
|
|
||||||
}
|
|
||||||
|
|
||||||
interface KotlinReferenceProviderContributor {
|
|
||||||
fun registerReferenceProviders(registrar: KotlinPsiReferenceRegistrar)
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
fun getInstance(): KotlinReferenceProviderContributor = service()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class KotlinPsiReferenceRegistrar {
|
|
||||||
val providers: MultiMap<Class<out PsiElement>, KotlinPsiReferenceProvider> = MultiMap.create()
|
|
||||||
|
|
||||||
inline fun <reified E : KtElement> registerProvider(crossinline factory: (E) -> PsiReference?) {
|
|
||||||
registerMultiProvider<E> { element ->
|
|
||||||
factory(element)?.let { reference -> arrayOf(reference) } ?: PsiReference.EMPTY_ARRAY
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fun <reified E : KtElement> registerMultiProvider(crossinline factory: (E) -> Array<PsiReference>) {
|
|
||||||
val provider: KotlinPsiReferenceProvider = object : KotlinPsiReferenceProvider {
|
|
||||||
override fun getReferencesByElement(element: PsiElement): Array<PsiReference> {
|
|
||||||
return factory(element as E)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
registerMultiProvider(E::class.java, provider)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun registerMultiProvider(klass: Class<out PsiElement>, provider: KotlinPsiReferenceProvider) {
|
|
||||||
providers.putValue(klass, provider)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class KtIdeReferenceProviderService : KotlinReferenceProvidersService() {
|
class KtIdeReferenceProviderService : KotlinReferenceProvidersService() {
|
||||||
private val originalProvidersBinding: MultiMap<Class<out PsiElement>, KotlinPsiReferenceProvider>
|
private val originalProvidersBinding: MultiMap<Class<out PsiElement>, KotlinPsiReferenceProvider>
|
||||||
private val providersBindingCache: Map<Class<out PsiElement>, List<KotlinPsiReferenceProvider>>
|
private val providersBindingCache: Map<Class<out PsiElement>, List<KotlinPsiReferenceProvider>>
|
||||||
|
|||||||
Reference in New Issue
Block a user