Quick search of iterator operator usages
This commit is contained in:
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.KtNodeTypes
|
||||
import org.jetbrains.kotlin.idea.references.KtForLoopInReference
|
||||
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.KtForExpression
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
|
||||
|
||||
class IteratorOperatorReferenceSearcher(
|
||||
targetFunction: PsiElement,
|
||||
searchScope: SearchScope,
|
||||
consumer: Processor<PsiReference>,
|
||||
optimizer: SearchRequestCollector,
|
||||
options: KotlinReferencesSearchOptions
|
||||
) : OperatorReferenceSearcher<KtForExpression>(targetFunction, searchScope, consumer, optimizer, options, wordsToSearch = listOf("in")) {
|
||||
|
||||
override fun processPossibleReceiverExpression(expression: KtExpression) {
|
||||
val parent = expression.parent
|
||||
if (parent.node.elementType == KtNodeTypes.LOOP_RANGE) {
|
||||
processReferenceElement(parent.parent as KtForExpression)
|
||||
}
|
||||
}
|
||||
|
||||
override fun isReferenceToCheck(ref: PsiReference): Boolean {
|
||||
return ref is KtForLoopInReference
|
||||
}
|
||||
|
||||
override fun extractReference(element: KtElement): PsiReference? {
|
||||
return (element as? KtForExpression)?.references?.firstIsInstance<KtForLoopInReference>()
|
||||
}
|
||||
}
|
||||
+3
@@ -180,6 +180,9 @@ abstract class OperatorReferenceSearcher<TReferenceElement : KtElement>(
|
||||
name == OperatorNameConventions.COMPARE_TO ->
|
||||
return BinaryOperatorReferenceSearcher(declaration, listOf(KtTokens.LT, KtTokens.GT, KtTokens.LTEQ, KtTokens.GTEQ), searchScope, consumer, optimizer, options)
|
||||
|
||||
name == OperatorNameConventions.ITERATOR ->
|
||||
return IteratorOperatorReferenceSearcher(declaration, searchScope, consumer, optimizer, options)
|
||||
|
||||
else ->
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -17,14 +17,12 @@
|
||||
package org.jetbrains.kotlin.idea.search.usagesSearch
|
||||
|
||||
import com.google.common.collect.ImmutableSet
|
||||
import org.jetbrains.kotlin.idea.references.KtForLoopInReference
|
||||
import org.jetbrains.kotlin.idea.references.KtPropertyDelegationMethodsReference
|
||||
import org.jetbrains.kotlin.lexer.KtToken
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DelegatedPropertyResolver
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions.*
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
|
||||
val ALL_SEARCHABLE_OPERATIONS: ImmutableSet<KtToken> = ImmutableSet
|
||||
.builder<KtToken>()
|
||||
@@ -40,11 +38,8 @@ val ALL_SEARCHABLE_OPERATIONS: ImmutableSet<KtToken> = ImmutableSet
|
||||
|
||||
val DELEGATE_ACCESSOR_NAMES = setOf(Name.identifier("getValue"), Name.identifier("setValue"))
|
||||
|
||||
val IN_OPERATIONS_TO_SEARCH = setOf(KtTokens.IN_KEYWORD)
|
||||
|
||||
fun Name.getOperationSymbolsToSearch(): Pair<Set<KtToken>, Class<*>>? {
|
||||
when (this) {
|
||||
OperatorNameConventions.ITERATOR -> return IN_OPERATIONS_TO_SEARCH to KtForLoopInReference::class.java
|
||||
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
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
Checked type of parameter a of FOR
|
||||
Checked type of parameter a of FOR
|
||||
Resolved for (a in A<Int>()) {}
|
||||
Resolved for (a in A<String>()) {}
|
||||
Searched references to A
|
||||
Used plain search of A.iterator() in LocalSearchScope:
|
||||
CLASS:A
|
||||
Reference in New Issue
Block a user