KT-5045: intention to convert between two comparisons and range check and vice versa
This commit is contained in:
committed by
Mikhail Glukhikh
parent
1040c97196
commit
6d6a16f399
+1
@@ -0,0 +1 @@
|
|||||||
|
fun foo(arg: Int) = 1 <= arg && arg <= 4
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
fun foo(arg: Int) = arg in 1..4
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
This intention converts range check (in) to two consecutive comparisons
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
fun foo(arg: Int) = arg in 1..4
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
fun foo(arg: Int) = 1 <= arg && arg <= 4
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
This intention converts two consecutive comparisons to range check (in)
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1469,6 +1469,16 @@
|
|||||||
<category>Kotlin</category>
|
<category>Kotlin</category>
|
||||||
</intentionAction>
|
</intentionAction>
|
||||||
|
|
||||||
|
<intentionAction>
|
||||||
|
<className>org.jetbrains.kotlin.idea.intentions.ConvertTwoComparisonsToRangeCheckIntention</className>
|
||||||
|
<category>Kotlin</category>
|
||||||
|
</intentionAction>
|
||||||
|
|
||||||
|
<intentionAction>
|
||||||
|
<className>org.jetbrains.kotlin.idea.intentions.ConvertRangeCheckToTwoComparisonsIntention</className>
|
||||||
|
<category>Kotlin</category>
|
||||||
|
</intentionAction>
|
||||||
|
|
||||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.intentions.ObjectLiteralToLambdaInspection"
|
<localInspection implementationClass="org.jetbrains.kotlin.idea.intentions.ObjectLiteralToLambdaInspection"
|
||||||
displayName="Object literal can be converted to lambda"
|
displayName="Object literal can be converted to lambda"
|
||||||
groupName="Kotlin"
|
groupName="Kotlin"
|
||||||
|
|||||||
+51
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.intentions
|
||||||
|
|
||||||
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
|
import org.jetbrains.kotlin.psi.*
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||||
|
|
||||||
|
class ConvertRangeCheckToTwoComparisonsIntention : SelfTargetingOffsetIndependentIntention<KtBinaryExpression>(
|
||||||
|
KtBinaryExpression::class.java,
|
||||||
|
"Convert to comparisons"
|
||||||
|
) {
|
||||||
|
private fun KtExpression?.isSimple() = this is KtConstantExpression || this is KtNameReferenceExpression
|
||||||
|
|
||||||
|
override fun applyTo(element: KtBinaryExpression, editor: Editor?) {
|
||||||
|
if (element.operationToken != KtTokens.IN_KEYWORD) return
|
||||||
|
val rangeExpression = element.right as? KtBinaryExpression ?: return
|
||||||
|
val min = rangeExpression.left ?: return
|
||||||
|
val arg = element.left ?: return
|
||||||
|
val max = rangeExpression.right ?: return
|
||||||
|
val comparisonsExpression = KtPsiFactory(element).createExpressionByPattern("$0 <= $1 && $1 <= $2", min, arg, max)
|
||||||
|
element.replace(comparisonsExpression)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isApplicableTo(element: KtBinaryExpression): Boolean {
|
||||||
|
if (element.operationToken != KtTokens.IN_KEYWORD) return false
|
||||||
|
|
||||||
|
// ignore for-loop. for(x in 1..2) should not be convert to for(1<=x && x<=2)
|
||||||
|
if (element.parent is KtForExpression) return false
|
||||||
|
|
||||||
|
val rangeExpression = element.right as? KtBinaryExpression ?: return false
|
||||||
|
if (rangeExpression.operationToken != KtTokens.RANGE) return false
|
||||||
|
|
||||||
|
return element.left.isSimple() && rangeExpression.left.isSimple() && rangeExpression.right.isSimple()
|
||||||
|
}
|
||||||
|
}
|
||||||
+139
@@ -0,0 +1,139 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.intentions
|
||||||
|
|
||||||
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import com.intellij.psi.tree.IElementType
|
||||||
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
|
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.evaluatesTo
|
||||||
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
|
import org.jetbrains.kotlin.psi.*
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getType
|
||||||
|
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator
|
||||||
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
|
||||||
|
class ConvertTwoComparisonsToRangeCheckIntention : SelfTargetingOffsetIndependentIntention<KtBinaryExpression>(
|
||||||
|
KtBinaryExpression::class.java,
|
||||||
|
"Convert to range check"
|
||||||
|
) {
|
||||||
|
|
||||||
|
private data class RangeExpressionData(val value: KtExpression, val min: String, val max: String)
|
||||||
|
|
||||||
|
override fun isApplicableTo(element: KtBinaryExpression) = generateRangeExpressionData(element) != null
|
||||||
|
|
||||||
|
override fun applyTo(element: KtBinaryExpression, editor: Editor?) {
|
||||||
|
val rangeData = generateRangeExpressionData(element) ?: return
|
||||||
|
val factory = KtPsiFactory(element)
|
||||||
|
element.replace(factory.createExpressionByPattern("$0 in $1..$2", rangeData.value,
|
||||||
|
factory.createExpression(rangeData.min),
|
||||||
|
factory.createExpression(rangeData.max)))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun generateRangeExpressionData(condition: KtBinaryExpression): RangeExpressionData? {
|
||||||
|
if (condition.operationToken != KtTokens.ANDAND) return null
|
||||||
|
val firstCondition = condition.left as? KtBinaryExpression ?: return null
|
||||||
|
val secondCondition = condition.right as? KtBinaryExpression ?: return null
|
||||||
|
val firstOpToken = firstCondition.operationToken
|
||||||
|
val secondOpToken = secondCondition.operationToken
|
||||||
|
val firstLeft = firstCondition.left ?: return null
|
||||||
|
val firstRight = firstCondition.right ?: return null
|
||||||
|
val secondLeft = secondCondition.left ?: return null
|
||||||
|
val secondRight = secondCondition.right ?: return null
|
||||||
|
|
||||||
|
fun IElementType.isStrictComparison() = this == KtTokens.GT || this == KtTokens.LT
|
||||||
|
|
||||||
|
val firstStrict = firstOpToken.isStrictComparison()
|
||||||
|
val secondStrict = secondOpToken.isStrictComparison()
|
||||||
|
|
||||||
|
fun IElementType.orderLessAndGreater(left: KtExpression, right: KtExpression): Pair<KtExpression, KtExpression>? = when (this) {
|
||||||
|
KtTokens.GTEQ, KtTokens.GT -> right to left
|
||||||
|
KtTokens.LTEQ, KtTokens.LT -> left to right
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
|
||||||
|
val (firstLess, firstGreater) = firstOpToken.orderLessAndGreater(firstLeft, firstRight) ?: return null
|
||||||
|
val (secondLess, secondGreater) = secondOpToken.orderLessAndGreater(secondLeft, secondRight) ?: return null
|
||||||
|
|
||||||
|
return generateRangeExpressionData(firstLess, firstGreater, firstStrict, secondLess, secondGreater, secondStrict)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun KtExpression.isSimple() = this is KtConstantExpression || this is KtNameReferenceExpression
|
||||||
|
|
||||||
|
private fun generateRangeExpressionData(
|
||||||
|
firstLess: KtExpression, firstGreater: KtExpression, firstStrict: Boolean,
|
||||||
|
secondLess: KtExpression, secondGreater: KtExpression, secondStrict: Boolean
|
||||||
|
) = when {
|
||||||
|
firstGreater !is KtConstantExpression && firstGreater.evaluatesTo(secondLess) ->
|
||||||
|
generateRangeExpressionData(firstGreater,
|
||||||
|
min = firstLess,
|
||||||
|
max = secondGreater,
|
||||||
|
incrementMinByOne = firstStrict,
|
||||||
|
decrementMaxByOne = secondStrict)
|
||||||
|
firstLess !is KtConstantExpression && firstLess.evaluatesTo(secondGreater) ->
|
||||||
|
generateRangeExpressionData(firstLess,
|
||||||
|
min = secondLess,
|
||||||
|
max = firstGreater,
|
||||||
|
incrementMinByOne = secondStrict,
|
||||||
|
decrementMaxByOne = firstStrict)
|
||||||
|
else ->
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun generateRangeExpressionData(
|
||||||
|
value: KtExpression, min: KtExpression, max: KtExpression, incrementMinByOne: Boolean, decrementMaxByOne: Boolean
|
||||||
|
): RangeExpressionData? {
|
||||||
|
fun KtExpression.getChangeBy(number: Int): String? {
|
||||||
|
val context = analyze()
|
||||||
|
val type = getType(context) ?: return null
|
||||||
|
if (!type.isValidTypeForIncrementDecrementByOne()) return null
|
||||||
|
|
||||||
|
when (this) {
|
||||||
|
is KtConstantExpression -> {
|
||||||
|
val constantValue = ConstantExpressionEvaluator.getConstant(this, context)?.getValue(type) ?: return null
|
||||||
|
return when {
|
||||||
|
KotlinBuiltIns.isInt(type) -> (constantValue as Int + number).toString()
|
||||||
|
KotlinBuiltIns.isLong(type) -> (constantValue as Long + number).toString()
|
||||||
|
KotlinBuiltIns.isChar(type) -> "'${constantValue as Char + number}'"
|
||||||
|
else -> return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> return if (number >= 0) "($text + $number)" else "($text - ${-number})"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// To avoid possible side effects
|
||||||
|
if (!min.isSimple() || !max.isSimple()) return null
|
||||||
|
|
||||||
|
if (incrementMinByOne || decrementMaxByOne) {
|
||||||
|
if (!value.getType(value.analyze()).isValidTypeForIncrementDecrementByOne()) return null
|
||||||
|
}
|
||||||
|
|
||||||
|
val minText = if (incrementMinByOne) min.getChangeBy(1) else min.text
|
||||||
|
val maxText = if (decrementMaxByOne) max.getChangeBy(-1) else max.text
|
||||||
|
return RangeExpressionData(value, minText ?: return null, maxText ?: return null)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun KotlinType?.isValidTypeForIncrementDecrementByOne(): Boolean {
|
||||||
|
this ?: return false
|
||||||
|
return KotlinBuiltIns.isInt(this) ||
|
||||||
|
KotlinBuiltIns.isLong(this) ||
|
||||||
|
KotlinBuiltIns.isShort(this) ||
|
||||||
|
KotlinBuiltIns.isByte(this) ||
|
||||||
|
KotlinBuiltIns.isChar(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
org.jetbrains.kotlin.idea.intentions.ConvertRangeCheckToTwoComparisonsIntention
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
fun foo(bar: Double) {
|
||||||
|
bar in 1.0..10.0<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
fun foo(bar: Double) {
|
||||||
|
1.0 <= bar && bar <= 10.0
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
fun foo(bar: Int) {
|
||||||
|
for (bar in 1..2<caret>) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
for (bar in 1..10) {
|
||||||
|
bar in 1..10<caret>
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
for (bar in 1..10) {
|
||||||
|
1 <= bar && bar <= 10
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
for (bar in 1..10) {
|
||||||
|
if (bar in 1..10<caret>) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
for (bar in 1..10) {
|
||||||
|
if (1 <= bar && bar <= 10) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
bar in 1..10<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
1 <= bar && bar <= 10<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int, min: Int, max: Int) {
|
||||||
|
bar in min..max<caret>
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int, min: Int, max: Int) {
|
||||||
|
min <= bar && bar <= max<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
// WITH_RUNTIME
|
||||||
|
fun foo(bar: Int) {
|
||||||
|
if (bar in arrayOf(1, 2, 3)<caret>) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
|
||||||
|
var x = 5
|
||||||
|
var y = 10
|
||||||
|
|
||||||
|
fun foo() = <caret>++x in --x..y++
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
org.jetbrains.kotlin.idea.intentions.ConvertTwoComparisonsToRangeCheckIntention
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Char) {
|
||||||
|
bar >= 'a' && 'z' >= bar<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Char) {
|
||||||
|
bar in 'a'..'z'
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Char) {
|
||||||
|
bar > 'a' && 'z' > bar<caret>
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Char) {
|
||||||
|
bar in 'b'..'y'
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
fun foo(bar: Int) {
|
||||||
|
bar >= 0.0 && 10.0 >= bar<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
fun foo(bar: Int) {
|
||||||
|
bar in 0.0..10.0
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
fun foo(arg: Int) = 6 > arg && arg >= 1<caret>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
fun foo(arg: Int) = arg in 1..5
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
|
||||||
|
var x = 42
|
||||||
|
|
||||||
|
// Should be converted into arg in --x..++x (41..42) but initial check is arg <= ++x (43) && --x (42) <= arg
|
||||||
|
fun foo(arg: Int) = <caret>arg <= ++x && --x <= arg
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
// WITH_RUNTIME
|
||||||
|
fun foo(bar: Int) {
|
||||||
|
bar > 0.0 && 10.0 >= bar<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
// WITH_RUNTIME
|
||||||
|
fun foo(bar: Double) {
|
||||||
|
bar > 0 && 10 >= bar<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
bar >= 0 && 10 > bar<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
bar in 0..9
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
bar >= 0 && 10 >= bar<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
bar in 0..10
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
bar >= 0 && bar < 10<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
bar in 0..9
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
bar >= 0 && bar <= 10<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
bar in 0..10
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
bar > 0 && 10 > bar<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
bar in 1..9
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
bar > 0 && 10 >= bar<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
bar in 1..10
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
bar > 0 && bar < 10<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
bar in 1..9
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
bar > 0 && bar <= 10<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
bar in 1..10
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
0 <= bar && 10 > bar<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
bar in 0..9
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
0 <= bar && 10 >= bar<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
bar in 0..10
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
0 <= bar && bar < 10<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
bar in 0..9
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
0 <= bar && bar <= 10<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
bar in 0..10
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
0 < bar && 10 > bar<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
bar in 1..9
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
0 < bar && 10 >= bar<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
bar in 1..10
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
0 < bar && bar < 10<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
bar in 1..9
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
0 < bar && bar <= 10<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int) {
|
||||||
|
bar in 1..10
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int, min: Int, max: Int) {
|
||||||
|
min < bar && bar < max<caret>
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(bar: Int, min: Int, max: Int) {
|
||||||
|
bar in (min + 1)..(max - 1)
|
||||||
|
}
|
||||||
@@ -5052,6 +5052,63 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("idea/testData/intentions/convertRangeCheckToTwoComparisons")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class ConvertRangeCheckToTwoComparisons extends AbstractIntentionTest {
|
||||||
|
public void testAllFilesPresentInConvertRangeCheckToTwoComparisons() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/convertRangeCheckToTwoComparisons"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("double.kt")
|
||||||
|
public void testDouble() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertRangeCheckToTwoComparisons/double.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("forLoop.kt")
|
||||||
|
public void testForLoop() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertRangeCheckToTwoComparisons/forLoop.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("insideForLoop.kt")
|
||||||
|
public void testInsideForLoop() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertRangeCheckToTwoComparisons/insideForLoop.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("insideForLoop2.kt")
|
||||||
|
public void testInsideForLoop2() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertRangeCheckToTwoComparisons/insideForLoop2.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("int.kt")
|
||||||
|
public void testInt() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertRangeCheckToTwoComparisons/int.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nonConstants.kt")
|
||||||
|
public void testNonConstants() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertRangeCheckToTwoComparisons/nonConstants.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("otherOp.kt")
|
||||||
|
public void testOtherOp() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertRangeCheckToTwoComparisons/otherOp.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("withSideEffects.kt")
|
||||||
|
public void testWithSideEffects() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertRangeCheckToTwoComparisons/withSideEffects.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/intentions/convertReceiverToParameter")
|
@TestMetadata("idea/testData/intentions/convertReceiverToParameter")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
@@ -6442,6 +6499,159 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("idea/testData/intentions/convertTwoComparisonsToRangeCheck")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class ConvertTwoComparisonsToRangeCheck extends AbstractIntentionTest {
|
||||||
|
public void testAllFilesPresentInConvertTwoComparisonsToRangeCheck() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/convertTwoComparisonsToRangeCheck"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("char.kt")
|
||||||
|
public void testChar() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertTwoComparisonsToRangeCheck/char.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("charInclusive.kt")
|
||||||
|
public void testCharInclusive() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertTwoComparisonsToRangeCheck/charInclusive.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("double.kt")
|
||||||
|
public void testDouble() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertTwoComparisonsToRangeCheck/double.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("flipped.kt")
|
||||||
|
public void testFlipped() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertTwoComparisonsToRangeCheck/flipped.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("flippedSideEffect.kt")
|
||||||
|
public void testFlippedSideEffect() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertTwoComparisonsToRangeCheck/flippedSideEffect.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("gtDouble.kt")
|
||||||
|
public void testGtDouble() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertTwoComparisonsToRangeCheck/gtDouble.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("gtDouble2.kt")
|
||||||
|
public void testGtDouble2() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertTwoComparisonsToRangeCheck/gtDouble2.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("gteqgt.kt")
|
||||||
|
public void testGteqgt() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertTwoComparisonsToRangeCheck/gteqgt.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("gteqgteq.kt")
|
||||||
|
public void testGteqgteq() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertTwoComparisonsToRangeCheck/gteqgteq.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("gteqlt.kt")
|
||||||
|
public void testGteqlt() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertTwoComparisonsToRangeCheck/gteqlt.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("gteqlteq.kt")
|
||||||
|
public void testGteqlteq() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertTwoComparisonsToRangeCheck/gteqlteq.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("gtgt.kt")
|
||||||
|
public void testGtgt() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertTwoComparisonsToRangeCheck/gtgt.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("gtgteq.kt")
|
||||||
|
public void testGtgteq() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertTwoComparisonsToRangeCheck/gtgteq.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("gtlt.kt")
|
||||||
|
public void testGtlt() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertTwoComparisonsToRangeCheck/gtlt.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("gtlteq.kt")
|
||||||
|
public void testGtlteq() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertTwoComparisonsToRangeCheck/gtlteq.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("lteqgt.kt")
|
||||||
|
public void testLteqgt() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertTwoComparisonsToRangeCheck/lteqgt.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("lteqgteq.kt")
|
||||||
|
public void testLteqgteq() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertTwoComparisonsToRangeCheck/lteqgteq.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("lteqlt.kt")
|
||||||
|
public void testLteqlt() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertTwoComparisonsToRangeCheck/lteqlt.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("lteqlteq.kt")
|
||||||
|
public void testLteqlteq() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertTwoComparisonsToRangeCheck/lteqlteq.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ltgt.kt")
|
||||||
|
public void testLtgt() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertTwoComparisonsToRangeCheck/ltgt.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ltgteq.kt")
|
||||||
|
public void testLtgteq() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertTwoComparisonsToRangeCheck/ltgteq.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ltlt.kt")
|
||||||
|
public void testLtlt() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertTwoComparisonsToRangeCheck/ltlt.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ltlteq.kt")
|
||||||
|
public void testLtlteq() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertTwoComparisonsToRangeCheck/ltlteq.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nonConstants.kt")
|
||||||
|
public void testNonConstants() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertTwoComparisonsToRangeCheck/nonConstants.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/intentions/copyConcatenatedStringToClipboard")
|
@TestMetadata("idea/testData/intentions/copyConcatenatedStringToClipboard")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Reference in New Issue
Block a user