Do not report "reflection is not available" on built-in sources
This commit is contained in:
+13
@@ -17,10 +17,13 @@
|
|||||||
package org.jetbrains.kotlin.resolve.jvm.checkers
|
package org.jetbrains.kotlin.resolve.jvm.checkers
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement
|
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.builtins.ReflectionTypes
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||||
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
|
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) {
|
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
|
||||||
if (isReflectionAvailable) return
|
if (isReflectionAvailable) return
|
||||||
|
|
||||||
|
// Do not report the diagnostic on built-in sources
|
||||||
|
if (isReflectionSource(reportOn)) return
|
||||||
|
|
||||||
val descriptor = resolvedCall.resultingDescriptor
|
val descriptor = resolvedCall.resultingDescriptor
|
||||||
val containingClass = descriptor.containingDeclaration as? ClassDescriptor ?: return
|
val containingClass = descriptor.containingDeclaration as? ClassDescriptor ?: return
|
||||||
if (!ReflectionTypes.isReflectionClass(containingClass)) 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))
|
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() + "."))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user