Redundant semicolon: fix false positive between modifier and declaration

#KT-25579 Fixed
This commit is contained in:
Toshiaki Kameyama
2018-07-24 04:34:10 +03:00
committed by Mikhail Glukhikh
parent 1898df3fb7
commit 2bf3b435f2
7 changed files with 53 additions and 0 deletions
@@ -24,6 +24,7 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.PsiElementVisitor
import com.intellij.psi.PsiWhiteSpace
import org.jetbrains.kotlin.kdoc.psi.api.KDoc
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.*
@@ -86,6 +87,11 @@ class RedundantSemicolonInspection : AbstractKotlinInspection(), CleanupLocalIns
return false
}
val prevNameReference = semicolon.getPrevSiblingIgnoringWhitespaceAndComments() as? KtNameReferenceExpression
if (prevNameReference != null && prevNameReference.text in softModifierKeywords
&& semicolon.getNextSiblingIgnoringWhitespaceAndComments() is KtDeclaration
) return false
return true
}
@@ -112,4 +118,6 @@ class RedundantSemicolonInspection : AbstractKotlinInspection(), CleanupLocalIns
descriptor.psiElement.delete()
}
}
private val softModifierKeywords = KtTokens.SOFT_KEYWORDS.types.mapNotNull { (it as? KtModifierKeywordToken)?.toString() }
}