[JS FIR] Implement FirJsReflectionAPICallChecker diagnostic

^KT-60899 Fixed
This commit is contained in:
Alexander Korepanov
2023-11-29 12:39:15 +01:00
committed by Space Team
parent af7eb8b7af
commit d5aaa29a7f
8 changed files with 47 additions and 60 deletions
@@ -20,6 +20,7 @@ object JsExpressionCheckers : ExpressionCheckers() {
get() = setOf(
FirJsDefinedExternallyCallChecker,
FirJsNativeRttiChecker,
FirJsReflectionAPICallChecker
)
override val functionCallCheckers: Set<FirFunctionCallChecker>
@@ -0,0 +1,33 @@
/*
* 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.expression
import org.jetbrains.kotlin.KtSourceElement
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
import org.jetbrains.kotlin.diagnostics.reportOn
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
import org.jetbrains.kotlin.fir.analysis.checkers.expression.AbstractFirReflectionApiCallChecker
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.name.StandardClassIds
object FirJsReflectionAPICallChecker : AbstractFirReflectionApiCallChecker() {
override fun isWholeReflectionApiAvailable(context: CheckerContext): Boolean {
return false
}
override fun isAllowedReflectionApi(name: Name, containingClassId: ClassId, context: CheckerContext): Boolean {
return super.isAllowedReflectionApi(name, containingClassId, context) ||
containingClassId in StandardClassIds.associatedObjectAnnotations ||
name == StandardNames.FqNames.findAssociatedObject.shortName()
}
override fun report(source: KtSourceElement?, context: CheckerContext, reporter: DiagnosticReporter) {
reporter.reportOn(source, FirErrors.UNSUPPORTED, "This reflection API is not supported yet in JavaScript", context)
}
}