FIR IDE: fix resolving of inner type aliases
This commit is contained in:
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.fileClasses.JvmFileClassInfo;
|
|||||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil;
|
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil;
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens;
|
import org.jetbrains.kotlin.lexer.KtTokens;
|
||||||
import org.jetbrains.kotlin.load.java.JvmAbi;
|
import org.jetbrains.kotlin.load.java.JvmAbi;
|
||||||
|
import org.jetbrains.kotlin.name.ClassId;
|
||||||
import org.jetbrains.kotlin.name.FqName;
|
import org.jetbrains.kotlin.name.FqName;
|
||||||
import org.jetbrains.kotlin.name.Name;
|
import org.jetbrains.kotlin.name.Name;
|
||||||
import org.jetbrains.kotlin.psi.KtClassOrObject;
|
import org.jetbrains.kotlin.psi.KtClassOrObject;
|
||||||
@@ -174,13 +175,18 @@ public class IdeStubIndexService extends StubIndexService {
|
|||||||
|
|
||||||
IndexUtilsKt.indexTypeAliasExpansion(stub, sink);
|
IndexUtilsKt.indexTypeAliasExpansion(stub, sink);
|
||||||
|
|
||||||
if (stub.isTopLevel()) {
|
FqName fqName = stub.getFqName();
|
||||||
FqName fqName = stub.getFqName();
|
if (fqName != null) {
|
||||||
if (fqName != null) {
|
if (stub.isTopLevel()) {
|
||||||
sink.occurrence(KotlinTopLevelTypeAliasFqNameIndex.getInstance().getKey(), fqName.asString());
|
sink.occurrence(KotlinTopLevelTypeAliasFqNameIndex.getInstance().getKey(), fqName.asString());
|
||||||
sink.occurrence(KotlinTopLevelTypeAliasByPackageIndex.getInstance().getKey(), fqName.parent().asString());
|
sink.occurrence(KotlinTopLevelTypeAliasByPackageIndex.getInstance().getKey(), fqName.parent().asString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClassId classId = stub.getClassId();
|
||||||
|
if (classId != null && !stub.isTopLevel()) {
|
||||||
|
sink.occurrence(KotlinInnerTypeAliasClassIdIndex.getInstance().getKey(), classId.asString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+34
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.stubindex
|
||||||
|
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.psi.search.GlobalSearchScope
|
||||||
|
import com.intellij.psi.stubs.StringStubIndexExtension
|
||||||
|
import com.intellij.psi.stubs.StubIndex
|
||||||
|
import com.intellij.psi.stubs.StubIndexKey
|
||||||
|
import org.jetbrains.kotlin.psi.KtTypeAlias
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Index of non-top-level type aliases (members of classes)
|
||||||
|
* The key is stringified [org.jetbrains.kotlin.name.ClassId] by the rules described in [org.jetbrains.kotlin.name.ClassId.asString]:
|
||||||
|
* packages are delimited by '/' and classes by '.', e.g. "kotlin/Map.Entry"
|
||||||
|
*/
|
||||||
|
class KotlinInnerTypeAliasClassIdIndex : StringStubIndexExtension<KtTypeAlias>() {
|
||||||
|
override fun getKey(): StubIndexKey<String, KtTypeAlias> = KEY
|
||||||
|
|
||||||
|
override fun get(s: String, project: Project, scope: GlobalSearchScope): Collection<KtTypeAlias> =
|
||||||
|
StubIndex.getElements(KEY, s, project, scope, KtTypeAlias::class.java)
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val KEY = KotlinIndexUtil.createIndexKey(KotlinInnerTypeAliasClassIdIndex::class.java)
|
||||||
|
val INSTANCE = KotlinInnerTypeAliasClassIdIndex()
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun getInstance() = INSTANCE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
+8
-3
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.name.ClassId
|
|||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
|
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Move to another module
|
* Move to another module
|
||||||
@@ -28,7 +29,7 @@ public class IndexHelper(val project: Project, private val scope: GlobalSearchSc
|
|||||||
private inline fun <INDEX_KEY : Any, reified PSI : PsiElement> firstMatchingOrNull(
|
private inline fun <INDEX_KEY : Any, reified PSI : PsiElement> firstMatchingOrNull(
|
||||||
stubKey: StubIndexKey<INDEX_KEY, PSI>,
|
stubKey: StubIndexKey<INDEX_KEY, PSI>,
|
||||||
key: INDEX_KEY,
|
key: INDEX_KEY,
|
||||||
crossinline filter: (PSI) -> Boolean
|
crossinline filter: (PSI) -> Boolean = { true }
|
||||||
): PSI? {
|
): PSI? {
|
||||||
var result: PSI? = null
|
var result: PSI? = null
|
||||||
stubIndex.processElements(
|
stubIndex.processElements(
|
||||||
@@ -48,10 +49,14 @@ public class IndexHelper(val project: Project, private val scope: GlobalSearchSc
|
|||||||
classId.asStringForIndexes(),
|
classId.asStringForIndexes(),
|
||||||
) { candidate -> candidate.containingKtFile.packageFqName == classId.packageFqName }
|
) { candidate -> candidate.containingKtFile.packageFqName == classId.packageFqName }
|
||||||
|
|
||||||
fun typeAliasFromIndexByClassId(classId: ClassId) = firstMatchingOrNull(
|
fun typeAliasFromIndexByClassId(classId: ClassId): KtTypeAlias? = firstMatchingOrNull<String, KtTypeAlias>(
|
||||||
KotlinTopLevelTypeAliasFqNameIndex.KEY,
|
KotlinTopLevelTypeAliasFqNameIndex.KEY,
|
||||||
classId.asStringForIndexes(),
|
key = classId.asStringForIndexes(),
|
||||||
) { candidate -> candidate.containingKtFile.packageFqName == classId.packageFqName }
|
) { candidate -> candidate.containingKtFile.packageFqName == classId.packageFqName }
|
||||||
|
?: firstMatchingOrNull<String, KtTypeAlias>(
|
||||||
|
KotlinInnerTypeAliasClassIdIndex.KEY,
|
||||||
|
key = classId.asString(),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
fun getTopLevelProperties(callableId: CallableId): Collection<KtProperty> =
|
fun getTopLevelProperties(callableId: CallableId): Collection<KtProperty> =
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinTopLevelFunctionFqnNameIndex"/>
|
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinTopLevelFunctionFqnNameIndex"/>
|
||||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinTopLevelPropertyFqnNameIndex"/>
|
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinTopLevelPropertyFqnNameIndex"/>
|
||||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinTopLevelTypeAliasFqNameIndex"/>
|
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinTopLevelTypeAliasFqNameIndex"/>
|
||||||
|
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinInnerTypeAliasClassIdIndex"/>
|
||||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinTopLevelExtensionsByReceiverTypeIndex"/>
|
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinTopLevelExtensionsByReceiverTypeIndex"/>
|
||||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinAnnotationsIndex"/>
|
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinAnnotationsIndex"/>
|
||||||
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinProbablyNothingFunctionShortNameIndex"/>
|
<stubIndex implementation="org.jetbrains.kotlin.idea.stubindex.KotlinProbablyNothingFunctionShortNameIndex"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user