diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt index 4e32deee05d..74082c28fe2 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt @@ -23,12 +23,12 @@ object KotlinStubVersions { // Though only kotlin declarations (no code in the bodies) are stubbed, please do increase this version // if you are not 100% sure it can be avoided. // Increasing this version will lead to reindexing of all kotlin source files on the first IDE startup with the new version. - const val SOURCE_STUB_VERSION = 121 + const val SOURCE_STUB_VERSION = 122 // Binary stub version should be increased if stub format (org.jetbrains.kotlin.psi.stubs.impl) is changed // or changes are made to the core stub building code (org.jetbrains.kotlin.idea.decompiler.stubBuilder). // Increasing this version will lead to reindexing of all binary files that are potentially kotlin binaries (including all class files). - private const val BINARY_STUB_VERSION = 58 + private const val BINARY_STUB_VERSION = 59 // Classfile stub version should be increased if changes are made to classfile stub building subsystem (org.jetbrains.kotlin.idea.decompiler.classFile) // Increasing this version will lead to reindexing of all classfiles. diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/KtParameterElementType.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/KtParameterElementType.java index 0d3be3752e6..c9996ae6384 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/KtParameterElementType.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/elements/KtParameterElementType.java @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.psi.stubs.elements; +import com.intellij.psi.stubs.IndexSink; import com.intellij.psi.stubs.StubElement; import com.intellij.psi.stubs.StubInputStream; import com.intellij.psi.stubs.StubOutputStream; @@ -63,4 +64,9 @@ public class KtParameterElementType extends KtStubElementType = allMethods.iterator() } } + +fun KtNamedDeclaration.getAccessorLightMethods(): LightClassUtil.PropertyAccessorsPsiMethods { + return when (this) { + is KtProperty -> LightClassUtil.getLightClassPropertyMethods(this) + is KtParameter -> LightClassUtil.getLightClassPropertyMethods(this) + else -> throw IllegalStateException("Unexpected property type: ${this}") + } +} diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/KotlinShortNamesCache.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/KotlinShortNamesCache.kt index ace5b4b204a..0a294091b31 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/KotlinShortNamesCache.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/KotlinShortNamesCache.kt @@ -28,6 +28,7 @@ import com.intellij.util.containers.HashSet import org.jetbrains.kotlin.asJava.LightClassUtil import org.jetbrains.kotlin.asJava.defaultImplsChild import org.jetbrains.kotlin.asJava.finder.JavaElementFinder +import org.jetbrains.kotlin.asJava.getAccessorLightMethods import org.jetbrains.kotlin.asJava.getAccessorNamesCandidatesByPropertyName import org.jetbrains.kotlin.fileClasses.javaFileFacadeFqName import org.jetbrains.kotlin.idea.stubindex.* @@ -103,7 +104,7 @@ class KotlinShortNamesCache(private val project: Project) : PsiShortNamesCache() val propertyAccessorsPsi = sequenceOfLazyValues({ getPropertyNamesCandidatesByAccessorName(Name.identifier(name)) }) .flatMap { it.asSequence() } .flatMap { propertiesIndex.get(it.asString(), project, scope).asSequence() } - .flatMap { LightClassUtil.getLightClassPropertyMethods(it).allDeclarations.asSequence() } + .flatMap { it.getAccessorLightMethods().allDeclarations.asSequence() } .filter { it.name == name } .map { it as? PsiMethod } diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/IdeStubIndexService.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/IdeStubIndexService.java index 15e47eb47b8..a4e3f3c5009 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/IdeStubIndexService.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/IdeStubIndexService.java @@ -214,6 +214,14 @@ public class IdeStubIndexService extends StubIndexService { IndexUtilsKt.indexInternals(stub, sink); } + @Override + public void indexParameter(@NotNull KotlinParameterStub stub, @NotNull IndexSink sink) { + String name = stub.getName(); + if (name != null && stub.hasValOrVar()) { + sink.occurrence(KotlinPropertyShortNameIndex.getInstance().getKey(), name); + } + } + @Override public void indexAnnotation(KotlinAnnotationEntryStub stub, IndexSink sink) { sink.occurrence(KotlinAnnotationsIndex.getInstance().getKey(), stub.getShortName()); diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinPropertyShortNameIndex.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinPropertyShortNameIndex.java index 7f3b9c8c543..e0acc8f5ff8 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinPropertyShortNameIndex.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/stubindex/KotlinPropertyShortNameIndex.java @@ -22,12 +22,12 @@ import com.intellij.psi.stubs.StringStubIndexExtension; import com.intellij.psi.stubs.StubIndex; import com.intellij.psi.stubs.StubIndexKey; import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.psi.KtProperty; +import org.jetbrains.kotlin.psi.KtNamedDeclaration; import java.util.Collection; -public class KotlinPropertyShortNameIndex extends StringStubIndexExtension { - private static final StubIndexKey KEY = KotlinIndexUtil.createIndexKey(KotlinPropertyShortNameIndex.class); +public class KotlinPropertyShortNameIndex extends StringStubIndexExtension { + private static final StubIndexKey KEY = KotlinIndexUtil.createIndexKey(KotlinPropertyShortNameIndex.class); private static final KotlinPropertyShortNameIndex ourInstance = new KotlinPropertyShortNameIndex(); @@ -39,13 +39,13 @@ public class KotlinPropertyShortNameIndex extends StringStubIndexExtension getKey() { + public StubIndexKey getKey() { return KEY; } @NotNull @Override - public Collection get(@NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) { - return StubIndex.getElements(KEY, s, project, scope, KtProperty.class); + public Collection get(@NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) { + return StubIndex.getElements(KEY, s, project, scope, KtNamedDeclaration.class); } } diff --git a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/StaticMembersCompletion.kt b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/StaticMembersCompletion.kt index b78eb5806d4..5c7194c5652 100644 --- a/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/StaticMembersCompletion.kt +++ b/idea/idea-completion/src/org/jetbrains/kotlin/idea/completion/StaticMembersCompletion.kt @@ -27,9 +27,9 @@ import org.jetbrains.kotlin.idea.core.KotlinIndicesHelper import org.jetbrains.kotlin.idea.core.targetDescriptors import org.jetbrains.kotlin.idea.resolve.ResolutionFacade import org.jetbrains.kotlin.lexer.KtTokens -import org.jetbrains.kotlin.psi.KtCallableDeclaration import org.jetbrains.kotlin.psi.KtClass import org.jetbrains.kotlin.psi.KtFile +import org.jetbrains.kotlin.psi.KtNamedDeclaration import org.jetbrains.kotlin.psi.KtObjectDeclaration import org.jetbrains.kotlin.resolve.ImportedFromObjectCallableDescriptor import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude @@ -99,7 +99,7 @@ class StaticMembersCompletion( val descriptorKindFilter = DescriptorKindFilter.CALLABLES exclude DescriptorKindExclude.Extensions val nameFilter: (String) -> Boolean = { prefixMatcher.prefixMatches(it) } - val filter = { declaration: KtCallableDeclaration, objectDeclaration: KtObjectDeclaration -> + val filter = { declaration: KtNamedDeclaration, objectDeclaration: KtObjectDeclaration -> !declaration.hasModifier(KtTokens.OVERRIDE_KEYWORD) && objectDeclaration.isTopLevelOrCompanion() } indicesHelper.processObjectMembers(descriptorKindFilter, nameFilter, filter) { diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinIndicesHelper.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinIndicesHelper.kt index 5daeadafcd3..d9227343439 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinIndicesHelper.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinIndicesHelper.kt @@ -75,7 +75,7 @@ class KotlinIndicesHelper( } fun getTopLevelCallablesByName(name: String): Collection { - val declarations = LinkedHashSet() + val declarations = LinkedHashSet() declarations.addTopLevelNonExtensionCallablesByName(KotlinFunctionShortNameIndex.getInstance(), name) declarations.addTopLevelNonExtensionCallablesByName(KotlinPropertyShortNameIndex.getInstance(), name) return declarations @@ -83,11 +83,11 @@ class KotlinIndicesHelper( .filter { descriptorFilter(it) } } - private fun MutableSet.addTopLevelNonExtensionCallablesByName( - index: StringStubIndexExtension, + private fun MutableSet.addTopLevelNonExtensionCallablesByName( + index: StringStubIndexExtension, name: String ) { - index.get(name, project, scope).filterTo(this) { it.parent is KtFile && it.receiverTypeReference == null } + index.get(name, project, scope).filterTo(this) { it.parent is KtFile && it is KtCallableDeclaration && it.receiverTypeReference == null } } fun getTopLevelExtensionOperatorsByName(name: String): Collection { @@ -336,11 +336,11 @@ class KotlinIndicesHelper( fun processKotlinCallablesByName( name: String, - filter: (KtCallableDeclaration) -> Boolean, + filter: (KtNamedDeclaration) -> Boolean, processor: (CallableDescriptor) -> Unit ) { val functions: Sequence = KotlinFunctionShortNameIndex.getInstance().get(name, project, scope).asSequence() - val properties: Sequence = KotlinPropertyShortNameIndex.getInstance().get(name, project, scope).asSequence() + val properties: Sequence = KotlinPropertyShortNameIndex.getInstance().get(name, project, scope).asSequence() val processed = HashSet() for (declaration in functions + properties) { ProgressManager.checkCanceled() @@ -390,10 +390,10 @@ class KotlinIndicesHelper( fun processObjectMembers( descriptorKindFilter: DescriptorKindFilter, nameFilter: (String) -> Boolean, - filter: (KtCallableDeclaration, KtObjectDeclaration) -> Boolean, + filter: (KtNamedDeclaration, KtObjectDeclaration) -> Boolean, processor: (DeclarationDescriptor) -> Unit ) { - fun processIndex(index: StringStubIndexExtension) { + fun processIndex(index: StringStubIndexExtension) { for (name in index.getAllKeys(project)) { ProgressManager.checkCanceled() if (!nameFilter(name)) continue diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/KotlinLineMarkerProvider.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/KotlinLineMarkerProvider.kt index ab5543f0c09..3809c8e3e16 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/KotlinLineMarkerProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/KotlinLineMarkerProvider.kt @@ -34,6 +34,7 @@ import com.intellij.psi.PsiMethod import com.intellij.psi.PsiNameIdentifierOwner import com.intellij.psi.search.searches.ClassInheritorsSearch import org.jetbrains.kotlin.asJava.LightClassUtil +import org.jetbrains.kotlin.asJava.getAccessorLightMethods import org.jetbrains.kotlin.asJava.toLightClass import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.MemberDescriptor @@ -323,14 +324,6 @@ private fun collectHeaderMarkers(declaration: KtNamedDeclaration, )) } -fun KtNamedDeclaration.getAccessorLightMethods(): LightClassUtil.PropertyAccessorsPsiMethods { - return when (this) { - is KtProperty -> LightClassUtil.getLightClassPropertyMethods(this) - is KtParameter -> LightClassUtil.getLightClassPropertyMethods(this) - else -> throw IllegalStateException("Unexpected property type: ${this}") - } -} - private fun collectOverriddenFunctions(functions: Collection, result: MutableCollection>) { val mappingToJava = HashMap() for (function in functions) { diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/OverridenPropertyMarker.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/OverridenPropertyMarker.kt index ec27a9563b5..da52b0e108d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/OverridenPropertyMarker.kt +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/markers/OverridenPropertyMarker.kt @@ -34,6 +34,7 @@ import com.intellij.util.AdapterProcessor import com.intellij.util.CommonProcessors import com.intellij.util.Function import org.jetbrains.kotlin.asJava.LightClassUtil +import org.jetbrains.kotlin.asJava.getAccessorLightMethods import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinDefinitionsSearcher import org.jetbrains.kotlin.lexer.KtTokens diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/kotlinRefactoringUtil.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/kotlinRefactoringUtil.kt index b99d080b0a2..3b3e04a3f32 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/kotlinRefactoringUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/kotlinRefactoringUtil.kt @@ -60,6 +60,7 @@ import com.intellij.util.VisibilityUtil import com.intellij.util.containers.MultiMap import org.jetbrains.kotlin.asJava.LightClassUtil import org.jetbrains.kotlin.asJava.elements.KtLightMethod +import org.jetbrains.kotlin.asJava.getAccessorLightMethods import org.jetbrains.kotlin.asJava.namedUnwrappedElement import org.jetbrains.kotlin.asJava.toLightClass import org.jetbrains.kotlin.descriptors.* @@ -75,7 +76,6 @@ import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde import org.jetbrains.kotlin.idea.core.* import org.jetbrains.kotlin.idea.core.util.showYesNoCancelDialog -import org.jetbrains.kotlin.idea.highlighter.markers.getAccessorLightMethods import org.jetbrains.kotlin.idea.intentions.RemoveCurlyBracesFromTemplateIntention import org.jetbrains.kotlin.idea.j2k.IdeaJavaToKotlinServices import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinValVar diff --git a/idea/testData/navigation/gotoSymbol/properties.kt b/idea/testData/navigation/gotoSymbol/properties.kt index b0bf66d93bc..8e61c4e96a3 100644 --- a/idea/testData/navigation/gotoSymbol/properties.kt +++ b/idea/testData/navigation/gotoSymbol/properties.kt @@ -16,8 +16,11 @@ class Some() { } } +class SomePrimary(val testInPrimary: Int) + // SEARCH_TEXT: test // REF: ().testGlobal // REF: (in Some).testInClass // REF: (in Some.Companion).testInClassObject +// REF: (in SomePrimary).testInPrimary // REF: (in SomeTrait).testInTrait \ No newline at end of file