mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
2/2 EmptyRangeInspection: support rangeUntil operator
^KTIJ-22378 Fixed GitOrigin-RevId: 2d94ee8f6b91e1b32a7cb205ce7e43d0818a6201
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f30e8ca592
commit
e1de80a85b
+2
-3
@@ -33,15 +33,14 @@ abstract class AbstractRangeInspection : AbstractKotlinInspection() {
|
||||
val context = lazy { expression.analyze(BodyResolveMode.PARTIAL) }
|
||||
when (expression.getRangeBinaryExpressionType(context) ?: return) {
|
||||
RangeKtExpressionType.rangeTo -> visitRangeTo(expression, context.value, holder)
|
||||
RangeKtExpressionType.rangeUntil -> Unit
|
||||
RangeKtExpressionType.until, RangeKtExpressionType.rangeUntil -> visitUntilOrRangeUntil(expression, context.value, holder)
|
||||
RangeKtExpressionType.downTo -> visitDownTo(expression, context.value, holder)
|
||||
RangeKtExpressionType.until -> visitUntil(expression, context.value, holder)
|
||||
}
|
||||
}
|
||||
|
||||
abstract fun visitRangeTo(expression: KtExpression, context: BindingContext, holder: ProblemsHolder)
|
||||
|
||||
abstract fun visitUntil(expression: KtExpression, context: BindingContext, holder: ProblemsHolder)
|
||||
abstract fun visitUntilOrRangeUntil(expression: KtExpression, context: BindingContext, holder: ProblemsHolder)
|
||||
|
||||
abstract fun visitDownTo(expression: KtExpression, context: BindingContext, holder: ProblemsHolder)
|
||||
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ class EmptyRangeInspection : AbstractRangeInspection() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitUntil(expression: KtExpression, context: BindingContext, holder: ProblemsHolder) {
|
||||
override fun visitUntilOrRangeUntil(expression: KtExpression, context: BindingContext, holder: ProblemsHolder) {
|
||||
expression.startAndEndValueSignedOrNull(context)?.let { (startValue, endValue) ->
|
||||
when {
|
||||
startValue > endValue -> holder.registerProblem(expression, downTo = true)
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ class ReplaceRangeToWithUntilInspection : AbstractRangeInspection() {
|
||||
)
|
||||
}
|
||||
|
||||
override fun visitUntil(expression: KtExpression, context: BindingContext, holder: ProblemsHolder) {
|
||||
override fun visitUntilOrRangeUntil(expression: KtExpression, context: BindingContext, holder: ProblemsHolder) {
|
||||
}
|
||||
|
||||
override fun visitDownTo(expression: KtExpression, context: BindingContext, holder: ProblemsHolder) {
|
||||
|
||||
+10
@@ -4660,6 +4660,16 @@ public abstract class LocalInspectionTestGenerated extends AbstractLocalInspecti
|
||||
runTest("testData/inspectionsLocal/emptyRange/downTo2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("rangeUntil.kt")
|
||||
public void testRangeUntil() throws Exception {
|
||||
runTest("testData/inspectionsLocal/emptyRange/rangeUntil.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("rangeUntil2.kt")
|
||||
public void testRangeUntil2() throws Exception {
|
||||
runTest("testData/inspectionsLocal/emptyRange/rangeUntil2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
runTest("testData/inspectionsLocal/emptyRange/simple.kt");
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
// PROBLEM: This range is empty. Did you mean to use 'downTo'?
|
||||
// WITH_STDLIB
|
||||
fun test() {
|
||||
<caret>0..<-1
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// PROBLEM: This range is empty. Did you mean to use 'downTo'?
|
||||
// WITH_STDLIB
|
||||
fun test() {
|
||||
<caret>0 downTo -1
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// PROBLEM: This range is empty. Did you mean to use 'rangeTo'?
|
||||
// WITH_STDLIB
|
||||
fun test() {
|
||||
<caret>0..<0
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// PROBLEM: This range is empty. Did you mean to use 'rangeTo'?
|
||||
// WITH_STDLIB
|
||||
fun test() {
|
||||
<caret>0..0
|
||||
}
|
||||
Reference in New Issue
Block a user