"Split property declaration" intention: do not suggest in 'when' subject
#KT-35528 Fixed
This commit is contained in:
committed by
Dmitry Gridin
parent
eab6864269
commit
1cdcef3b08
+3
-1
@@ -11,12 +11,14 @@ import com.intellij.openapi.util.TextRange
|
|||||||
import org.jetbrains.kotlin.idea.intentions.SelfTargetingRangeIntention
|
import org.jetbrains.kotlin.idea.intentions.SelfTargetingRangeIntention
|
||||||
import org.jetbrains.kotlin.idea.intentions.splitPropertyDeclaration
|
import org.jetbrains.kotlin.idea.intentions.splitPropertyDeclaration
|
||||||
import org.jetbrains.kotlin.psi.KtProperty
|
import org.jetbrains.kotlin.psi.KtProperty
|
||||||
|
import org.jetbrains.kotlin.psi.KtWhenEntry
|
||||||
|
import org.jetbrains.kotlin.psi.KtWhenExpression
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||||
|
|
||||||
class SplitPropertyDeclarationIntention : SelfTargetingRangeIntention<KtProperty>(KtProperty::class.java, "Split property declaration"),
|
class SplitPropertyDeclarationIntention : SelfTargetingRangeIntention<KtProperty>(KtProperty::class.java, "Split property declaration"),
|
||||||
LowPriorityAction {
|
LowPriorityAction {
|
||||||
override fun applicabilityRange(element: KtProperty): TextRange? {
|
override fun applicabilityRange(element: KtProperty): TextRange? {
|
||||||
if (!element.isLocal) return null
|
if (!element.isLocal || element.parent is KtWhenExpression) return null
|
||||||
val initializer = element.initializer ?: return null
|
val initializer = element.initializer ?: return null
|
||||||
return TextRange(element.startOffset, initializer.startOffset)
|
return TextRange(element.startOffset, initializer.startOffset)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
enum class Type {
|
||||||
|
HYDRO,
|
||||||
|
PYRO
|
||||||
|
}
|
||||||
|
|
||||||
|
fun select(t: Type): Int {
|
||||||
|
return when (<caret>val i = t.ordinal) {
|
||||||
|
0 -> 1
|
||||||
|
1 -> 42
|
||||||
|
else -> i
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8100,6 +8100,11 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
public void testSimpleInitWithType2() throws Exception {
|
public void testSimpleInitWithType2() throws Exception {
|
||||||
runTest("idea/testData/intentions/declarations/split/simpleInitWithType2.kt");
|
runTest("idea/testData/intentions/declarations/split/simpleInitWithType2.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("whenSubject.kt")
|
||||||
|
public void testWhenSubject() throws Exception {
|
||||||
|
runTest("idea/testData/intentions/declarations/split/whenSubject.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user