Skip to content

Commit

Permalink
[PSI] KtCommonFile: optimize search for import aliases
Browse files Browse the repository at this point in the history
This check can be done on top of stub only

^KT-73687
  • Loading branch information
dimonchik0036 authored and qodana-bot committed Dec 9, 2024
1 parent 7ab8dad commit 754f157
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions compiler/psi/src/org/jetbrains/kotlin/psi/KtCommonFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.parsing.KotlinParserDefinition
import org.jetbrains.kotlin.psi.psiUtil.children
import org.jetbrains.kotlin.psi.psiUtil.hasExpectModifier
import org.jetbrains.kotlin.psi.stubs.KotlinFileStub
import org.jetbrains.kotlin.psi.stubs.KotlinImportDirectiveStub
import org.jetbrains.kotlin.psi.stubs.elements.KtPlaceHolderStubElementType
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementType
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
Expand Down Expand Up @@ -325,14 +326,15 @@ open class KtCommonFile(viewProvider: FileViewProvider, val isCompiled: Boolean)
}

private fun KtImportList.computeHasImportAlias(): Boolean {
var child: PsiElement? = firstChild
while (child != null) {
if (child is KtImportDirective && child.alias != null) {
return true
val stub = greenStub
if (stub != null) {
return stub.childrenStubs.any {
it is KotlinImportDirectiveStub && it.findChildStubByType(KtStubElementTypes.IMPORT_ALIAS) != null
}

child = child.nextSibling
}

return false
return node.children().any {
val psi = it.psi
psi is KtImportDirective && psi.alias != null
}
}

0 comments on commit 754f157

Please sign in to comment.