Add accessor intention: don't suggest if property has @JvmField annotation #KT-27139 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
27dc160aef
commit
3866c85a34
@@ -22,7 +22,10 @@ import com.intellij.openapi.util.TextRange
|
|||||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
|
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
|
||||||
import org.jetbrains.kotlin.idea.refactoring.isAbstract
|
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.lexer.KtTokens
|
||||||
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.psi.KtProperty
|
import org.jetbrains.kotlin.psi.KtProperty
|
||||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||||
|
|
||||||
@@ -34,7 +37,8 @@ abstract class AbstractAddAccessorsIntention(
|
|||||||
override fun applicabilityRange(element: KtProperty): TextRange? {
|
override fun applicabilityRange(element: KtProperty): TextRange? {
|
||||||
if (element.isLocal || element.isAbstract() || element.hasDelegate() ||
|
if (element.isLocal || element.isAbstract() || element.hasDelegate() ||
|
||||||
element.hasModifier(KtTokens.LATEINIT_KEYWORD) ||
|
element.hasModifier(KtTokens.LATEINIT_KEYWORD) ||
|
||||||
element.hasModifier(KtTokens.CONST_KEYWORD)
|
element.hasModifier(KtTokens.CONST_KEYWORD) ||
|
||||||
|
element.hasJvmFieldAnnotation()
|
||||||
) {
|
) {
|
||||||
return null
|
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");
|
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")
|
@TestMetadata("lateinit.kt")
|
||||||
public void testLateinit() throws Exception {
|
public void testLateinit() throws Exception {
|
||||||
runTest("idea/testData/intentions/addPropertyAccessors/both/lateinit.kt");
|
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");
|
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")
|
@TestMetadata("lateinit.kt")
|
||||||
public void testLateinit() throws Exception {
|
public void testLateinit() throws Exception {
|
||||||
runTest("idea/testData/intentions/addPropertyAccessors/getter/lateinit.kt");
|
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");
|
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")
|
@TestMetadata("lateinit.kt")
|
||||||
public void testLateinit() throws Exception {
|
public void testLateinit() throws Exception {
|
||||||
runTest("idea/testData/intentions/addPropertyAccessors/setter/lateinit.kt");
|
runTest("idea/testData/intentions/addPropertyAccessors/setter/lateinit.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user