Kotlin: Share a Psi2Ir instance

This commit is contained in:
Ian Lynagh
2022-07-11 18:57:43 +01:00
parent 780f5abc67
commit b9072a3594
2 changed files with 6 additions and 5 deletions

View File

@@ -16,7 +16,8 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset
class CommentExtractor(private val fileExtractor: KotlinFileExtractor, private val file: IrFile, private val fileLabel: Label<out DbFile>) {
private val tw = fileExtractor.tw
private val logger = fileExtractor.logger
private val ktFile = Psi2Ir().getKtFile(file)
private val psi2Ir = Psi2Ir()
private val ktFile = psi2Ir.getKtFile(file)
fun extract() {
if (ktFile == null) {
@@ -85,7 +86,7 @@ class CommentExtractor(private val fileExtractor: KotlinFileExtractor, private v
val ownerPsi = getKDocOwner(comment) ?: return
val owners = mutableListOf<IrElement>()
file.accept(IrVisitorLookup(ownerPsi, file), owners)
file.accept(IrVisitorLookup(psi2Ir, ownerPsi, file), owners)
for (ownerIr in owners) {
val ownerLabel =

View File

@@ -8,7 +8,7 @@ import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.util.isFakeOverride
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
class IrVisitorLookup(private val psi: PsiElement, private val file: IrFile) :
class IrVisitorLookup(private val psi2Ir: Psi2Ir, private val psi: PsiElement, private val file: IrFile) :
IrElementVisitor<Unit, MutableCollection<IrElement>> {
private val location = psi.getLocation()
@@ -27,7 +27,7 @@ class IrVisitorLookup(private val psi: PsiElement, private val file: IrFile) :
}
if (location.contains(elementLocation)) {
val psiElement = Psi2Ir().findPsiElement(element, file)
val psiElement = psi2Ir.findPsiElement(element, file)
if (psiElement == psi) {
// There can be multiple IrElements that match the same PSI element.
data.add(element)
@@ -35,4 +35,4 @@ class IrVisitorLookup(private val psi: PsiElement, private val file: IrFile) :
}
element.acceptChildren(this, data)
}
}
}