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