[FIR] Let FirTopLevelFunctionsChecker run on all platforms

Use a session component to control platform specific suppression logic.
This commit is contained in:
Kirill Rakhman
2023-04-04 10:28:20 +02:00
committed by Space Team
parent 085df96afe
commit d6e14f37a7
9 changed files with 18 additions and 45 deletions
@@ -16,7 +16,7 @@ private fun FirDeclaration.isLexicallyInsideJsNative(context: CheckerContext): B
return JsStandardClassIds.Annotations.nativeAnnotations.any { hasAnnotationOrInsideAnnotatedClass(it, context.session) }
}
object FirJsPlatformDiagnosticSuppressor : FirPlatformDiagnosticSuppressor {
class FirJsPlatformDiagnosticSuppressor : FirPlatformDiagnosticSuppressor {
override fun shouldReportNoBody(declaration: FirCallableDeclaration, context: CheckerContext) =
!declaration.isLexicallyInsideJsNative(context)
}
@@ -40,7 +40,6 @@ object JsDeclarationCheckers : DeclarationCheckers() {
override val simpleFunctionCheckers: Set<FirSimpleFunctionChecker>
get() = setOf(
FirJsTopLevelFunctionsChecker,
FirJsNativeInvokeChecker,
FirJsNativeGetterChecker,
FirJsNativeSetterChecker,
@@ -1,13 +0,0 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.fir.analysis.js.checkers.declaration
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirTopLevelFunctionsChecker
import org.jetbrains.kotlin.fir.analysis.js.checkers.FirJsPlatformDiagnosticSuppressor
object FirJsTopLevelFunctionsChecker : FirTopLevelFunctionsChecker() {
override val suppressor = FirJsPlatformDiagnosticSuppressor
}
@@ -51,9 +51,4 @@ object JvmDeclarationCheckers : DeclarationCheckers() {
get() = setOf(
FirUpperBoundsChecker,
)
override val simpleFunctionCheckers: Set<FirSimpleFunctionChecker>
get() = setOf(
FirJvmTopLevelFunctionsChecker,
)
}
@@ -1,13 +0,0 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.fir.analysis.jvm.checkers.declaration
import org.jetbrains.kotlin.fir.analysis.checkers.FirPlatformDiagnosticSuppressor
import org.jetbrains.kotlin.fir.analysis.checkers.declaration.FirTopLevelFunctionsChecker
object FirJvmTopLevelFunctionsChecker : FirTopLevelFunctionsChecker() {
override val suppressor = FirPlatformDiagnosticSuppressor.Default
}
@@ -58,6 +58,7 @@ object CommonDeclarationCheckers : DeclarationCheckers() {
FirMemberFunctionsChecker,
FirDataObjectContentChecker,
ContractSyntaxV2FunctionChecker,
FirTopLevelFunctionsChecker,
)
override val propertyCheckers: Set<FirPropertyChecker>
@@ -5,13 +5,10 @@
package org.jetbrains.kotlin.fir.analysis.checkers
import org.jetbrains.kotlin.fir.FirSessionComponent
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
interface FirPlatformDiagnosticSuppressor {
interface FirPlatformDiagnosticSuppressor : FirSessionComponent {
fun shouldReportNoBody(declaration: FirCallableDeclaration, context: CheckerContext): Boolean
object Default : FirPlatformDiagnosticSuppressor {
override fun shouldReportNoBody(declaration: FirCallableDeclaration, context: CheckerContext): Boolean = true
}
}
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.analysis.checkers.declaration
import org.jetbrains.kotlin.KtFakeSourceElementKind
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.diagnostics.reportOn
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.analysis.checkers.FirPlatformDiagnosticSuppressor
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.checkers.hasModifier
@@ -18,10 +19,10 @@ import org.jetbrains.kotlin.fir.declarations.utils.isExpect
import org.jetbrains.kotlin.fir.declarations.utils.isExternal
import org.jetbrains.kotlin.lexer.KtTokens
// See old FE's [DeclarationsChecker]
abstract class FirTopLevelFunctionsChecker : FirSimpleFunctionChecker() {
abstract val suppressor: FirPlatformDiagnosticSuppressor
val FirSession.platformDiagnosticSuppressor: FirPlatformDiagnosticSuppressor? by FirSession.nullableSessionComponentAccessor()
// See old FE's [DeclarationsChecker]
object FirTopLevelFunctionsChecker : FirSimpleFunctionChecker() {
override fun check(declaration: FirSimpleFunction, context: CheckerContext, reporter: DiagnosticReporter) {
// Only report on top level callable declarations
if (context.containingDeclarations.size > 1) return
@@ -32,7 +33,10 @@ abstract class FirTopLevelFunctionsChecker : FirSimpleFunctionChecker() {
// So, our source of truth should be the full modifier list retrieved from the source.
if (declaration.hasModifier(KtTokens.ABSTRACT_KEYWORD)) return
if (declaration.isExternal) return
if (!declaration.hasBody && !declaration.isExpect && suppressor.shouldReportNoBody(declaration, context)) {
if (!declaration.hasBody &&
!declaration.isExpect &&
context.session.platformDiagnosticSuppressor?.shouldReportNoBody(declaration, context) != false
) {
reporter.reportOn(source, FirErrors.NON_MEMBER_FUNCTION_NO_BODY, declaration.symbol, context)
}