FIR: move components from AbstractDiagnosticCollectorVisitor to CheckerRunningDiagnosticCollectorVisitor
This commit is contained in:
+8
-10
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.FirFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.fir.PrivateForInline
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.PersistentCheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.collectors.components.AbstractDiagnosticCollectorComponent
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
@@ -26,34 +25,33 @@ import org.jetbrains.kotlin.name.Name
|
||||
|
||||
abstract class AbstractDiagnosticCollectorVisitor(
|
||||
@set:PrivateForInline var context: PersistentCheckerContext,
|
||||
protected val components: List<AbstractDiagnosticCollectorComponent>,
|
||||
) : FirDefaultVisitor<Unit, Nothing?>() {
|
||||
|
||||
protected open fun shouldVisitDeclaration(declaration: FirDeclaration) = true
|
||||
protected open fun onDeclarationExit(declaration: FirDeclaration) {}
|
||||
|
||||
protected abstract fun visitNestedElements(element: FirElement)
|
||||
protected abstract fun runComponents(element: FirElement)
|
||||
protected abstract fun checkElement(element: FirElement)
|
||||
|
||||
override fun visitElement(element: FirElement, data: Nothing?) {
|
||||
if (element is FirAnnotationContainer) {
|
||||
visitAnnotationContainer(element, data)
|
||||
return
|
||||
}
|
||||
runComponents(element)
|
||||
checkElement(element)
|
||||
visitNestedElements(element)
|
||||
}
|
||||
|
||||
override fun visitAnnotationContainer(annotationContainer: FirAnnotationContainer, data: Nothing?) {
|
||||
withSuppressedDiagnostics(annotationContainer) {
|
||||
runComponents(annotationContainer)
|
||||
checkElement(annotationContainer)
|
||||
visitNestedElements(annotationContainer)
|
||||
}
|
||||
}
|
||||
|
||||
private fun visitJump(loopJump: FirLoopJump) {
|
||||
withSuppressedDiagnostics(loopJump) {
|
||||
runComponents(loopJump)
|
||||
checkElement(loopJump)
|
||||
loopJump.target.labeledElement.takeIf { it is FirErrorLoop }?.accept(this, null)
|
||||
}
|
||||
}
|
||||
@@ -160,7 +158,7 @@ abstract class AbstractDiagnosticCollectorVisitor(
|
||||
override fun visitTypeRef(typeRef: FirTypeRef, data: Nothing?) {
|
||||
if (typeRef.source != null && typeRef.source?.kind !is FirFakeSourceElementKind) {
|
||||
withSuppressedDiagnostics(typeRef) {
|
||||
runComponents(typeRef)
|
||||
checkElement(typeRef)
|
||||
visitNestedElements(typeRef)
|
||||
}
|
||||
}
|
||||
@@ -188,7 +186,7 @@ abstract class AbstractDiagnosticCollectorVisitor(
|
||||
block: () -> Unit = { visitNestedElements(declaration) }
|
||||
) {
|
||||
if (shouldVisitDeclaration(declaration)) {
|
||||
runComponents(declaration)
|
||||
checkElement(declaration)
|
||||
withDeclaration(declaration) {
|
||||
block()
|
||||
}
|
||||
@@ -210,14 +208,14 @@ abstract class AbstractDiagnosticCollectorVisitor(
|
||||
|
||||
private fun visitWithQualifiedAccess(qualifiedAccess: FirQualifiedAccess) {
|
||||
return withQualifiedAccess(qualifiedAccess) {
|
||||
runComponents(qualifiedAccess)
|
||||
checkElement(qualifiedAccess)
|
||||
visitNestedElements(qualifiedAccess)
|
||||
}
|
||||
}
|
||||
|
||||
private fun visitWithGetClassCall(getClassCall: FirGetClassCall) {
|
||||
return withGetClassCall(getClassCall) {
|
||||
runComponents(getClassCall)
|
||||
checkElement(getClassCall)
|
||||
visitNestedElements(getClassCall)
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -11,14 +11,14 @@ import org.jetbrains.kotlin.fir.analysis.collectors.components.AbstractDiagnosti
|
||||
|
||||
open class CheckerRunningDiagnosticCollectorVisitor(
|
||||
context: PersistentCheckerContext,
|
||||
components: List<AbstractDiagnosticCollectorComponent>
|
||||
) : AbstractDiagnosticCollectorVisitor(context, components) {
|
||||
protected val components: List<AbstractDiagnosticCollectorComponent>
|
||||
) : AbstractDiagnosticCollectorVisitor(context) {
|
||||
|
||||
override fun visitNestedElements(element: FirElement) {
|
||||
element.acceptChildren(this, null)
|
||||
}
|
||||
|
||||
override fun runComponents(element: FirElement) {
|
||||
override fun checkElement(element: FirElement) {
|
||||
components.forEach {
|
||||
element.accept(it, context)
|
||||
}
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ internal open class FirIdeDiagnosticVisitor(
|
||||
super.visitNestedElements(element)
|
||||
}
|
||||
|
||||
override fun runComponents(element: FirElement) {
|
||||
override fun checkElement(element: FirElement) {
|
||||
beforeElementDiagnosticCollectionHandler?.beforeCollectingForElement(element)
|
||||
components.forEach {
|
||||
checkCanceled()
|
||||
|
||||
+2
-3
@@ -20,8 +20,7 @@ private class ContextCollectingDiagnosticCollectorVisitor private constructor(
|
||||
designation: FirDeclarationDesignation,
|
||||
firFile: FirFile,
|
||||
) : AbstractDiagnosticCollectorVisitor(
|
||||
PersistentCheckerContextFactory.createEmptyPersistenceCheckerContext(sessionHolder),
|
||||
components = emptyList()
|
||||
PersistentCheckerContextFactory.createEmptyPersistenceCheckerContext(sessionHolder)
|
||||
) {
|
||||
private val contextCollector = object : ContextByDesignationCollector<PersistentCheckerContext>(designation, firFile) {
|
||||
override fun getCurrentContext(): PersistentCheckerContext = context
|
||||
@@ -39,7 +38,7 @@ private class ContextCollectingDiagnosticCollectorVisitor private constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override fun runComponents(element: FirElement) {}
|
||||
override fun checkElement(element: FirElement) {}
|
||||
|
||||
companion object {
|
||||
fun collect(sessionHolder: SessionHolder, firFile: FirFile, designation: FirDeclarationDesignation): PersistentCheckerContext {
|
||||
|
||||
Reference in New Issue
Block a user