[JS FIR] Implement FirJsReflectionAPICallChecker diagnostic
^KT-60899 Fixed
This commit is contained in:
committed by
Space Team
parent
af7eb8b7af
commit
d5aaa29a7f
+1
@@ -20,6 +20,7 @@ object JsExpressionCheckers : ExpressionCheckers() {
|
||||
get() = setOf(
|
||||
FirJsDefinedExternallyCallChecker,
|
||||
FirJsNativeRttiChecker,
|
||||
FirJsReflectionAPICallChecker
|
||||
)
|
||||
|
||||
override val functionCallCheckers: Set<FirFunctionCallChecker>
|
||||
|
||||
+33
@@ -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)
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -51,7 +51,7 @@ abstract class AbstractFirReflectionApiCallChecker : FirBasicExpressionChecker()
|
||||
}
|
||||
}
|
||||
|
||||
private fun isAllowedReflectionApi(name: Name, containingClassId: ClassId, context: CheckerContext): Boolean =
|
||||
protected open fun isAllowedReflectionApi(name: Name, containingClassId: ClassId, context: CheckerContext): Boolean =
|
||||
name in ALLOWED_MEMBER_NAMES ||
|
||||
containingClassId == K_CLASS && isAllowedKClassMember(name, context) ||
|
||||
(name.asString() == "get" || name.asString() == "set") && containingClassId in K_PROPERTY_CLASSES ||
|
||||
|
||||
-50
@@ -1,50 +0,0 @@
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION
|
||||
import kotlin.reflect.*
|
||||
|
||||
class Foo(val prop: Any) {
|
||||
fun func() {}
|
||||
}
|
||||
|
||||
fun testSomeValidCases(p0: KProperty0<Int>, pm0: KMutableProperty0<String>, f: KFunction<String>, p1: KProperty1<String, Int>, p2: KProperty2<String, String, Int>) {
|
||||
Foo::prop
|
||||
Foo::func
|
||||
Foo::class
|
||||
p0.get()
|
||||
p0.name
|
||||
pm0.set("")
|
||||
f.name
|
||||
p1.get("")
|
||||
p2.get("", "")
|
||||
(Foo::func).invoke(Foo(""))
|
||||
(Foo::func)(Foo(""))
|
||||
|
||||
p0 == pm0
|
||||
p1.equals(p2)
|
||||
p0.hashCode()
|
||||
f.toString()
|
||||
}
|
||||
|
||||
fun <T : Any> kclass(k: KClass<*>, kt: KClass<T>) {
|
||||
k.simpleName
|
||||
k.qualifiedName
|
||||
k.<!UNRESOLVED_REFERENCE!>members<!>
|
||||
k.<!UNRESOLVED_REFERENCE!>constructors<!>
|
||||
k.<!UNRESOLVED_REFERENCE!>nestedClasses<!>
|
||||
k.<!UNRESOLVED_REFERENCE!>objectInstance<!>
|
||||
k.<!UNRESOLVED_REFERENCE!>typeParameters<!>
|
||||
k.<!UNRESOLVED_REFERENCE!>supertypes<!>
|
||||
k.<!UNRESOLVED_REFERENCE!>visibility<!>
|
||||
k.<!UNRESOLVED_REFERENCE!>isFinal<!>
|
||||
k.<!UNRESOLVED_REFERENCE!>isOpen<!>
|
||||
k.<!UNRESOLVED_REFERENCE!>isAbstract<!>
|
||||
k.<!UNRESOLVED_REFERENCE!>isSealed<!>
|
||||
k.<!UNRESOLVED_REFERENCE!>isData<!>
|
||||
k.<!UNRESOLVED_REFERENCE!>isInner<!>
|
||||
k.<!UNRESOLVED_REFERENCE!>isCompanion<!>
|
||||
|
||||
k.<!UNRESOLVED_REFERENCE!>annotations<!>
|
||||
|
||||
k == kt
|
||||
k.hashCode()
|
||||
k.toString()
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION
|
||||
import kotlin.reflect.*
|
||||
|
||||
|
||||
Reference in New Issue
Block a user