diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/findUsages/JetFindUsagesProvider.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/findUsages/JetFindUsagesProvider.kt index 5e011749faf..eb0090b63f0 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/findUsages/JetFindUsagesProvider.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/findUsages/JetFindUsagesProvider.kt @@ -26,8 +26,7 @@ public class JetFindUsagesProvider : FindUsagesProvider { public override fun canFindUsagesFor(psiElement: PsiElement): Boolean = psiElement is JetNamedDeclaration - public override fun getWordsScanner(): WordsScanner = - KotlinWordsScanner() + public override fun getWordsScanner() = null public override fun getHelpId(psiElement: PsiElement): String? = null diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/findUsages/KotlinWordsScanner.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/findUsages/KotlinWordsScanner.kt deleted file mode 100644 index 464908aef9e..00000000000 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/findUsages/KotlinWordsScanner.kt +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2010-2015 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.findUsages - -import org.jetbrains.kotlin.idea.search.usagesSearch.* -import com.intellij.lang.cacheBuilder.WordsScanner -import com.intellij.util.Processor -import org.jetbrains.kotlin.lexer.JetLexer -import com.intellij.lang.cacheBuilder.WordOccurrence -import org.jetbrains.kotlin.lexer.JetTokens -import com.intellij.lang.cacheBuilder.SimpleWordsScanner - -class KotlinWordsScanner() : WordsScanner { - private val lexer = JetLexer() - private val simpleWordsScanner = SimpleWordsScanner() - - fun scanWords(kind: WordOccurrence.Kind, processor: Processor) { - val tokenStart = lexer.getTokenStart() - simpleWordsScanner.processWords(lexer.getTokenSequence()) { - it!!.init(lexer.getBufferSequence(), tokenStart + it.getStart(), tokenStart + it.getEnd(), kind) - processor.process(it) - } - } - - override fun processWords(fileText: CharSequence, processor: Processor) { - lexer.start(fileText) - - val occurrence = WordOccurrence(null, 0, 0, null) - var valOrVarBefore: Boolean = false - - stream { lexer.getTokenType() }.forEach { elementType -> - // todo: replace with when - if (ALL_SEARCHABLE_OPERATIONS.contains(elementType) || (valOrVarBefore && elementType == JetTokens.LPAR)) { - occurrence.init(lexer.getBufferSequence(), lexer.getTokenStart(), lexer.getTokenEnd(), WordOccurrence.Kind.CODE) - processor.process(occurrence) - } - else if (JetTokens.COMMENTS.contains(elementType)) scanWords(WordOccurrence.Kind.COMMENTS, processor) - else if (JetTokens.STRINGS.contains(elementType)) scanWords(WordOccurrence.Kind.LITERALS, processor) - else scanWords(WordOccurrence.Kind.CODE, processor) - - if (elementType !in JetTokens.WHITE_SPACE_OR_COMMENT_BIT_SET) { - valOrVarBefore = elementType == JetTokens.VAL_KEYWORD || elementType == JetTokens.VAR_KEYWORD - } - - lexer.advance() - } - } -} diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/KotlinIndexers.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/KotlinIndexers.kt index 63c58fd36ce..ba83f221ae8 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/KotlinIndexers.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/KotlinIndexers.kt @@ -24,11 +24,13 @@ import com.intellij.psi.impl.cache.impl.OccurrenceConsumer import com.intellij.psi.impl.cache.impl.id.LexerBasedIdIndexer import com.intellij.psi.impl.cache.impl.todo.LexerBasedTodoIndexer import com.intellij.psi.search.UsageSearchContext +import com.intellij.psi.tree.IElementType import com.intellij.psi.tree.TokenSet import org.jetbrains.kotlin.idea.search.usagesSearch.ALL_SEARCHABLE_OPERATIONS import org.jetbrains.kotlin.kdoc.lexer.KDocTokens import org.jetbrains.kotlin.lexer.JetLexer import org.jetbrains.kotlin.lexer.JetTokens +import java.util.* class KotlinFilterLexer(table: OccurrenceConsumer): BaseFilterLexer(JetLexer(), table) { private val codeTokens = TokenSet.orSet( @@ -43,11 +45,19 @@ class KotlinFilterLexer(table: OccurrenceConsumer): BaseFilterLexer(JetLexer(), JetTokens.RBRACKET, JetTokens.SEMICOLON, JetTokens.COMMA, JetTokens.DOT ) + private var previousTokens = LinkedList() + override fun advance() { + fun isMultiDeclarationPosition(): Boolean { + return previousTokens[0] == JetTokens.VAL_KEYWORD || previousTokens[0] == JetTokens.VAR_KEYWORD + || previousTokens[0] == JetTokens.LPAR && previousTokens[1] == JetTokens.FOR_KEYWORD + } + val tokenType = myDelegate.getTokenType() - when(tokenType) { + when (tokenType) { in codeTokens -> addOccurrenceInToken(UsageSearchContext.IN_CODE.toInt()) + JetTokens.LPAR -> if (isMultiDeclarationPosition()) addOccurrenceInToken(UsageSearchContext.IN_CODE.toInt()) in JetTokens.STRINGS -> scanWordsInToken(UsageSearchContext.IN_STRINGS + UsageSearchContext.IN_FOREIGN_LANGUAGES, false, true) in commentTokens -> { scanWordsInToken(UsageSearchContext.IN_COMMENTS.toInt(), false, false) @@ -56,6 +66,14 @@ class KotlinFilterLexer(table: OccurrenceConsumer): BaseFilterLexer(JetLexer(), !in skipTokens -> scanWordsInToken(UsageSearchContext.IN_PLAIN_TEXT.toInt(), false, false) } + if (tokenType != TokenType.WHITE_SPACE) { + previousTokens.addFirst(tokenType) + + if (previousTokens.size() > 2) { + previousTokens.removeLast() + } + } + myDelegate.advance() } } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/conventions.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/conventions.kt index 9f54a705ca9..876ef78109d 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/conventions.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/conventions.kt @@ -35,7 +35,6 @@ public val ALL_SEARCHABLE_OPERATIONS: ImmutableSet = ImmutableSet .addAll(IDENTITY_EQUALS_OPERATIONS) .addAll(IN_OPERATIONS) .add(JetTokens.LBRACKET) - .add(JetTokens.LPAR) .add(JetTokens.BY_KEYWORD) .build() diff --git a/idea/testData/findUsages/kotlin/conventions/componentFunctions.1.kt b/idea/testData/findUsages/kotlin/conventions/componentFunctions.1.kt new file mode 100644 index 00000000000..767210b8f9c --- /dev/null +++ b/idea/testData/findUsages/kotlin/conventions/componentFunctions.1.kt @@ -0,0 +1,4 @@ +fun test() { + for ((x, y, z) in array()) { + } +} diff --git a/idea/testData/findUsages/kotlin/conventions/componentFunctions.results.txt b/idea/testData/findUsages/kotlin/conventions/componentFunctions.results.txt index a488cb0de61..68bbfba6331 100644 --- a/idea/testData/findUsages/kotlin/conventions/componentFunctions.results.txt +++ b/idea/testData/findUsages/kotlin/conventions/componentFunctions.results.txt @@ -1,3 +1,4 @@ Function call (9: 7) a.component1() Value read (10: 9) val (x, y, z) = a +Value read (2: 10) for ((x, y, z) in array()) { Value read (8: 7) a.n \ No newline at end of file