Detection of semicolon between enum entries together with the correct delimiter quick fix for this case.

Error message reported directly on semicolon.
This commit is contained in:
Mikhail Glukhikh
2015-05-12 15:31:04 +03:00
parent edd269f5ff
commit 983339e1c9
19 changed files with 387 additions and 8 deletions
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.intention.IntentionAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiErrorElement
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.quickfix.quickfixUtil.createIntentionFactory
import org.jetbrains.kotlin.idea.quickfix.quickfixUtil.createIntentionForFirstParentOfType
@@ -62,7 +63,11 @@ class DeprecatedEnumEntryDelimiterSyntaxFix(element: JetEnumEntry): JetIntention
var next = entry.getNextSiblingIgnoringWhitespaceAndComments()
var nextType = next?.getNode()?.getElementType()
if (entryIndex < entries.size() - 1) {
if (nextType != JetTokens.COMMA) {
if (next is PsiErrorElement && next.getFirstChild()?.getNode()?.getElementType() == JetTokens.SEMICOLON) {
// Fix for syntax error like ENUM_ENTRY1; ENUM_ENTRY2; ENUM_ENTRY3
next.replace(psiFactory.createComma())
}
else if (nextType != JetTokens.COMMA) {
// Classic case like ENUM_ENTRY1 ENUM_ENTRY2
body.addAfter(psiFactory.createComma(), entry)
}
@@ -0,0 +1,6 @@
// "Insert lacking comma(s) / semicolon(s)" "true"
enum class MyEnum {
A, B; C<caret> D,
fun foo() = 42
}
@@ -0,0 +1,6 @@
// "Insert lacking comma(s) / semicolon(s)" "true"
enum class MyEnum {
A, B, C<caret>, D;
fun foo() = 42
}
@@ -0,0 +1,6 @@
// "Insert lacking comma(s) / semicolon(s)" "true"
enum class MyEnum {
A<caret>; B; C; D;
fun foo() = 42
}
@@ -0,0 +1,6 @@
// "Insert lacking comma(s) / semicolon(s)" "true"
enum class MyEnum {
A<caret>, B, C, D;
fun foo() = 42
}
@@ -0,0 +1,6 @@
// "Insert lacking comma(s) / semicolon(s)" "true"
enum class MyEnum {
A; B; C<caret>; D
fun foo() = 42
}
@@ -0,0 +1,6 @@
// "Insert lacking comma(s) / semicolon(s)" "true"
enum class MyEnum {
A, B, C<caret>, D;
fun foo() = 42
}
@@ -3096,6 +3096,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest(fileName);
}
@TestMetadata("commaSemicolonDelimiter.kt")
public void testCommaSemicolonDelimiter() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/enumDelimiter/commaSemicolonDelimiter.kt");
doTest(fileName);
}
@TestMetadata("missedCommas.kt")
public void testMissedCommas() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/enumDelimiter/missedCommas.kt");
@@ -3150,6 +3156,18 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest(fileName);
}
@TestMetadata("semicolonDelimiter.kt")
public void testSemicolonDelimiter() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/enumDelimiter/semicolonDelimiter.kt");
doTest(fileName);
}
@TestMetadata("semicolonDelimiterExceptLast.kt")
public void testSemicolonDelimiterExceptLast() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/enumDelimiter/semicolonDelimiterExceptLast.kt");
doTest(fileName);
}
@TestMetadata("wholeProject.kt")
public void testWholeProject() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/enumDelimiter/wholeProject.kt");