Add accessor intention: don't suggest if property has @JvmField annotation #KT-27139 Fixed

This commit is contained in:
Toshiaki Kameyama
2018-09-27 01:08:33 +09:00
committed by Mikhail Glukhikh
parent 27dc160aef
commit 3866c85a34
5 changed files with 38 additions and 1 deletions
@@ -22,7 +22,10 @@ import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
import org.jetbrains.kotlin.idea.refactoring.isAbstract
import org.jetbrains.kotlin.idea.util.findAnnotation
import org.jetbrains.kotlin.idea.util.hasJvmFieldAnnotation
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtProperty
import org.jetbrains.kotlin.psi.KtPsiFactory
@@ -34,7 +37,8 @@ abstract class AbstractAddAccessorsIntention(
override fun applicabilityRange(element: KtProperty): TextRange? {
if (element.isLocal || element.isAbstract() || element.hasDelegate() ||
element.hasModifier(KtTokens.LATEINIT_KEYWORD) ||
element.hasModifier(KtTokens.CONST_KEYWORD)
element.hasModifier(KtTokens.CONST_KEYWORD) ||
element.hasJvmFieldAnnotation()
) {
return null
}
@@ -0,0 +1,6 @@
// IS_APPLICABLE: false
// WITH_RUNTIME
class Test {
@JvmField
var <caret>foo = 1
}
@@ -0,0 +1,6 @@
// IS_APPLICABLE: false
// WITH_RUNTIME
class Test {
@JvmField
val <caret>foo = 1
}
@@ -0,0 +1,6 @@
// IS_APPLICABLE: false
// WITH_RUNTIME
class Test {
@JvmField
var <caret>foo = 1
}
@@ -1485,6 +1485,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
runTest("idea/testData/intentions/addPropertyAccessors/both/hasSetter.kt");
}
@TestMetadata("jvmField.kt")
public void testJvmField() throws Exception {
runTest("idea/testData/intentions/addPropertyAccessors/both/jvmField.kt");
}
@TestMetadata("lateinit.kt")
public void testLateinit() throws Exception {
runTest("idea/testData/intentions/addPropertyAccessors/both/lateinit.kt");
@@ -1558,6 +1563,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
runTest("idea/testData/intentions/addPropertyAccessors/getter/header.kt");
}
@TestMetadata("jvmField.kt")
public void testJvmField() throws Exception {
runTest("idea/testData/intentions/addPropertyAccessors/getter/jvmField.kt");
}
@TestMetadata("lateinit.kt")
public void testLateinit() throws Exception {
runTest("idea/testData/intentions/addPropertyAccessors/getter/lateinit.kt");
@@ -1626,6 +1636,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
runTest("idea/testData/intentions/addPropertyAccessors/setter/hasSetter.kt");
}
@TestMetadata("jvmField.kt")
public void testJvmField() throws Exception {
runTest("idea/testData/intentions/addPropertyAccessors/setter/jvmField.kt");
}
@TestMetadata("lateinit.kt")
public void testLateinit() throws Exception {
runTest("idea/testData/intentions/addPropertyAccessors/setter/lateinit.kt");