From 809d518fcf4e086ddd13701adfaacf30d8661c34 Mon Sep 17 00:00:00 2001 From: Tianyu Geng Date: Fri, 24 Sep 2021 11:43:02 -0700 Subject: [PATCH] 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` --- .../RedundantModalityModifierSyntaxChecker.kt | 2 +- ...edundantVisibilityModifierSyntaxChecker.kt | 2 +- .../FirAnonymousFunctionSyntaxChecker.kt | 4 ++-- .../syntax/FirCommaInWhenConditionChecker.kt | 2 +- .../FirConfusingWhenBranchSyntaxChecker.kt | 2 +- .../FirDelegationInInterfaceSyntaxChecker.kt | 3 ++- .../FirExplicitApiDeclarationChecker.kt | 14 +++++++------ .../FirFunctionTypeParametersSyntaxChecker.kt | 3 ++- ...ocalVariableTypeParametersSyntaxChecker.kt | 7 ++----- .../checkers/syntax/FirSyntaxChecker.kt | 21 +++++++++++-------- .../syntax/FirTypeParameterSyntaxChecker.kt | 2 +- 11 files changed, 33 insertions(+), 29 deletions(-) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/RedundantModalityModifierSyntaxChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/RedundantModalityModifierSyntaxChecker.kt index 7d06008cee2..641c4d0640b 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/RedundantModalityModifierSyntaxChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/extended/RedundantModalityModifierSyntaxChecker.kt @@ -27,7 +27,7 @@ object RedundantModalityModifierSyntaxChecker : FirDeclarationSyntaxChecker() { - override fun checkLightTree( + override fun checkPsiOrLightTree( element: FirDeclaration, source: FirSourceElement, context: CheckerContext, diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/syntax/FirAnonymousFunctionSyntaxChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/syntax/FirAnonymousFunctionSyntaxChecker.kt index 1736bdee257..49f3fa46b96 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/syntax/FirAnonymousFunctionSyntaxChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/syntax/FirAnonymousFunctionSyntaxChecker.kt @@ -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 { @@ -34,18 +37,18 @@ interface FirSyntaxChecker { 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 : diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/syntax/FirTypeParameterSyntaxChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/syntax/FirTypeParameterSyntaxChecker.kt index 8d0bed13e87..cfe74f9635b 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/syntax/FirTypeParameterSyntaxChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/syntax/FirTypeParameterSyntaxChecker.kt @@ -35,7 +35,7 @@ object FirTypeParameterSyntaxChecker : FirDeclarationSyntaxChecker