Allow script dependnencies to be found as a candidates for decompilation
This commit is contained in:
+16
-4
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.idea.decompiler.KtDecompiledFile
|
||||
import org.jetbrains.kotlin.idea.decompiler.textBuilder.DecompiledTextIndexer
|
||||
import org.jetbrains.kotlin.idea.script.KotlinScriptConfigurationManager
|
||||
import org.jetbrains.kotlin.idea.stubindex.KotlinFullClassNameIndex
|
||||
import org.jetbrains.kotlin.idea.stubindex.KotlinSourceFilterScope
|
||||
import org.jetbrains.kotlin.idea.stubindex.KotlinTopLevelFunctionFqnNameIndex
|
||||
@@ -76,11 +77,16 @@ private fun findCandidateDeclarationsInIndex(
|
||||
project: Project,
|
||||
referencedDescriptor: DeclarationDescriptor
|
||||
): Collection<KtDeclaration?> {
|
||||
val scope = KotlinSourceFilterScope.libraryClassFiles(GlobalSearchScope.allScope(project), project)
|
||||
val scope = GlobalSearchScope.union(
|
||||
arrayOf<GlobalSearchScope>(
|
||||
KotlinSourceFilterScope.libraryClassFiles(GlobalSearchScope.allScope(project), project),
|
||||
// NOTE: using this scope here and getNoScopeWrap below is hopefully temporary and will be removed after refactoring
|
||||
// of searching logic
|
||||
KotlinScriptConfigurationManager.getInstance(project).getAllScriptsClasspathScope()))
|
||||
|
||||
val containingClass = DescriptorUtils.getParentOfType(referencedDescriptor, ClassDescriptor::class.java, false)
|
||||
if (containingClass != null) {
|
||||
return KotlinFullClassNameIndex.getInstance().get(containingClass.fqNameSafe.asString(), project, scope)
|
||||
return KotlinFullClassNameIndex.getInstance().getNoScopeWrap(containingClass.fqNameSafe.asString(), project, scope)
|
||||
}
|
||||
|
||||
val topLevelDeclaration = DescriptorUtils.getParentOfType(referencedDescriptor, PropertyDescriptor::class.java, false)
|
||||
@@ -92,10 +98,16 @@ private fun findCandidateDeclarationsInIndex(
|
||||
val fqName = topLevelDeclaration.fqNameSafe.asString()
|
||||
when (topLevelDeclaration) {
|
||||
is FunctionDescriptor -> {
|
||||
return KotlinTopLevelFunctionFqnNameIndex.getInstance().get(fqName, project, scope)
|
||||
return if (scriptsScope != null)
|
||||
KotlinTopLevelFunctionFqnNameIndex.getInstance().getNoScopeWrap(fqName, project, scope)
|
||||
else
|
||||
KotlinTopLevelFunctionFqnNameIndex.getInstance().get(fqName, project, scope)
|
||||
}
|
||||
is PropertyDescriptor -> {
|
||||
return KotlinTopLevelPropertyFqnNameIndex.getInstance().get(fqName, project, scope)
|
||||
return if (scriptsScope != null)
|
||||
KotlinTopLevelPropertyFqnNameIndex.getInstance().getNoScopeWrap(fqName, project, scope)
|
||||
else
|
||||
KotlinTopLevelPropertyFqnNameIndex.getInstance().get(fqName, project, scope)
|
||||
}
|
||||
else -> error("Referenced non local declaration that is not inside top level function, property of class:\n $referencedDescriptor")
|
||||
}
|
||||
|
||||
+6
@@ -50,4 +50,10 @@ public class KotlinFullClassNameIndex extends StringStubIndexExtension<KtClassOr
|
||||
public Collection<KtClassOrObject> get(@NotNull String fqName, @NotNull Project project, @NotNull GlobalSearchScope scope) {
|
||||
return StubIndex.getElements(KEY, fqName, project, KotlinSourceFilterScope.sourcesAndLibraries(scope, project), KtClassOrObject.class);
|
||||
}
|
||||
|
||||
// temporary hack, see comments in findCandidateDeclarationsInIndex (findDecompiledDeclaration.kt)
|
||||
@NotNull
|
||||
public Collection<KtClassOrObject> getNoScopeWrap(@NotNull String fqName, @NotNull Project project, @NotNull GlobalSearchScope scope) {
|
||||
return StubIndex.getElements(KEY, fqName, project, scope, KtClassOrObject.class);
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -52,4 +52,10 @@ public class KotlinTopLevelFunctionFqnNameIndex extends StringStubIndexExtension
|
||||
public Collection<KtNamedFunction> get(@NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) {
|
||||
return StubIndex.getElements(KEY, s, project, KotlinSourceFilterScope.sourcesAndLibraries(scope, project), KtNamedFunction.class);
|
||||
}
|
||||
|
||||
// temporary hack, see comments in findCandidateDeclarationsInIndex (findDecompiledDeclaration.kt)
|
||||
@NotNull
|
||||
public Collection<KtNamedFunction> getNoScopeWrap(@NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) {
|
||||
return StubIndex.getElements(KEY, s, project, scope, KtNamedFunction.class);
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -49,4 +49,10 @@ public class KotlinTopLevelPropertyFqnNameIndex extends StringStubIndexExtension
|
||||
public Collection<KtProperty> get(@NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) {
|
||||
return StubIndex.getElements(KEY, s, project, KotlinSourceFilterScope.sourcesAndLibraries(scope, project), KtProperty.class);
|
||||
}
|
||||
|
||||
// temporary hack, see comments in findCandidateDeclarationsInIndex (findDecompiledDeclaration.kt)
|
||||
@NotNull
|
||||
public Collection<KtProperty> getNoScopeWrap(@NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) {
|
||||
return StubIndex.getElements(KEY, s, project, scope, KtProperty.class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user