Index properties defined in primary constructor

#KT-15029 Fixed
This commit is contained in:
Dmitry Jemerov
2017-05-09 19:03:32 +02:00
parent ec53a6dbe7
commit 9c4f897d31
13 changed files with 51 additions and 28 deletions
@@ -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 }
@@ -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());
@@ -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<KtProperty> {
private static final StubIndexKey<String, KtProperty> KEY = KotlinIndexUtil.createIndexKey(KotlinPropertyShortNameIndex.class);
public class KotlinPropertyShortNameIndex extends StringStubIndexExtension<KtNamedDeclaration> {
private static final StubIndexKey<String, KtNamedDeclaration> KEY = KotlinIndexUtil.createIndexKey(KotlinPropertyShortNameIndex.class);
private static final KotlinPropertyShortNameIndex ourInstance = new KotlinPropertyShortNameIndex();
@@ -39,13 +39,13 @@ public class KotlinPropertyShortNameIndex extends StringStubIndexExtension<KtPro
@NotNull
@Override
public StubIndexKey<String, KtProperty> getKey() {
public StubIndexKey<String, KtNamedDeclaration> getKey() {
return KEY;
}
@NotNull
@Override
public Collection<KtProperty> get(@NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) {
return StubIndex.getElements(KEY, s, project, scope, KtProperty.class);
public Collection<KtNamedDeclaration> get(@NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) {
return StubIndex.getElements(KEY, s, project, scope, KtNamedDeclaration.class);
}
}