Do not report inspection "no reflection" in annotation entries
Annotation codegen shouldn't use something from reflection.jar
This commit is contained in:
@@ -45,6 +45,8 @@ import org.jetbrains.kotlin.psi.JetVisitorVoid
|
|||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.findClassAcrossModuleDependencies
|
import org.jetbrains.kotlin.serialization.deserialization.findClassAcrossModuleDependencies
|
||||||
import org.jetbrains.kotlin.builtins.ReflectionTypes
|
import org.jetbrains.kotlin.builtins.ReflectionTypes
|
||||||
|
import org.jetbrains.kotlin.psi.JetAnnotationEntry
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||||
import org.jetbrains.kotlin.utils.PathUtil
|
import org.jetbrains.kotlin.utils.PathUtil
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||||
import org.jetbrains.kotlin.utils.singletonOrEmptyList
|
import org.jetbrains.kotlin.utils.singletonOrEmptyList
|
||||||
@@ -75,6 +77,8 @@ public class ReflectionNotFoundInspection : AbstractKotlinInspection() {
|
|||||||
val expectedType = expression.analyze().get(BindingContext.EXPECTED_EXPRESSION_TYPE, expression)
|
val expectedType = expression.analyze().get(BindingContext.EXPECTED_EXPRESSION_TYPE, expression)
|
||||||
if (expectedType != null && !ReflectionTypes.isReflectionType(expectedType)) return
|
if (expectedType != null && !ReflectionTypes.isReflectionType(expectedType)) return
|
||||||
|
|
||||||
|
if (expression.getStrictParentOfType<JetAnnotationEntry>() != null) return
|
||||||
|
|
||||||
// If a callable reference is used where a KFunction/KProperty/... expected, we should report that usage as dangerous
|
// If a callable reference is used where a KFunction/KProperty/... expected, we should report that usage as dangerous
|
||||||
// because reflection features will fail without kotlin-reflect.jar in the classpath.
|
// because reflection features will fail without kotlin-reflect.jar in the classpath.
|
||||||
// If it's only used as a Function however (for example, "list.map(::function)"), we should not report anything
|
// If it's only used as a Function however (for example, "list.map(::function)"), we should not report anything
|
||||||
|
|||||||
@@ -15,4 +15,12 @@
|
|||||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Reflection not found</problem_class>
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Reflection not found</problem_class>
|
||||||
<description>Reflection not found in the classpath</description>
|
<description>Reflection not found in the classpath</description>
|
||||||
</problem>
|
</problem>
|
||||||
|
<problem>
|
||||||
|
<file>withinAnnotationEntry.kt</file>
|
||||||
|
<line>13</line>
|
||||||
|
<module>light_idea_test_case</module>
|
||||||
|
<entry_point TYPE="file" FQNAME="temp:///src/withinAnnotationEntry.kt" />
|
||||||
|
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Reflection not found</problem_class>
|
||||||
|
<description>Reflection not found in the classpath</description>
|
||||||
|
</problem>
|
||||||
</problems>
|
</problems>
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
|
annotation class A(val arg: KClass<*>, val args: Array<KClass<*>>, vararg val other: KClass<*>)
|
||||||
|
|
||||||
|
A(Int::class, array(String::class), Double::class, Char::class)
|
||||||
|
class MyClass {
|
||||||
|
throws(Exception::class)
|
||||||
|
fun foo() {
|
||||||
|
Exception::class
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user