[JS] Support typeOf
This commit is contained in:
+15
-6
@@ -23,19 +23,27 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.NotFoundClasses
|
||||
import org.jetbrains.kotlin.diagnostics.Errors.UNSUPPORTED
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.AbstractReflectionApiCallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.storage.getValue
|
||||
|
||||
private val ALLOWED_KCLASS_MEMBERS = setOf("simpleName", "isInstance")
|
||||
private val ALLOWED_CLASSES = setOf(
|
||||
FqName("kotlin.reflect.KType"),
|
||||
FqName("kotlin.reflect.KTypeProjection"),
|
||||
FqName("kotlin.reflect.KTypeProjection.Companion"),
|
||||
FqName("kotlin.reflect.KVariance")
|
||||
)
|
||||
|
||||
class JsReflectionAPICallChecker(
|
||||
module: ModuleDescriptor,
|
||||
private val reflectionTypes: ReflectionTypes,
|
||||
notFoundClasses: NotFoundClasses,
|
||||
storageManager: StorageManager
|
||||
module: ModuleDescriptor,
|
||||
private val reflectionTypes: ReflectionTypes,
|
||||
notFoundClasses: NotFoundClasses,
|
||||
storageManager: StorageManager
|
||||
) : AbstractReflectionApiCallChecker(module, notFoundClasses, storageManager) {
|
||||
override val isWholeReflectionApiAvailable: Boolean
|
||||
get() = false
|
||||
@@ -47,6 +55,7 @@ class JsReflectionAPICallChecker(
|
||||
private val kClass by storageManager.createLazyValue { reflectionTypes.kClass }
|
||||
|
||||
override fun isAllowedReflectionApi(descriptor: CallableDescriptor, containingClass: ClassDescriptor): Boolean =
|
||||
super.isAllowedReflectionApi(descriptor, containingClass) ||
|
||||
DescriptorUtils.isSubclass(containingClass, kClass) && descriptor.name.asString() in ALLOWED_KCLASS_MEMBERS
|
||||
super.isAllowedReflectionApi(descriptor, containingClass) ||
|
||||
DescriptorUtils.isSubclass(containingClass, kClass) && descriptor.name.asString() in ALLOWED_KCLASS_MEMBERS ||
|
||||
containingClass.fqNameSafe in ALLOWED_CLASSES
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user