"Create enum constant" quick fix: add before semicolon
#KT-33718 Fixed
This commit is contained in:
committed by
Dmitry Gridin
parent
30c41e6720
commit
0497f0cba4
@@ -40,8 +40,9 @@ private class Visitor(var range: TextRange) : KtTreeVisitorVoid() {
|
|||||||
|
|
||||||
var delta = 0
|
var delta = 0
|
||||||
|
|
||||||
|
val psiFactory = KtPsiFactory(klass)
|
||||||
if (declaration is KtEnumEntry) {
|
if (declaration is KtEnumEntry) {
|
||||||
val comma = KtPsiFactory(klass).createComma()
|
val comma = psiFactory.createComma()
|
||||||
|
|
||||||
val nextEntry = declaration.nextSiblingOfSameType()
|
val nextEntry = declaration.nextSiblingOfSameType()
|
||||||
if (nextEntry != null && !declaration.containsToken(KtTokens.COMMA)) {
|
if (nextEntry != null && !declaration.containsToken(KtTokens.COMMA)) {
|
||||||
@@ -51,6 +52,11 @@ private class Visitor(var range: TextRange) : KtTreeVisitorVoid() {
|
|||||||
|
|
||||||
val prevEntry = declaration.prevSiblingOfSameType()
|
val prevEntry = declaration.prevSiblingOfSameType()
|
||||||
if (prevEntry != null && !prevEntry.containsToken(KtTokens.COMMA)) {
|
if (prevEntry != null && !prevEntry.containsToken(KtTokens.COMMA)) {
|
||||||
|
val semicolon = prevEntry.allChildren.firstOrNull { it.node?.elementType == KtTokens.SEMICOLON }
|
||||||
|
if (semicolon != null) {
|
||||||
|
semicolon.delete()
|
||||||
|
declaration.add(psiFactory.createSemicolon())
|
||||||
|
}
|
||||||
prevEntry.add(comma)
|
prevEntry.add(comma)
|
||||||
delta += comma.textLength
|
delta += comma.textLength
|
||||||
}
|
}
|
||||||
@@ -60,7 +66,7 @@ private class Visitor(var range: TextRange) : KtTreeVisitorVoid() {
|
|||||||
if (lastEntry != null && lastEntry.containsToken(KtTokens.SEMICOLON)) return
|
if (lastEntry != null && lastEntry.containsToken(KtTokens.SEMICOLON)) return
|
||||||
if (lastEntry == null && classBody.containsToken(KtTokens.SEMICOLON)) return
|
if (lastEntry == null && classBody.containsToken(KtTokens.SEMICOLON)) return
|
||||||
|
|
||||||
val semicolon = KtPsiFactory(klass).createSemicolon()
|
val semicolon = psiFactory.createSemicolon()
|
||||||
classBody.addAfter(semicolon, lastEntry)
|
classBody.addAfter(semicolon, lastEntry)
|
||||||
delta += semicolon.textLength
|
delta += semicolon.textLength
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+13
@@ -0,0 +1,13 @@
|
|||||||
|
// "Create enum constant 'D'" "true"
|
||||||
|
enum class Test {
|
||||||
|
A,
|
||||||
|
B,
|
||||||
|
C;
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
Test.D<caret>
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
// "Create enum constant 'D'" "true"
|
||||||
|
enum class Test {
|
||||||
|
A,
|
||||||
|
B,
|
||||||
|
C,
|
||||||
|
<caret>D;
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
Test.D
|
||||||
|
}
|
||||||
@@ -3295,6 +3295,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
runTest("idea/testData/quickfix/createFromUsage/createClass/referenceExpression/enumEntryHasNoLineBreak.kt");
|
runTest("idea/testData/quickfix/createFromUsage/createClass/referenceExpression/enumEntryHasNoLineBreak.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("enumEntryHasSemicolon.kt")
|
||||||
|
public void testEnumEntryHasSemicolon() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/createFromUsage/createClass/referenceExpression/enumEntryHasSemicolon.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("enumEntryNoReceiver.kt")
|
@TestMetadata("enumEntryNoReceiver.kt")
|
||||||
public void testEnumEntryNoReceiver() throws Exception {
|
public void testEnumEntryNoReceiver() throws Exception {
|
||||||
runTest("idea/testData/quickfix/createFromUsage/createClass/referenceExpression/enumEntryNoReceiver.kt");
|
runTest("idea/testData/quickfix/createFromUsage/createClass/referenceExpression/enumEntryNoReceiver.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user