Find Usages: Disable by-convention search of invoke(). Improve scanner

accuracy when indexing possible references to component functions
This commit is contained in:
Alexey Sedunov
2014-10-03 20:37:28 +04:00
parent 5e6619e368
commit 1353e7f56b
4 changed files with 7 additions and 4 deletions
@@ -41,10 +41,11 @@ class KotlinWordsScanner() : WordsScanner {
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)) {
if (ALL_SEARCHABLE_OPERATIONS.contains(elementType) || (valOrVarBefore && elementType == JetTokens.LPAR)) {
occurrence.init(lexer.getBufferSequence(), lexer.getTokenStart(), lexer.getTokenEnd(), WordOccurrence.Kind.CODE)
processor.process(occurrence)
}
@@ -52,6 +53,10 @@ class KotlinWordsScanner() : WordsScanner {
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()
}
}
@@ -58,7 +58,6 @@ public fun Name.getOperationSymbolsToSearch(): Set<JetToken> {
EQUALS -> return EQUALS_OPERATIONS
IDENTITY_EQUALS -> return IDENTITY_EQUALS_OPERATIONS
CONTAINS -> return IN_OPERATIONS_TO_SEARCH
INVOKE_OPERATION_NAME -> return ImmutableSet.of<JetToken>(JetTokens.LPAR)
ITERATOR_OPERATION_NAME -> return ImmutableSet.of<JetToken>(JetTokens.IN_KEYWORD)
in INDEXING_OPERATION_NAMES -> return ImmutableSet.of<JetToken>(JetTokens.LBRACKET)
}
@@ -1,2 +1 @@
Function call (9: 10) B(1).invoke(2)
Implicit 'invoke' (10: 5) B(1)(2)
@@ -4,5 +4,5 @@ class A(val n: Int) {
fun test() {
A(1).foo(2)
A(1).foo(2)
A(1)(2)
}