File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
sqldelight-idea-plugin/src/main/kotlin/app/cash/sqldelight/intellij Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ internal class SqlDelightReferenceContributor : PsiReferenceContributor() {
64
64
val scope = module.getModuleWithDependenciesAndLibrariesScope(false )
65
65
val classNameIndex = KotlinFullClassNameIndex .getInstance()
66
66
val ktClass = { classNameIndex[qName, project, scope].firstOrNull() }
67
- val typeAliasFqNameIndex = KotlinTopLevelTypeAliasFqNameIndex .getInstance ()
67
+ val typeAliasFqNameIndex = getKotlinTopLevelTypeAliasFqNameIndex ()
68
68
val typeAlias = { typeAliasFqNameIndex[qName, project, scope].firstOrNull() }
69
69
val javaPsiFacade = JavaPsiFacade .getInstance(project)
70
70
val javaClass = { javaPsiFacade.findClass(qName, scope) }
@@ -74,3 +74,17 @@ internal class SqlDelightReferenceContributor : PsiReferenceContributor() {
74
74
private fun typeForThisPackage (file : SqlDelightFile ) = " ${file.packageName} .${element.text} "
75
75
}
76
76
}
77
+
78
+ private fun getKotlinTopLevelTypeAliasFqNameIndex (): KotlinTopLevelTypeAliasFqNameIndex {
79
+ // read the INSTANCE variable reflectively first (newer Kotlin plugins)
80
+ try {
81
+ val instanceField = KotlinTopLevelTypeAliasFqNameIndex ::class .java.getField(" INSTANCE" )
82
+ val instance = instanceField.get(null )
83
+ if (instance is KotlinTopLevelTypeAliasFqNameIndex ) {
84
+ return instance
85
+ }
86
+ } catch (e: Exception ) {
87
+ /* intentionally empty, fall back to getInstance() call in case of errors */
88
+ }
89
+ return KotlinTopLevelTypeAliasFqNameIndex .getInstance()
90
+ }
You can’t perform that action at this time.
0 commit comments