FIR checker: refactor FirSyntaxChecker
Introduce a new checkPsiOrLightTree so the structure is more symmetric. In addition, now implementation of `checkLightTree` has access to `FirLightSourceElement` rather tha a generic `FirSourceElement`
This commit is contained in:
committed by
TeamCityServer
parent
34071f285a
commit
809d518fcf
+1
-1
@@ -27,7 +27,7 @@ object RedundantModalityModifierSyntaxChecker : FirDeclarationSyntaxChecker<FirD
|
||||
override fun isApplicable(element: FirDeclaration, source: FirSourceElement): Boolean =
|
||||
source.kind !is FirFakeSourceElementKind && element is FirMemberDeclaration
|
||||
|
||||
override fun checkLightTree(
|
||||
override fun checkPsiOrLightTree(
|
||||
element: FirDeclaration,
|
||||
source: FirSourceElement,
|
||||
context: CheckerContext,
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
|
||||
object RedundantVisibilityModifierSyntaxChecker : FirDeclarationSyntaxChecker<FirDeclaration, KtDeclaration>() {
|
||||
|
||||
override fun checkLightTree(
|
||||
override fun checkPsiOrLightTree(
|
||||
element: FirDeclaration,
|
||||
source: FirSourceElement,
|
||||
context: CheckerContext,
|
||||
|
||||
+2
-2
@@ -5,8 +5,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.syntax
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirLightSourceElement
|
||||
import org.jetbrains.kotlin.fir.FirPsiSourceElement
|
||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
@@ -34,7 +34,7 @@ object FirAnonymousFunctionSyntaxChecker : FirDeclarationSyntaxChecker<FirAnonym
|
||||
|
||||
override fun checkLightTree(
|
||||
element: FirAnonymousFunction,
|
||||
source: FirSourceElement,
|
||||
source: FirLightSourceElement,
|
||||
context: CheckerContext,
|
||||
reporter: DiagnosticReporter
|
||||
) {
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ object FirCommaInWhenConditionChecker : FirExpressionSyntaxChecker<FirWhenExpres
|
||||
return element.subject == null
|
||||
}
|
||||
|
||||
override fun checkLightTree(
|
||||
override fun checkPsiOrLightTree(
|
||||
element: FirWhenExpression,
|
||||
source: FirSourceElement,
|
||||
context: CheckerContext,
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ object FirConfusingWhenBranchSyntaxChecker : FirExpressionSyntaxChecker<FirWhenE
|
||||
|
||||
override fun checkLightTree(
|
||||
element: FirWhenExpression,
|
||||
source: FirSourceElement,
|
||||
source: FirLightSourceElement,
|
||||
context: CheckerContext,
|
||||
reporter: DiagnosticReporter
|
||||
) {
|
||||
|
||||
+2
-1
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.syntax
|
||||
|
||||
import org.jetbrains.kotlin.KtNodeTypes
|
||||
import org.jetbrains.kotlin.fir.FirLightSourceElement
|
||||
import org.jetbrains.kotlin.fir.FirPsiSourceElement
|
||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
@@ -39,7 +40,7 @@ object FirDelegationInInterfaceSyntaxChecker : FirDeclarationSyntaxChecker<FirRe
|
||||
|
||||
override fun checkLightTree(
|
||||
element: FirRegularClass,
|
||||
source: FirSourceElement,
|
||||
source: FirLightSourceElement,
|
||||
context: CheckerContext,
|
||||
reporter: DiagnosticReporter
|
||||
) {
|
||||
|
||||
+8
-6
@@ -9,9 +9,7 @@ import org.jetbrains.kotlin.KtNodeTypes
|
||||
import org.jetbrains.kotlin.config.AnalysisFlags
|
||||
import org.jetbrains.kotlin.config.ExplicitApiMode
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.fir.FirFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.fir.FirRealSourceElementKind
|
||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||
import org.jetbrains.kotlin.fir.*
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.isLocalMember
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||
@@ -23,7 +21,6 @@ import org.jetbrains.kotlin.fir.declarations.impl.FirPrimaryConstructor
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.effectiveVisibility
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isData
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isOverride
|
||||
import org.jetbrains.kotlin.fir.languageVersionSettings
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.publishedApiEffectiveVisibility
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
@@ -32,7 +29,12 @@ object FirExplicitApiDeclarationChecker : FirDeclarationSyntaxChecker<FirDeclara
|
||||
private val codeFragmentTypes =
|
||||
setOf(KtNodeTypes.BLOCK_CODE_FRAGMENT, KtNodeTypes.EXPRESSION_CODE_FRAGMENT, KtNodeTypes.TYPE_CODE_FRAGMENT)
|
||||
|
||||
override fun checkLightTree(element: FirDeclaration, source: FirSourceElement, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
override fun checkPsiOrLightTree(
|
||||
element: FirDeclaration,
|
||||
source: FirSourceElement,
|
||||
context: CheckerContext,
|
||||
reporter: DiagnosticReporter
|
||||
) {
|
||||
if ((source.kind !is FirRealSourceElementKind && source.kind != FirFakeSourceElementKind.PropertyFromParameter) ||
|
||||
element !is FirMemberDeclaration
|
||||
) {
|
||||
@@ -143,4 +145,4 @@ object FirExplicitApiDeclarationChecker : FirDeclarationSyntaxChecker<FirDeclara
|
||||
// If current declaration is local or it's a member in a local declaration (local class, etc), then we do not require return type.
|
||||
return !declaration.isLocalMember && context.containingDeclarations.lastOrNull()?.isLocalMember != true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.syntax
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.fir.FirLightSourceElement
|
||||
import org.jetbrains.kotlin.fir.FirPsiSourceElement
|
||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
@@ -39,7 +40,7 @@ object FirFunctionTypeParametersSyntaxChecker : FirDeclarationSyntaxChecker<FirS
|
||||
|
||||
override fun checkLightTree(
|
||||
element: FirSimpleFunction,
|
||||
source: FirSourceElement,
|
||||
source: FirLightSourceElement,
|
||||
context: CheckerContext,
|
||||
reporter: DiagnosticReporter
|
||||
) {
|
||||
|
||||
+2
-5
@@ -6,16 +6,13 @@
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.syntax
|
||||
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.fir.FirFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.fir.FirPsiSourceElement
|
||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||
import org.jetbrains.kotlin.fir.*
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.typeParametersList
|
||||
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
||||
import org.jetbrains.kotlin.fir.languageVersionSettings
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtProperty
|
||||
|
||||
@@ -41,7 +38,7 @@ object FirLocalVariableTypeParametersSyntaxChecker : FirDeclarationSyntaxChecker
|
||||
|
||||
override fun checkLightTree(
|
||||
element: FirProperty,
|
||||
source: FirSourceElement,
|
||||
source: FirLightSourceElement,
|
||||
context: CheckerContext,
|
||||
reporter: DiagnosticReporter
|
||||
) {
|
||||
|
||||
+12
-9
@@ -18,7 +18,10 @@ import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
||||
|
||||
/**
|
||||
* Checker that heavily relies on source tree. So it should have different implementation for each tree variant
|
||||
* Checker that heavily relies on source tree. So it may have different implementation for each tree variant. Subclass should either
|
||||
*
|
||||
* - implement `checkPsiOrLightTree` in an AST-agnostic manner, or
|
||||
* - implement both `checkPsi` and `checkLightTree` if it's difficult to handle PSI and LT tree in a unified way.
|
||||
*/
|
||||
interface FirSyntaxChecker<in D : FirElement, P : PsiElement> {
|
||||
|
||||
@@ -34,18 +37,18 @@ interface FirSyntaxChecker<in D : FirElement, P : PsiElement> {
|
||||
|
||||
fun isApplicable(element: D, source: FirSourceElement): Boolean = true
|
||||
|
||||
/**
|
||||
* By default psi tree should be equivalent to light tree and can be processed the same way
|
||||
*/
|
||||
fun checkPsi(element: D, source: FirPsiSourceElement, psi: P, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
checkLightTree(element, source, context, reporter)
|
||||
checkPsiOrLightTree(element, source, context, reporter)
|
||||
}
|
||||
|
||||
/*
|
||||
accepts FirSourceElement instead of FirLightSourceElement because now they have the same interface
|
||||
and it allows to reuse LT check for psi tree
|
||||
fun checkLightTree(element: D, source: FirLightSourceElement, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
checkPsiOrLightTree(element, source, context, reporter)
|
||||
}
|
||||
|
||||
/**
|
||||
* By default psi tree should be equivalent to light tree and can be processed the same way.
|
||||
*/
|
||||
fun checkLightTree(element: D, source: FirSourceElement, context: CheckerContext, reporter: DiagnosticReporter)
|
||||
fun checkPsiOrLightTree(element: D, source: FirSourceElement, context: CheckerContext, reporter: DiagnosticReporter) {}
|
||||
}
|
||||
|
||||
abstract class FirDeclarationSyntaxChecker<in D : FirDeclaration, P : PsiElement> :
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ object FirTypeParameterSyntaxChecker : FirDeclarationSyntaxChecker<FirTypeParame
|
||||
}
|
||||
}
|
||||
|
||||
override fun checkLightTree(
|
||||
override fun checkPsiOrLightTree(
|
||||
element: FirTypeParameter,
|
||||
source: FirSourceElement,
|
||||
context: CheckerContext,
|
||||
|
||||
Reference in New Issue
Block a user