Add inspection to detect non-const vals used as Java annotation args
So #KT-20615 Fixed
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module-library">
|
||||
<library>
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/lib/FakeJvmFieldConstant.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
</component>
|
||||
</module>
|
||||
Vendored
BIN
Binary file not shown.
+13
@@ -0,0 +1,13 @@
|
||||
public class JavaUser {
|
||||
// Dangerous
|
||||
@Ann(s = KotlinPropertiesKt.importantString)
|
||||
public void foo() {}
|
||||
|
||||
// Also dangerous
|
||||
@AnnValue(OtherPropertiesKt.notSoImportantString)
|
||||
public void bar() {}
|
||||
|
||||
// Safe
|
||||
@Ann(s = KotlinPropertiesKt.constantString)
|
||||
public void baz() {}
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
annotation class Ann(val s: String)
|
||||
|
||||
annotation class AnnValue(val value: String)
|
||||
|
||||
@JvmField val importantString = "important"
|
||||
|
||||
const val constantString = "constant"
|
||||
@@ -0,0 +1,20 @@
|
||||
<problems>
|
||||
<problem>
|
||||
<file>JavaUser.java</file>
|
||||
<line>3</line>
|
||||
<module>First</module>
|
||||
<package><default></package>
|
||||
<entry_point TYPE="file" FQNAME="file://C:/Users/Mikhail.Glukhikh/AppData/Local/Temp/unitTest_fakeJvmFieldConstant_FakeJvmFieldConstant/unitTest1/First/src/JavaUser.java" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Kotlin non-const property used as annotation argument</problem_class>
|
||||
<description>Use of @JvmField non-const Kotlin property as annotation argument is incorrect. Will be forbidden in 1.3</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>JavaUser.java</file>
|
||||
<line>7</line>
|
||||
<module>First</module>
|
||||
<package><default></package>
|
||||
<entry_point TYPE="file" FQNAME="file://C:/Users/Mikhail.Glukhikh/AppData/Local/Temp/unitTest_fakeJvmFieldConstant_FakeJvmFieldConstant/unitTest1/First/src/JavaUser.java" />
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Kotlin non-const property used as annotation argument</problem_class>
|
||||
<description>Use of @JvmField non-const Kotlin property as annotation argument is incorrect. Will be forbidden in 1.3</description>
|
||||
</problem>
|
||||
</problems>
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"inspectionClass": "org.jetbrains.kotlin.idea.inspections.FakeJvmFieldConstantInspection",
|
||||
"withRuntime": "true",
|
||||
"isMultiModule": "true"
|
||||
}
|
||||
Reference in New Issue
Block a user