Refactoring: "simplify negated binary expression" is now an inspection

This commit is contained in:
Mikhail Glukhikh
2017-12-20 20:41:50 +03:00
parent 35d85ddd1f
commit bc361363d5
56 changed files with 292 additions and 292 deletions
@@ -1,3 +0,0 @@
if (a != b) {
println("Not Equal")
}
@@ -1,3 +0,0 @@
if (<spot>!(a == b)</spot>) {
println("Not Equal")
}
@@ -1,7 +0,0 @@
<html>
<body>
This intention simplifies negated binary expressions by replacing expressions such as
!(<b>a</b> <small>op</small> <b>b</b>) with <b>a</b> <small>negop</small> <b>b</b>
(where <small>op</small> and <small>negop</small> are inverse comparison operators like <b>==</b> and <b>!=</b> or <b>in</b> and <b>!in</b>).
</body>
</html>
+1 -6
View File
@@ -907,11 +907,6 @@
<category>Kotlin</category>
</intentionAction>
<intentionAction>
<className>org.jetbrains.kotlin.idea.intentions.SimplifyNegatedBinaryExpressionIntention</className>
<category>Kotlin</category>
</intentionAction>
<intentionAction>
<className>org.jetbrains.kotlin.idea.intentions.RemoveUnnecessaryParenthesesIntention</className>
<category>Kotlin</category>
@@ -1642,7 +1637,7 @@
language="kotlin"
/>
<localInspection implementationClass="org.jetbrains.kotlin.idea.intentions.SimplifyNegatedBinaryExpressionInspection"
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.SimplifyNegatedBinaryExpressionInspection"
displayName="Negated boolean expression that can be simplified"
groupPath="Kotlin"
groupName="Style issues"
@@ -24,7 +24,6 @@ import com.intellij.openapi.project.Project
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.core.replaced
import org.jetbrains.kotlin.idea.intentions.SimplifyNegatedBinaryExpressionIntention
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
@@ -87,9 +86,9 @@ class NullableBooleanElvisInspection : AbstractKotlinInspection(), CleanupLocalI
appendFixedText(if (constValue) " != false" else " == true")
})
val prefixExpression = equalityCheckExpression.getParentOfType<KtPrefixExpression>(strict = true) ?: return
val simplifier = SimplifyNegatedBinaryExpressionIntention()
if (simplifier.isApplicableTo(prefixExpression)) {
simplifier.applyTo(prefixExpression, null)
val simplifier = SimplifyNegatedBinaryExpressionInspection()
if (simplifier.isApplicable(prefixExpression)) {
simplifier.applyTo(prefixExpression.operationReference)
}
}
}
@@ -0,0 +1,100 @@
/*
* Copyright 2010-2017 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.inspections
import com.intellij.codeInspection.LocalInspectionToolSession
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import com.intellij.psi.tree.IElementType
import org.jetbrains.kotlin.idea.inspections.AbstractApplicabilityBasedInspection
import org.jetbrains.kotlin.lexer.KtSingleValueToken
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
class SimplifyNegatedBinaryExpressionInspection : AbstractApplicabilityBasedInspection<KtPrefixExpression>() {
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): KtVisitorVoid =
object : KtVisitorVoid() {
override fun visitPrefixExpression(expression: KtPrefixExpression) {
super.visitPrefixExpression(expression)
visitTargetElement(expression, holder, isOnTheFly)
}
}
private fun IElementType.negate(): KtSingleValueToken? = when (this) {
KtTokens.IN_KEYWORD -> KtTokens.NOT_IN
KtTokens.NOT_IN -> KtTokens.IN_KEYWORD
KtTokens.IS_KEYWORD -> KtTokens.NOT_IS
KtTokens.NOT_IS -> KtTokens.IS_KEYWORD
KtTokens.EQEQ -> KtTokens.EXCLEQ
KtTokens.EXCLEQ -> KtTokens.EQEQ
KtTokens.LT -> KtTokens.GTEQ
KtTokens.GTEQ -> KtTokens.LT
KtTokens.GT -> KtTokens.LTEQ
KtTokens.LTEQ -> KtTokens.GT
else -> null
}
override fun inspectionTarget(element: KtPrefixExpression) = element.operationReference
override fun inspectionText(element: KtPrefixExpression) = "Negated expression can be simplified"
override val defaultFixText = "Simplify negated expression"
override fun fixText(element: KtPrefixExpression): String {
val expression = KtPsiUtil.deparenthesize(element.baseExpression) as? KtOperationExpression ?: return defaultFixText
val operation = expression.operationReference.getReferencedNameElementType() as? KtSingleValueToken ?: return defaultFixText
val negatedOperation = operation.negate() ?: return defaultFixText
return "Simplify negated '${operation.value}' expression to '${negatedOperation.value}'"
}
override fun isApplicable(element: KtPrefixExpression): Boolean {
if (element.operationToken != KtTokens.EXCL) return false
val expression = KtPsiUtil.deparenthesize(element.baseExpression) as? KtOperationExpression ?: return false
when (expression) {
is KtIsExpression -> if (expression.typeReference == null) return false
is KtBinaryExpression -> if (expression.left == null || expression.right == null) return false
else -> return false
}
return (expression.operationReference.getReferencedNameElementType() as? KtSingleValueToken)?.negate() != null
}
override fun applyTo(element: PsiElement, project: Project, editor: Editor?) {
val prefixExpression = element.parent as? KtPrefixExpression ?: return
val expression = KtPsiUtil.deparenthesize(prefixExpression.baseExpression) ?: return
val operation = (expression as KtOperationExpression).operationReference.getReferencedNameElementType().negate()?.value ?: return
val psiFactory = KtPsiFactory(expression)
val newExpression = when (expression) {
is KtIsExpression ->
psiFactory.createExpressionByPattern("$0 $1 $2", expression.leftHandSide, operation, expression.typeReference!!)
is KtBinaryExpression ->
psiFactory.createExpressionByPattern("$0 $1 $2", expression.left!!, operation, expression.right!!)
else ->
throw IllegalArgumentException()
}
prefixExpression.replace(newExpression)
}
}
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.core.replaced
import org.jetbrains.kotlin.idea.core.ShortenReferences
import org.jetbrains.kotlin.idea.inspections.SimplifyNegatedBinaryExpressionInspection
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.DescriptorUtils
@@ -104,9 +105,9 @@ class ConvertAssertToIfWithThrowIntention : SelfTargetingIntention<KtCallExpress
private fun simplifyConditionIfPossible(ifExpression: KtIfExpression, editor: Editor?) {
val condition = ifExpression.condition as KtPrefixExpression
val simplifier = SimplifyNegatedBinaryExpressionIntention()
if (simplifier.isApplicableTo(condition)) {
simplifier.applyTo(condition, editor)
val simplifier = SimplifyNegatedBinaryExpressionInspection()
if (simplifier.isApplicable(condition)) {
simplifier.applyTo(condition.operationReference, editor = editor)
}
}
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.idea.core.replaced
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isNullExpression
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.unwrapBlockOrParenthesis
import org.jetbrains.kotlin.idea.core.ShortenReferences
import org.jetbrains.kotlin.idea.inspections.SimplifyNegatedBinaryExpressionInspection
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
@@ -52,9 +53,9 @@ class ConvertIfWithThrowToAssertIntention : SelfTargetingOffsetIndependentIntent
condition.replace(psiFactory.createExpressionByPattern("!$0", condition))
var newCondition = element.condition!!
val simplifier = SimplifyNegatedBinaryExpressionIntention()
if (simplifier.isApplicableTo(newCondition as KtPrefixExpression)) {
simplifier.applyTo(newCondition, editor)
val simplifier = SimplifyNegatedBinaryExpressionInspection()
if (simplifier.isApplicable(newCondition as KtPrefixExpression)) {
simplifier.applyTo(newCondition.operationReference, editor = editor)
newCondition = element.condition!!
}
@@ -1,83 +0,0 @@
/*
* Copyright 2010-2015 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.openapi.util.TextRange
import com.intellij.psi.tree.IElementType
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
import org.jetbrains.kotlin.lexer.KtSingleValueToken
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
class SimplifyNegatedBinaryExpressionInspection : IntentionBasedInspection<KtPrefixExpression>(SimplifyNegatedBinaryExpressionIntention::class)
class SimplifyNegatedBinaryExpressionIntention : SelfTargetingRangeIntention<KtPrefixExpression>(KtPrefixExpression::class.java, "Simplify negated binary expression") {
private fun IElementType.negate(): KtSingleValueToken? = when (this) {
KtTokens.IN_KEYWORD -> KtTokens.NOT_IN
KtTokens.NOT_IN -> KtTokens.IN_KEYWORD
KtTokens.IS_KEYWORD -> KtTokens.NOT_IS
KtTokens.NOT_IS -> KtTokens.IS_KEYWORD
KtTokens.EQEQ -> KtTokens.EXCLEQ
KtTokens.EXCLEQ -> KtTokens.EQEQ
KtTokens.LT -> KtTokens.GTEQ
KtTokens.GTEQ -> KtTokens.LT
KtTokens.GT -> KtTokens.LTEQ
KtTokens.LTEQ -> KtTokens.GT
else -> null
}
override fun applicabilityRange(element: KtPrefixExpression): TextRange? {
return if (isApplicableTo(element)) element.operationReference.textRange else null
}
fun isApplicableTo(element: KtPrefixExpression): Boolean {
if (element.operationToken != KtTokens.EXCL) return false
val expression = KtPsiUtil.deparenthesize(element.baseExpression) as? KtOperationExpression ?: return false
when (expression) {
is KtIsExpression -> { if (expression.typeReference == null) return false }
is KtBinaryExpression -> { if (expression.left == null || expression.right == null) return false }
else -> return false
}
val operation = expression.operationReference.getReferencedNameElementType() as? KtSingleValueToken ?: return false
val negatedOperation = operation.negate() ?: return false
text = "Simplify negated '${operation.value}' expression to '${negatedOperation.value}'"
return true
}
override fun applyTo(element: KtPrefixExpression, editor: Editor?) {
val expression = KtPsiUtil.deparenthesize(element.baseExpression)!!
val operation = (expression as KtOperationExpression).operationReference.getReferencedNameElementType().negate()!!.value
val psiFactory = KtPsiFactory(expression)
val newExpression = when (expression) {
is KtIsExpression -> psiFactory.createExpressionByPattern("$0 $1 $2", expression.leftHandSide, operation, expression.typeReference!!)
is KtBinaryExpression -> psiFactory.createExpressionByPattern("$0 $1 $2", expression.left!!, operation, expression.right!!)
else -> throw IllegalArgumentException()
}
element.replace(newExpression)
}
}
@@ -89,7 +89,7 @@ object J2KPostProcessingRegistrar {
registerInspectionBasedProcessing(IfThenToSafeAccessInspection())
registerIntentionBasedProcessing(IfThenToElvisIntention())
registerIntentionBasedProcessing(SimplifyNegatedBinaryExpressionIntention())
registerInspectionBasedProcessing(SimplifyNegatedBinaryExpressionInspection())
registerInspectionBasedProcessing(ReplaceGetOrSetInspection())
registerIntentionBasedProcessing(AddOperatorModifierIntention())
registerIntentionBasedProcessing(ObjectLiteralToLambdaIntention())
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.SimplifyNegatedBinaryExpressionInspection
@@ -0,0 +1,4 @@
// FIX: Simplify negated '==' expression to '!='
fun test(n: Int) {
<caret>!(0 == 1)
}
@@ -0,0 +1,4 @@
// FIX: Simplify negated '==' expression to '!='
fun test(n: Int) {
0 != 1
}
@@ -0,0 +1,4 @@
// FIX: Simplify negated '>' expression to '<='
fun test(n: Int) {
<caret>!(0 > 1)
}
@@ -0,0 +1,4 @@
// FIX: Simplify negated '>' expression to '<='
fun test(n: Int) {
0 <= 1
}
@@ -0,0 +1,4 @@
// FIX: Simplify negated '>=' expression to '<'
fun test(n: Int) {
<caret>!(0 >= 1)
}
@@ -0,0 +1,4 @@
// FIX: Simplify negated '>=' expression to '<'
fun test(n: Int) {
0 < 1
}
@@ -1,4 +1,4 @@
// INTENTION_TEXT: Simplify negated 'in' expression to '!in'
// FIX: Simplify negated 'in' expression to '!in'
class A(val e: Int) {
operator fun contains(i: Int): Boolean = e == i
}
@@ -1,4 +1,4 @@
// INTENTION_TEXT: Simplify negated 'in' expression to '!in'
// FIX: Simplify negated 'in' expression to '!in'
class A(val e: Int) {
operator fun contains(i: Int): Boolean = e == i
}
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
infix fun Int.lt(b: Int): Boolean = this < b
fun test(n: Int) {
<caret>!(1 lt 2)
@@ -5,8 +5,8 @@
<line>3</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/notIs.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Simplify Negated Binary Expression</problem_class>
<description>Simplify negated '!is' expression to 'is'</description>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Negated boolean expression that can be simplified</problem_class>
<description>Negated expression can be simplified</description>
</problem>
<problem>
@@ -14,8 +14,8 @@
<line>8</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/notIn.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Simplify Negated Binary Expression</problem_class>
<description>Simplify negated '!in' expression to 'in'</description>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Negated boolean expression that can be simplified</problem_class>
<description>Negated expression can be simplified</description>
</problem>
<problem>
@@ -23,8 +23,8 @@
<line>3</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/notEquals.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Simplify Negated Binary Expression</problem_class>
<description>Simplify negated '!=' expression to '=='</description>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Negated boolean expression that can be simplified</problem_class>
<description>Negated expression can be simplified</description>
</problem>
<problem>
@@ -32,8 +32,8 @@
<line>3</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/lessThanOrEquals.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Simplify Negated Binary Expression</problem_class>
<description>Simplify negated '&lt;=' expression to '&gt;'</description>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Negated boolean expression that can be simplified</problem_class>
<description>Negated expression can be simplified</description>
</problem>
<problem>
@@ -41,8 +41,8 @@
<line>3</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/lessThan.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Simplify Negated Binary Expression</problem_class>
<description>Simplify negated '&lt;' expression to '&gt;='</description>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Negated boolean expression that can be simplified</problem_class>
<description>Negated expression can be simplified</description>
</problem>
<problem>
@@ -50,8 +50,8 @@
<line>3</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/is.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Simplify Negated Binary Expression</problem_class>
<description>Simplify negated 'is' expression to '!is'</description>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Negated boolean expression that can be simplified</problem_class>
<description>Negated expression can be simplified</description>
</problem>
<problem>
@@ -59,8 +59,8 @@
<line>8</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/in.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Simplify Negated Binary Expression</problem_class>
<description>Simplify negated 'in' expression to '!in'</description>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Negated boolean expression that can be simplified</problem_class>
<description>Negated expression can be simplified</description>
</problem>
<problem>
@@ -68,8 +68,8 @@
<line>3</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/greaterThanOrEquals.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Simplify Negated Binary Expression</problem_class>
<description>Simplify negated '&gt;=' expression to '&lt;'</description>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Negated boolean expression that can be simplified</problem_class>
<description>Negated expression can be simplified</description>
</problem>
<problem>
@@ -77,8 +77,8 @@
<line>3</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/greaterThan.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Simplify Negated Binary Expression</problem_class>
<description>Simplify negated '&gt;' expression to '&lt;='</description>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Negated boolean expression that can be simplified</problem_class>
<description>Negated expression can be simplified</description>
</problem>
<problem>
@@ -86,8 +86,8 @@
<line>3</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/equals.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Simplify Negated Binary Expression</problem_class>
<description>Simplify negated '==' expression to '!='</description>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Negated boolean expression that can be simplified</problem_class>
<description>Negated expression can be simplified</description>
</problem>
</problems>
@@ -0,0 +1 @@
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.SimplifyNegatedBinaryExpressionInspection
@@ -0,0 +1,4 @@
// FIX: Simplify negated 'is' expression to '!is'
fun test(n: Int) {
<caret>!(0 is Int)
}
@@ -0,0 +1,4 @@
// FIX: Simplify negated 'is' expression to '!is'
fun test(n: Int) {
0 !is Int
}
@@ -0,0 +1,4 @@
// FIX: Simplify negated '<' expression to '>='
fun test(n: Int) {
<caret>!(0 < 1)
}
@@ -0,0 +1,4 @@
// FIX: Simplify negated '<' expression to '>='
fun test(n: Int) {
0 >= 1
}
@@ -0,0 +1,4 @@
// FIX: Simplify negated '<=' expression to '>'
fun test(n: Int) {
<caret>!(0 <= 1)
}
@@ -0,0 +1,4 @@
// FIX: Simplify negated '<=' expression to '>'
fun test(n: Int) {
0 > 1
}
@@ -0,0 +1,4 @@
// FIX: Simplify negated '!=' expression to '=='
fun test(n: Int) {
<caret>!(0 != 1)
}
@@ -0,0 +1,4 @@
// FIX: Simplify negated '!=' expression to '=='
fun test(n: Int) {
0 == 1
}
@@ -1,4 +1,4 @@
// INTENTION_TEXT: Simplify negated '!in' expression to 'in'
// FIX: Simplify negated '!in' expression to 'in'
class A(val e: Int) {
operator fun contains(i: Int): Boolean = e == i
}
@@ -1,4 +1,4 @@
// INTENTION_TEXT: Simplify negated '!in' expression to 'in'
// FIX: Simplify negated '!in' expression to 'in'
class A(val e: Int) {
operator fun contains(i: Int): Boolean = e == i
}
@@ -0,0 +1,4 @@
// FIX: Simplify negated '!is' expression to 'is'
fun test(n: Int) {
<caret>!(0 !is Int)
}
@@ -0,0 +1,4 @@
// FIX: Simplify negated '!is' expression to 'is'
fun test(n: Int) {
0 is Int
}
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
fun test(n: Int) {
!<caret>true
}
@@ -1 +0,0 @@
org.jetbrains.kotlin.idea.intentions.SimplifyNegatedBinaryExpressionIntention
@@ -1,4 +0,0 @@
// INTENTION_TEXT: Simplify negated '==' expression to '!='
fun test(n: Int) {
!<caret>(0 == 1)
}
@@ -1,4 +0,0 @@
// INTENTION_TEXT: Simplify negated '==' expression to '!='
fun test(n: Int) {
0 != 1
}
@@ -1,4 +0,0 @@
// INTENTION_TEXT: Simplify negated '>' expression to '<='
fun test(n: Int) {
!<caret>(0 > 1)
}
@@ -1,4 +0,0 @@
// INTENTION_TEXT: Simplify negated '>' expression to '<='
fun test(n: Int) {
0 <= 1
}
@@ -1,4 +0,0 @@
// INTENTION_TEXT: Simplify negated '>=' expression to '<'
fun test(n: Int) {
<caret>!(0 >= 1)
}
@@ -1,4 +0,0 @@
// INTENTION_TEXT: Simplify negated '>=' expression to '<'
fun test(n: Int) {
0 < 1
}
@@ -1 +0,0 @@
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.intentions.SimplifyNegatedBinaryExpressionInspection
@@ -1,4 +0,0 @@
// INTENTION_TEXT: Simplify negated 'is' expression to '!is'
fun test(n: Int) {
<caret>!(0 is Int)
}
@@ -1,4 +0,0 @@
// INTENTION_TEXT: Simplify negated 'is' expression to '!is'
fun test(n: Int) {
0 !is Int
}
@@ -1,4 +0,0 @@
// INTENTION_TEXT: Simplify negated '<' expression to '>='
fun test(n: Int) {
<caret>!(0 < 1)
}
@@ -1,4 +0,0 @@
// INTENTION_TEXT: Simplify negated '<' expression to '>='
fun test(n: Int) {
0 >= 1
}
@@ -1,4 +0,0 @@
// INTENTION_TEXT: Simplify negated '<=' expression to '>'
fun test(n: Int) {
<caret>!(0 <= 1)
}
@@ -1,4 +0,0 @@
// INTENTION_TEXT: Simplify negated '<=' expression to '>'
fun test(n: Int) {
0 > 1
}
@@ -1,4 +0,0 @@
// INTENTION_TEXT: Simplify negated '!=' expression to '=='
fun test(n: Int) {
<caret>!(0 != 1)
}
@@ -1,4 +0,0 @@
// INTENTION_TEXT: Simplify negated '!=' expression to '=='
fun test(n: Int) {
0 == 1
}
@@ -1,4 +0,0 @@
// INTENTION_TEXT: Simplify negated '!is' expression to 'is'
fun test(n: Int) {
<caret>!(0 !is Int)
}
@@ -1,4 +0,0 @@
// INTENTION_TEXT: Simplify negated '!is' expression to 'is'
fun test(n: Int) {
0 is Int
}
@@ -85,12 +85,6 @@ public class InspectionTestGenerated extends AbstractInspectionTest {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/removeExplicitTypeArguments/inspectionData/inspections.test");
doTest(fileName);
}
@TestMetadata("simplifyNegatedBinaryExpression/inspectionData/inspections.test")
public void testSimplifyNegatedBinaryExpression_inspectionData_Inspections_test() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/simplifyNegatedBinaryExpression/inspectionData/inspections.test");
doTest(fileName);
}
}
@TestMetadata("idea/testData/inspections")
@@ -493,5 +487,11 @@ public class InspectionTestGenerated extends AbstractInspectionTest {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/conventionNameCalls/replaceGetOrSet/inspectionData/inspections.test");
doTest(fileName);
}
@TestMetadata("simplifyNegatedBinaryExpression/inspectionData/inspections.test")
public void testSimplifyNegatedBinaryExpression_inspectionData_Inspections_test() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/simplifyNegatedBinaryExpression/inspectionData/inspections.test");
doTest(fileName);
}
}
}
@@ -3516,6 +3516,87 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
}
}
@TestMetadata("idea/testData/inspectionsLocal/simplifyNegatedBinaryExpression")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class SimplifyNegatedBinaryExpression extends AbstractLocalInspectionTest {
public void testAllFilesPresentInSimplifyNegatedBinaryExpression() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/simplifyNegatedBinaryExpression"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true);
}
@TestMetadata("equals.kt")
public void testEquals() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/simplifyNegatedBinaryExpression/equals.kt");
doTest(fileName);
}
@TestMetadata("greaterThan.kt")
public void testGreaterThan() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/simplifyNegatedBinaryExpression/greaterThan.kt");
doTest(fileName);
}
@TestMetadata("greaterThanOrEquals.kt")
public void testGreaterThanOrEquals() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/simplifyNegatedBinaryExpression/greaterThanOrEquals.kt");
doTest(fileName);
}
@TestMetadata("in.kt")
public void testIn() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/simplifyNegatedBinaryExpression/in.kt");
doTest(fileName);
}
@TestMetadata("inapplicableBinaryOperation.kt")
public void testInapplicableBinaryOperation() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/simplifyNegatedBinaryExpression/inapplicableBinaryOperation.kt");
doTest(fileName);
}
@TestMetadata("is.kt")
public void testIs() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/simplifyNegatedBinaryExpression/is.kt");
doTest(fileName);
}
@TestMetadata("lessThan.kt")
public void testLessThan() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/simplifyNegatedBinaryExpression/lessThan.kt");
doTest(fileName);
}
@TestMetadata("lessThanOrEquals.kt")
public void testLessThanOrEquals() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/simplifyNegatedBinaryExpression/lessThanOrEquals.kt");
doTest(fileName);
}
@TestMetadata("notEquals.kt")
public void testNotEquals() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/simplifyNegatedBinaryExpression/notEquals.kt");
doTest(fileName);
}
@TestMetadata("notIn.kt")
public void testNotIn() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/simplifyNegatedBinaryExpression/notIn.kt");
doTest(fileName);
}
@TestMetadata("notIs.kt")
public void testNotIs() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/simplifyNegatedBinaryExpression/notIs.kt");
doTest(fileName);
}
@TestMetadata("simpleInvert.kt")
public void testSimpleInvert() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/simplifyNegatedBinaryExpression/simpleInvert.kt");
doTest(fileName);
}
}
@TestMetadata("idea/testData/inspectionsLocal/simplifyWhenWithBooleanConstantCondition")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -14463,87 +14463,6 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
}
}
@TestMetadata("idea/testData/intentions/simplifyNegatedBinaryExpression")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class SimplifyNegatedBinaryExpression extends AbstractIntentionTest {
public void testAllFilesPresentInSimplifyNegatedBinaryExpression() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/simplifyNegatedBinaryExpression"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true);
}
@TestMetadata("equals.kt")
public void testEquals() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/simplifyNegatedBinaryExpression/equals.kt");
doTest(fileName);
}
@TestMetadata("greaterThan.kt")
public void testGreaterThan() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/simplifyNegatedBinaryExpression/greaterThan.kt");
doTest(fileName);
}
@TestMetadata("greaterThanOrEquals.kt")
public void testGreaterThanOrEquals() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/simplifyNegatedBinaryExpression/greaterThanOrEquals.kt");
doTest(fileName);
}
@TestMetadata("in.kt")
public void testIn() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/simplifyNegatedBinaryExpression/in.kt");
doTest(fileName);
}
@TestMetadata("inapplicableBinaryOperation.kt")
public void testInapplicableBinaryOperation() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/simplifyNegatedBinaryExpression/inapplicableBinaryOperation.kt");
doTest(fileName);
}
@TestMetadata("is.kt")
public void testIs() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/simplifyNegatedBinaryExpression/is.kt");
doTest(fileName);
}
@TestMetadata("lessThan.kt")
public void testLessThan() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/simplifyNegatedBinaryExpression/lessThan.kt");
doTest(fileName);
}
@TestMetadata("lessThanOrEquals.kt")
public void testLessThanOrEquals() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/simplifyNegatedBinaryExpression/lessThanOrEquals.kt");
doTest(fileName);
}
@TestMetadata("notEquals.kt")
public void testNotEquals() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/simplifyNegatedBinaryExpression/notEquals.kt");
doTest(fileName);
}
@TestMetadata("notIn.kt")
public void testNotIn() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/simplifyNegatedBinaryExpression/notIn.kt");
doTest(fileName);
}
@TestMetadata("notIs.kt")
public void testNotIs() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/simplifyNegatedBinaryExpression/notIs.kt");
doTest(fileName);
}
@TestMetadata("simpleInvert.kt")
public void testSimpleInvert() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/simplifyNegatedBinaryExpression/simpleInvert.kt");
doTest(fileName);
}
}
@TestMetadata("idea/testData/intentions/specifyExplicitLambdaSignature")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)