Add accessors: determine header properties more correctly
Related to KT-17322
This commit is contained in:
@@ -19,6 +19,8 @@ package org.jetbrains.kotlin.idea.intentions
|
|||||||
import com.intellij.codeInsight.intention.LowPriorityAction
|
import com.intellij.codeInsight.intention.LowPriorityAction
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.util.TextRange
|
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.refactoring.isAbstract
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.psi.KtProperty
|
import org.jetbrains.kotlin.psi.KtProperty
|
||||||
@@ -32,10 +34,12 @@ 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.HEADER_KEYWORD) ||
|
|
||||||
element.hasModifier(KtTokens.CONST_KEYWORD)) {
|
element.hasModifier(KtTokens.CONST_KEYWORD)) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
val descriptor = element.resolveToDescriptorIfAny() as? CallableMemberDescriptor ?: return null
|
||||||
|
if (descriptor.isHeader) return null
|
||||||
|
|
||||||
if (addSetter && (!element.isVar || element.setter != null)) return null
|
if (addSetter && (!element.isVar || element.setter != null)) return null
|
||||||
if (addGetter && element.getter != null) return null
|
if (addGetter && element.getter != null) return null
|
||||||
return element.nameIdentifier?.textRange
|
return element.nameIdentifier?.textRange
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// SKIP_ERRORS_BEFORE
|
||||||
|
// SKIP_ERRORS_AFTER
|
||||||
|
// IS_APPLICABLE: false
|
||||||
|
header class Header {
|
||||||
|
val <caret>x: Int
|
||||||
|
}
|
||||||
@@ -853,6 +853,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("header.kt")
|
||||||
|
public void testHeader() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/addPropertyAccessors/getter/header.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("lateinit.kt")
|
@TestMetadata("lateinit.kt")
|
||||||
public void testLateinit() throws Exception {
|
public void testLateinit() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/addPropertyAccessors/getter/lateinit.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/addPropertyAccessors/getter/lateinit.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user