Don't report as redundant 1st semicolon in enum without entries

So #KT-12524 Fixed
This commit is contained in:
Dmitry Neverov
2017-06-23 06:50:52 +03:00
committed by Mikhail Glukhikh
parent 3a606d13f0
commit 3e29f9ed5a
3 changed files with 58 additions and 0 deletions
@@ -25,6 +25,7 @@ import com.intellij.psi.PsiElementVisitor
import com.intellij.psi.PsiWhiteSpace
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getChildrenOfType
import org.jetbrains.kotlin.psi.psiUtil.nextLeaf
import org.jetbrains.kotlin.psi.psiUtil.prevLeaf
@@ -57,6 +58,16 @@ class RedundantSemicolonInspection : AbstractKotlinInspection(), CleanupLocalIns
if (semicolon.parent is KtEnumEntry) return false
(semicolon.parent.parent as? KtClass)?.let {
if (it.isEnum() && it.getChildrenOfType<KtEnumEntry>().isEmpty()) {
if (semicolon.prevLeaf { it !is PsiWhiteSpace && it !is PsiComment && !it.isLineBreak() }?.node?.elementType == KtTokens.LBRACE
&& it.declarations.isNotEmpty()) {
//first semicolon in enum with no entries, but with some declarations
return false
}
}
}
(semicolon.prevLeaf()?.parent as? KtLoopExpression)?.let {
if (it !is KtDoWhileExpression && it.body == null)
return false
+11
View File
@@ -36,4 +36,15 @@ fun baz(args: Array<String>) {
while (args.size > 0);
// But here redundant!
do while (args.size > 0);
}
enum class Foo {
; //not redundant
;
companion object;
;
}
enum class Bar {
; //redundant
}
@@ -78,4 +78,40 @@
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant semicolon</problem_class>
<description>Redundant semicolon</description>
</problem>
<problem>
<file>Test.kt</file>
<line>43</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/Test.kt" />
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant semicolon</problem_class>
<description>Redundant semicolon</description>
</problem>
<problem>
<file>Test.kt</file>
<line>44</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/Test.kt" />
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant semicolon</problem_class>
<description>Redundant semicolon</description>
</problem>
<problem>
<file>Test.kt</file>
<line>45</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/Test.kt" />
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant semicolon</problem_class>
<description>Redundant semicolon</description>
</problem>
<problem>
<file>Test.kt</file>
<line>49</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/Test.kt" />
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Redundant semicolon</problem_class>
<description>Redundant semicolon</description>
</problem>
</problems>