"Create member function" quick fix: do not add redundant semicolons after enum entry

#KT-14899 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-09-12 18:01:12 +09:00
committed by Dmitry Gridin
parent 0497f0cba4
commit 44edd94fea
6 changed files with 54 additions and 3 deletions
@@ -60,10 +60,11 @@ private class Visitor(var range: TextRange) : KtTreeVisitorVoid() {
prevEntry.add(comma)
delta += comma.textLength
}
}
else {
} else {
val lastEntry = klass.declarations.lastIsInstanceOrNull<KtEnumEntry>()
if (lastEntry != null && lastEntry.containsToken(KtTokens.SEMICOLON)) return
if (lastEntry != null &&
(lastEntry.containsToken(KtTokens.SEMICOLON) || lastEntry.nextSibling?.node?.elementType == KtTokens.SEMICOLON)
) return
if (lastEntry == null && classBody.containsToken(KtTokens.SEMICOLON)) return
val semicolon = psiFactory.createSemicolon()
@@ -0,0 +1,8 @@
// "Create member function 'Bar.foo'" "true"
fun foo() {
Bar.BAZ.<caret>foo()
}
enum class Bar {
BAZ
}
@@ -0,0 +1,12 @@
// "Create member function 'Bar.foo'" "true"
fun foo() {
Bar.BAZ.foo()
}
enum class Bar {
BAZ;
fun foo() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
@@ -0,0 +1,8 @@
// "Create member function 'Bar.foo'" "true"
fun foo() {
Bar.BAZ.<caret>foo()
}
enum class Bar {
BAZ;
}
@@ -0,0 +1,12 @@
// "Create member function 'Bar.foo'" "true"
fun foo() {
Bar.BAZ.foo()
}
enum class Bar {
BAZ;
fun foo() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
@@ -3792,6 +3792,16 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
runTest("idea/testData/quickfix/createFromUsage/createFunction/call/funOnClassObject.kt");
}
@TestMetadata("funOnEnumClass.kt")
public void testFunOnEnumClass() throws Exception {
runTest("idea/testData/quickfix/createFromUsage/createFunction/call/funOnEnumClass.kt");
}
@TestMetadata("funOnEnumClass2.kt")
public void testFunOnEnumClass2() throws Exception {
runTest("idea/testData/quickfix/createFromUsage/createFunction/call/funOnEnumClass2.kt");
}
@TestMetadata("funOnLibObject.kt")
public void testFunOnLibObject() throws Exception {
runTest("idea/testData/quickfix/createFromUsage/createFunction/call/funOnLibObject.kt");