Quick search of getValue/setValue operator usages
This commit is contained in:
+2
@@ -23,10 +23,12 @@ import com.intellij.psi.search.SearchScope
|
|||||||
import com.intellij.util.Processor
|
import com.intellij.util.Processor
|
||||||
import org.jetbrains.kotlin.KtNodeTypes
|
import org.jetbrains.kotlin.KtNodeTypes
|
||||||
import org.jetbrains.kotlin.idea.references.KtForLoopInReference
|
import org.jetbrains.kotlin.idea.references.KtForLoopInReference
|
||||||
|
import org.jetbrains.kotlin.idea.references.KtPropertyDelegationMethodsReference
|
||||||
import org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinReferencesSearchOptions
|
import org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinReferencesSearchOptions
|
||||||
import org.jetbrains.kotlin.psi.KtElement
|
import org.jetbrains.kotlin.psi.KtElement
|
||||||
import org.jetbrains.kotlin.psi.KtExpression
|
import org.jetbrains.kotlin.psi.KtExpression
|
||||||
import org.jetbrains.kotlin.psi.KtForExpression
|
import org.jetbrains.kotlin.psi.KtForExpression
|
||||||
|
import org.jetbrains.kotlin.psi.KtPropertyDelegate
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
|
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
|
||||||
|
|
||||||
class IteratorOperatorReferenceSearcher(
|
class IteratorOperatorReferenceSearcher(
|
||||||
|
|||||||
+3
@@ -183,6 +183,9 @@ abstract class OperatorReferenceSearcher<TReferenceElement : KtElement>(
|
|||||||
name == OperatorNameConventions.ITERATOR ->
|
name == OperatorNameConventions.ITERATOR ->
|
||||||
return IteratorOperatorReferenceSearcher(declaration, searchScope, consumer, optimizer, options)
|
return IteratorOperatorReferenceSearcher(declaration, searchScope, consumer, optimizer, options)
|
||||||
|
|
||||||
|
name == OperatorNameConventions.GET_VALUE || name == OperatorNameConventions.SET_VALUE ->
|
||||||
|
return PropertyDelegationOperatorReferenceSearcher(declaration, searchScope, consumer, optimizer, options)
|
||||||
|
|
||||||
else ->
|
else ->
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
+50
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.search.usagesSearch
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import com.intellij.psi.PsiReference
|
||||||
|
import com.intellij.psi.search.SearchRequestCollector
|
||||||
|
import com.intellij.psi.search.SearchScope
|
||||||
|
import com.intellij.util.Processor
|
||||||
|
import org.jetbrains.kotlin.idea.references.KtPropertyDelegationMethodsReference
|
||||||
|
import org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinReferencesSearchOptions
|
||||||
|
import org.jetbrains.kotlin.psi.KtElement
|
||||||
|
import org.jetbrains.kotlin.psi.KtExpression
|
||||||
|
import org.jetbrains.kotlin.psi.KtPropertyDelegate
|
||||||
|
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
|
||||||
|
|
||||||
|
class PropertyDelegationOperatorReferenceSearcher(
|
||||||
|
targetFunction: PsiElement,
|
||||||
|
searchScope: SearchScope,
|
||||||
|
consumer: Processor<PsiReference>,
|
||||||
|
optimizer: SearchRequestCollector,
|
||||||
|
options: KotlinReferencesSearchOptions
|
||||||
|
) : OperatorReferenceSearcher<KtPropertyDelegate>(targetFunction, searchScope, consumer, optimizer, options, wordsToSearch = listOf("by")) {
|
||||||
|
|
||||||
|
override fun processPossibleReceiverExpression(expression: KtExpression) {
|
||||||
|
(expression.parent as? KtPropertyDelegate)?.let { processReferenceElement(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isReferenceToCheck(ref: PsiReference): Boolean {
|
||||||
|
return ref is KtPropertyDelegationMethodsReference
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun extractReference(element: KtElement): PsiReference? {
|
||||||
|
return (element as? KtPropertyDelegate)?.references?.firstIsInstance<KtPropertyDelegationMethodsReference>()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -36,11 +36,8 @@ val ALL_SEARCHABLE_OPERATIONS: ImmutableSet<KtToken> = ImmutableSet
|
|||||||
.add(KtTokens.BY_KEYWORD)
|
.add(KtTokens.BY_KEYWORD)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
val DELEGATE_ACCESSOR_NAMES = setOf(Name.identifier("getValue"), Name.identifier("setValue"))
|
|
||||||
|
|
||||||
fun Name.getOperationSymbolsToSearch(): Pair<Set<KtToken>, Class<*>>? {
|
fun Name.getOperationSymbolsToSearch(): Pair<Set<KtToken>, Class<*>>? {
|
||||||
when (this) {
|
when (this) {
|
||||||
in DELEGATE_ACCESSOR_NAMES -> return setOf(KtTokens.BY_KEYWORD) to KtPropertyDelegationMethodsReference::class.java
|
|
||||||
DelegatedPropertyResolver.PROPERTY_DELEGATED_FUNCTION_NAME -> return setOf(KtTokens.BY_KEYWORD) to KtPropertyDelegationMethodsReference::class.java
|
DelegatedPropertyResolver.PROPERTY_DELEGATED_FUNCTION_NAME -> return setOf(KtTokens.BY_KEYWORD) to KtPropertyDelegationMethodsReference::class.java
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
Resolved by Delegate()
|
||||||
|
Searched references to Delegate
|
||||||
|
Used plain search of Delegate.getValue(thisRef: Any?, property: KProperty<*>) in LocalSearchScope:
|
||||||
|
CLASS:Delegate
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
Resolved by Delegate()
|
||||||
|
Searched references to Delegate
|
||||||
|
Used plain search of Delegate.setValue(thisRef: Any?, property: KProperty<*>, value: String) in LocalSearchScope:
|
||||||
|
CLASS:Delegate
|
||||||
Reference in New Issue
Block a user