Reformat ReplaceRangeToWithUntilInspection
This commit is contained in:
committed by
Mikhail Glukhikh
parent
9c468ef2aa
commit
c183f0285d
@@ -29,20 +29,18 @@ import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.psi.createExpressionByPattern
|
||||
|
||||
class ReplaceRangeToWithUntilInspection : AbstractPrimitiveRangeToInspection() {
|
||||
|
||||
override fun visitRangeToExpression(expression: KtExpression, holder: ProblemsHolder) {
|
||||
if (expression.getArguments()?.second?.isMinusOne() != true) return
|
||||
|
||||
holder.registerProblem(
|
||||
expression,
|
||||
"'rangeTo' or the '..' call should be replaced with 'until'",
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||
ReplaceWithUntilQuickFix()
|
||||
expression,
|
||||
"'rangeTo' or the '..' call should be replaced with 'until'",
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||
ReplaceWithUntilQuickFix()
|
||||
)
|
||||
}
|
||||
|
||||
class ReplaceWithUntilQuickFix : LocalQuickFix {
|
||||
|
||||
override fun getName() = "Replace with until"
|
||||
|
||||
override fun getFamilyName() = name
|
||||
@@ -50,13 +48,14 @@ class ReplaceRangeToWithUntilInspection : AbstractPrimitiveRangeToInspection() {
|
||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||
val element = descriptor.psiElement as KtExpression
|
||||
val args = element.getArguments() ?: return
|
||||
element.replace(KtPsiFactory(element).createExpressionByPattern(
|
||||
element.replace(
|
||||
KtPsiFactory(element).createExpressionByPattern(
|
||||
"$0 until $1",
|
||||
args.first ?: return,
|
||||
(args.second as? KtBinaryExpression)?.left ?: return)
|
||||
(args.second as? KtBinaryExpression)?.left ?: return
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun KtExpression.isMinusOne(): Boolean {
|
||||
|
||||
Reference in New Issue
Block a user