From a92f0a0446c34a06ee7c92228969a476413fd1ff Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 19 Jul 2016 17:39:56 +0300 Subject: [PATCH] Do not report "reflection is not available" on built-in sources --- .../jvm/checkers/ReflectionAPICallChecker.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/ReflectionAPICallChecker.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/ReflectionAPICallChecker.kt index 98f0e645c70..502e5f35e37 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/ReflectionAPICallChecker.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/ReflectionAPICallChecker.kt @@ -17,10 +17,13 @@ package org.jetbrains.kotlin.resolve.jvm.checkers import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.builtins.KOTLIN_REFLECT_FQ_NAME +import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.ReflectionTypes import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.load.java.JvmAbi +import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext @@ -48,6 +51,9 @@ class ReflectionAPICallChecker(private val module: ModuleDescriptor, storageMana override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) { if (isReflectionAvailable) return + // Do not report the diagnostic on built-in sources + if (isReflectionSource(reportOn)) return + val descriptor = resolvedCall.resultingDescriptor val containingClass = descriptor.containingDeclaration as? ClassDescriptor ?: return if (!ReflectionTypes.isReflectionClass(containingClass)) return @@ -66,4 +72,11 @@ class ReflectionAPICallChecker(private val module: ModuleDescriptor, storageMana context.trace.report(NO_REFLECTION_IN_CLASS_PATH.on(reportOn)) } + + private fun isReflectionSource(reportOn: PsiElement): Boolean { + val file = reportOn.containingFile as? KtFile ?: return false + val fqName = file.packageFqName.toUnsafe() + return fqName.startsWith(KotlinBuiltIns.BUILT_INS_PACKAGE_NAME) && + (fqName == KOTLIN_REFLECT_FQ_NAME.toUnsafe() || fqName.asString().startsWith(KOTLIN_REFLECT_FQ_NAME.asString() + ".")) + } }