[Analysis API] refactoring, extract forEachNonKotlinPsiElementFinder to a separate file
This commit is contained in:
committed by
Space Team
parent
f8ddf204e2
commit
c646008438
+2
-18
@@ -6,7 +6,6 @@
|
||||
package org.jetbrains.kotlin.analysis.providers.impl
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiElementFinder
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.analysis.providers.KotlinPackageProvider
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -29,7 +28,7 @@ public abstract class KotlinPackageProviderBase(
|
||||
when {
|
||||
platform.isJvm() -> {
|
||||
val fqNameString = packageFqName.asString()
|
||||
forEachNonKotlinPsiElementFinder { finder ->
|
||||
forEachNonKotlinPsiElementFinder(project) { finder ->
|
||||
val psiPackage = finder.findPackage(fqNameString)
|
||||
if (psiPackage != null) {
|
||||
// we cannot easily check if some PsiPackage is in GlobalSearchScope or not
|
||||
@@ -60,7 +59,7 @@ public abstract class KotlinPackageProviderBase(
|
||||
platform.isJvm() -> {
|
||||
val fqNameString = packageFqName.asString()
|
||||
buildSet {
|
||||
forEachNonKotlinPsiElementFinder { finder ->
|
||||
forEachNonKotlinPsiElementFinder(project) { finder ->
|
||||
val psiPackage = finder.findPackage(fqNameString) ?: return@forEachNonKotlinPsiElementFinder
|
||||
for (subPackage in finder.getSubPackages(psiPackage, searchScope)) {
|
||||
val name = subPackage.name?.let(Name::identifierIfValid) ?: continue
|
||||
@@ -75,20 +74,5 @@ public abstract class KotlinPackageProviderBase(
|
||||
emptySet()
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun forEachNonKotlinPsiElementFinder(action: (PsiElementFinder) -> Unit) {
|
||||
for (finder in PsiElementFinder.EP.getPoint(project).extensionList) {
|
||||
if (finder::class.java.name == KOTLIN_JAVA_ELEMENT_FINDER_CLASS_NAME) {
|
||||
// ignore kotlin package finder
|
||||
// kotlin packages will be handled by KotlinPackageProvider.doesKotlinOnlyPackageExist/getKotlinOnlySubPackagesFqNames
|
||||
continue
|
||||
}
|
||||
action(finder)
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
private const val KOTLIN_JAVA_ELEMENT_FINDER_CLASS_NAME = "org.jetbrains.kotlin.asJava.finder.JavaElementFinder"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2023 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.analysis.providers.impl
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiElementFinder
|
||||
|
||||
public inline fun forEachNonKotlinPsiElementFinder(project: Project, action: (PsiElementFinder) -> Unit) {
|
||||
for (finder in PsiElementFinder.EP.getPoint(project).extensionList) {
|
||||
if (finder::class.java.name == KOTLIN_JAVA_ELEMENT_FINDER_CLASS_NAME) {
|
||||
continue
|
||||
}
|
||||
action(finder)
|
||||
}
|
||||
}
|
||||
|
||||
public const val KOTLIN_JAVA_ELEMENT_FINDER_CLASS_NAME: String = "org.jetbrains.kotlin.asJava.finder.JavaElementFinder"
|
||||
Reference in New Issue
Block a user