Add accessors: determine header properties more correctly

Related to KT-17322
This commit is contained in:
Mikhail Glukhikh
2017-09-08 16:08:21 +03:00
parent 13775f8637
commit c4ebfe8e84
3 changed files with 17 additions and 1 deletions
@@ -19,6 +19,8 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.codeInsight.intention.LowPriorityAction
import com.intellij.openapi.editor.Editor
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.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtProperty
@@ -32,10 +34,12 @@ abstract class AbstractAddAccessorsIntention(
override fun applicabilityRange(element: KtProperty): TextRange? {
if (element.isLocal || element.isAbstract() || element.hasDelegate() ||
element.hasModifier(KtTokens.LATEINIT_KEYWORD) ||
element.hasModifier(KtTokens.HEADER_KEYWORD) ||
element.hasModifier(KtTokens.CONST_KEYWORD)) {
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 (addGetter && element.getter != null) return null
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);
}
@TestMetadata("header.kt")
public void testHeader() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/addPropertyAccessors/getter/header.kt");
doTest(fileName);
}
@TestMetadata("lateinit.kt")
public void testLateinit() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/addPropertyAccessors/getter/lateinit.kt");