"Convert property to function" intention: don't suggest if property has @JvmField annotation #KT-27157 Fixed

This commit is contained in:
Toshiaki Kameyama
2018-10-12 02:05:28 +09:00
committed by Mikhail Glukhikh
parent 487b1e96be
commit 749fd5dd80
3 changed files with 17 additions and 1 deletions
@@ -37,6 +37,7 @@ import org.jetbrains.kotlin.idea.runSynchronouslyWithProgress
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
import org.jetbrains.kotlin.idea.util.application.progressIndicatorNullable
import org.jetbrains.kotlin.idea.util.application.runReadAction
import org.jetbrains.kotlin.idea.util.hasJvmFieldAnnotation
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.psi.KtCallableReferenceExpression
@@ -192,7 +193,11 @@ class ConvertPropertyToFunctionIntention : SelfTargetingIntention<KtProperty>(Kt
override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean {
val identifier = element.nameIdentifier ?: return false
if (!identifier.textRange.containsOffset(caretOffset)) return false
return element.delegate == null && !element.isVar && !element.isLocal && (element.initializer == null || element.getter == null)
return element.delegate == null
&& !element.isVar
&& !element.isLocal
&& (element.initializer == null || element.getter == null)
&& !element.hasJvmFieldAnnotation()
}
override fun applyTo(element: KtProperty, editor: Editor?) {
@@ -0,0 +1,6 @@
// IS_APPLICABLE: false
// WITH_RUNTIME
class Test {
@JvmField
val foo<caret> = 1
}
@@ -6139,6 +6139,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
runTest("idea/testData/intentions/convertPropertyToFunction/javaUsages.kt");
}
@TestMetadata("jvmField.kt")
public void testJvmField() throws Exception {
runTest("idea/testData/intentions/convertPropertyToFunction/jvmField.kt");
}
@TestMetadata("otherRefs.kt")
public void testOtherRefs() throws Exception {
runTest("idea/testData/intentions/convertPropertyToFunction/otherRefs.kt");