FIR IDE: Add applicability range to HLAddAccessorIntention (copied from
FE 1.0's logic) and actually check the range in AbstractHLIntention.
This commit is contained in:
committed by
TeamCityServer
parent
a497dd1d31
commit
91e62832ee
@@ -26,6 +26,11 @@ abstract class AbstractHLIntention<PSI : KtElement, INPUT : HLApplicatorInput>(
|
||||
if (!applicator.isApplicableByPsi(element, project)) return false
|
||||
val ranges = applicabilityRange.getApplicabilityRanges(element)
|
||||
if (ranges.isEmpty()) return false
|
||||
|
||||
// An HLApplicabilityRange should be relative to the element, while `caretOffset` is absolute
|
||||
val relativeCaretOffset = caretOffset - element.textRange.startOffset
|
||||
if (ranges.none { it.containsOffset(relativeCaretOffset) }) return false
|
||||
|
||||
val input = getInput(element)
|
||||
if (input != null && input.isValidFor(element)) {
|
||||
setFamilyNameGetter(applicator::getFamilyName)
|
||||
|
||||
+4
-3
@@ -12,8 +12,8 @@ import org.jetbrains.kotlin.idea.api.applicator.applicator
|
||||
import org.jetbrains.kotlin.idea.fir.api.AbstractHLIntention
|
||||
import org.jetbrains.kotlin.idea.fir.api.applicator.HLApplicabilityRange
|
||||
import org.jetbrains.kotlin.idea.fir.api.applicator.HLApplicatorInputProvider
|
||||
import org.jetbrains.kotlin.idea.fir.api.applicator.applicabilityTarget
|
||||
import org.jetbrains.kotlin.idea.fir.api.applicator.inputProvider
|
||||
import org.jetbrains.kotlin.idea.fir.applicators.ApplicabilityRanges
|
||||
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtPropertySymbol
|
||||
import org.jetbrains.kotlin.idea.intentions.AbstractAddAccessorsIntention
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
@@ -26,8 +26,9 @@ import org.jetbrains.kotlin.psi.psiUtil.hasExpectModifier
|
||||
|
||||
abstract class HLAddAccessorIntention(private val addGetter: Boolean, private val addSetter: Boolean) :
|
||||
AbstractHLIntention<KtProperty, HLApplicatorInput.Empty>(KtProperty::class) {
|
||||
// TODO: Copy and test range from AddAccessorIntentions.applicabilityRange
|
||||
override val applicabilityRange: HLApplicabilityRange<KtProperty> = ApplicabilityRanges.SELF
|
||||
override val applicabilityRange: HLApplicabilityRange<KtProperty> = applicabilityTarget { ktProperty ->
|
||||
if (ktProperty.hasInitializer()) ktProperty.nameIdentifier else ktProperty
|
||||
}
|
||||
|
||||
override val applicator: HLApplicator<KtProperty, HLApplicatorInput.Empty> = applicator {
|
||||
applyTo { ktProperty, _, _, editor ->
|
||||
|
||||
Generated
+15
@@ -48,6 +48,11 @@ public class HLIntentionTestGenerated extends AbstractHLIntentionTest {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/intentions/addPropertyAccessors/both"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("caretNotOnName.kt")
|
||||
public void testCaretNotOnName() throws Exception {
|
||||
runTest("idea/testData/intentions/addPropertyAccessors/both/caretNotOnName.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("delegate.kt")
|
||||
public void testDelegate() throws Exception {
|
||||
runTest("idea/testData/intentions/addPropertyAccessors/both/delegate.kt");
|
||||
@@ -126,6 +131,11 @@ public class HLIntentionTestGenerated extends AbstractHLIntentionTest {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/intentions/addPropertyAccessors/getter"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("caretNotOnName.kt")
|
||||
public void testCaretNotOnName() throws Exception {
|
||||
runTest("idea/testData/intentions/addPropertyAccessors/getter/caretNotOnName.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("const.kt")
|
||||
public void testConst() throws Exception {
|
||||
runTest("idea/testData/intentions/addPropertyAccessors/getter/const.kt");
|
||||
@@ -209,6 +219,11 @@ public class HLIntentionTestGenerated extends AbstractHLIntentionTest {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/intentions/addPropertyAccessors/setter"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("caretNotOnName.kt")
|
||||
public void testCaretNotOnName() throws Exception {
|
||||
runTest("idea/testData/intentions/addPropertyAccessors/setter/caretNotOnName.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("delegate.kt")
|
||||
public void testDelegate() throws Exception {
|
||||
runTest("idea/testData/intentions/addPropertyAccessors/setter/delegate.kt");
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
// IS_APPLICABLE: false
|
||||
class Test {
|
||||
var x = <caret>1
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// IS_APPLICABLE: false
|
||||
class Test {
|
||||
val x = <caret>1
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// IS_APPLICABLE: false
|
||||
class Test {
|
||||
var x = <caret>1
|
||||
}
|
||||
@@ -1621,6 +1621,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/intentions/addPropertyAccessors/both"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("caretNotOnName.kt")
|
||||
public void testCaretNotOnName() throws Exception {
|
||||
runTest("idea/testData/intentions/addPropertyAccessors/both/caretNotOnName.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("delegate.kt")
|
||||
public void testDelegate() throws Exception {
|
||||
runTest("idea/testData/intentions/addPropertyAccessors/both/delegate.kt");
|
||||
@@ -1699,6 +1704,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/intentions/addPropertyAccessors/getter"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("caretNotOnName.kt")
|
||||
public void testCaretNotOnName() throws Exception {
|
||||
runTest("idea/testData/intentions/addPropertyAccessors/getter/caretNotOnName.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("const.kt")
|
||||
public void testConst() throws Exception {
|
||||
runTest("idea/testData/intentions/addPropertyAccessors/getter/const.kt");
|
||||
@@ -1782,6 +1792,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/intentions/addPropertyAccessors/setter"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("caretNotOnName.kt")
|
||||
public void testCaretNotOnName() throws Exception {
|
||||
runTest("idea/testData/intentions/addPropertyAccessors/setter/caretNotOnName.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("delegate.kt")
|
||||
public void testDelegate() throws Exception {
|
||||
runTest("idea/testData/intentions/addPropertyAccessors/setter/delegate.kt");
|
||||
|
||||
Reference in New Issue
Block a user