"Convert property to function" intention: don't suggest if property has @JvmField annotation #KT-27157 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
487b1e96be
commit
749fd5dd80
@@ -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.executeWriteCommand
|
||||||
import org.jetbrains.kotlin.idea.util.application.progressIndicatorNullable
|
import org.jetbrains.kotlin.idea.util.application.progressIndicatorNullable
|
||||||
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
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.incremental.components.NoLookupLocation
|
||||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||||
import org.jetbrains.kotlin.psi.KtCallableReferenceExpression
|
import org.jetbrains.kotlin.psi.KtCallableReferenceExpression
|
||||||
@@ -192,7 +193,11 @@ class ConvertPropertyToFunctionIntention : SelfTargetingIntention<KtProperty>(Kt
|
|||||||
override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean {
|
override fun isApplicableTo(element: KtProperty, caretOffset: Int): Boolean {
|
||||||
val identifier = element.nameIdentifier ?: return false
|
val identifier = element.nameIdentifier ?: return false
|
||||||
if (!identifier.textRange.containsOffset(caretOffset)) 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?) {
|
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");
|
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")
|
@TestMetadata("otherRefs.kt")
|
||||||
public void testOtherRefs() throws Exception {
|
public void testOtherRefs() throws Exception {
|
||||||
runTest("idea/testData/intentions/convertPropertyToFunction/otherRefs.kt");
|
runTest("idea/testData/intentions/convertPropertyToFunction/otherRefs.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user