Add quickfix for INAPPLICABLE_JVM_FIELD

replaces with 'const' when possible

#KT-10981 Fixed
This commit is contained in:
Vyacheslav Gerasimov
2017-04-19 15:04:20 +03:00
parent 199bff7e70
commit dcae66a727
16 changed files with 207 additions and 0 deletions
@@ -0,0 +1,8 @@
// "Replace '@JvmField' with 'const'" "false"
// WITH_RUNTIME
// ERROR: JvmField has no effect on a private property
// ACTION: Move to constructor
// ACTION: Specify type explicitly
class Foo {
<caret>@JvmField private val a = "Lorem ipsum"
}
@@ -0,0 +1,7 @@
// "Replace '@JvmField' with 'const'" "true"
// WITH_RUNTIME
interface IFace {
companion object {
<caret>@JvmField val a = "Lorem ipsum"
}
}
@@ -0,0 +1,7 @@
// "Replace '@JvmField' with 'const'" "true"
// WITH_RUNTIME
interface IFace {
companion object {
const val a = "Lorem ipsum"
}
}
@@ -0,0 +1,8 @@
// "Replace '@JvmField' with 'const'" "false"
// WITH_RUNTIME
// ERROR: This annotation is not applicable to target 'top level property without backing field or delegate'
// ACTION: Make internal
// ACTION: Make private
// ACTION: Remove explicit type specification
<caret>@JvmField val number: Int
get() = 42
@@ -0,0 +1,6 @@
// "Replace '@JvmField' with 'const'" "false"
// WITH_RUNTIME
// ERROR: JvmField has no effect on a private property
// ACTION: Remove explicit type specification
fun getText() = ""
<caret>@JvmField private val text: String = getText()
@@ -0,0 +1,5 @@
// "Replace '@JvmField' with 'const'" "false"
// WITH_RUNTIME
// ERROR: JvmField has no effect on a private property
// ACTION: Remove explicit type specification
<caret>@JvmField private val number: Int? = 42
@@ -0,0 +1,5 @@
// "Replace '@JvmField' with 'const'" "true"
// WITH_RUNTIME
object Foo {
<caret>@JvmField private val a = "Lorem ipsum"
}
@@ -0,0 +1,5 @@
// "Replace '@JvmField' with 'const'" "true"
// WITH_RUNTIME
object Foo {
const private val a = "Lorem ipsum"
}
@@ -0,0 +1,4 @@
// "Replace '@JvmField' with 'const'" "true"
// WITH_RUNTIME
const val three = 3
<caret>@JvmField private val text = "${2 + three}"
@@ -0,0 +1,4 @@
// "Replace '@JvmField' with 'const'" "true"
// WITH_RUNTIME
const val three = 3
const private val text = "${2 + three}"
@@ -0,0 +1,7 @@
// "Replace '@JvmField' with 'const'" "false"
// WITH_RUNTIME
// ERROR: JvmField has no effect on a private property
// ACTION: Add 'const' modifier
// ACTION: Specify type explicitly
val three = 3
<caret>@JvmField private val text = "${2 + three}"
@@ -0,0 +1,3 @@
// "Replace '@JvmField' with 'const'" "true"
// WITH_RUNTIME
<caret>@JvmField private val number: Int = 42
@@ -0,0 +1,3 @@
// "Replace '@JvmField' with 'const'" "true"
// WITH_RUNTIME
const private val number: Int = 42