Foldable if-then: do not highlight for is checks #KT-24978 Fixed

This commit is contained in:
Toshiaki Kameyama
2018-08-30 10:40:22 +03:00
committed by Mikhail Glukhikh
parent ac14c5e74f
commit bae754a266
13 changed files with 18 additions and 91 deletions
@@ -31,7 +31,6 @@ import org.jetbrains.kotlin.idea.intentions.getLeftMostReceiverExpression
import org.jetbrains.kotlin.idea.intentions.replaceFirstReceiver
import org.jetbrains.kotlin.idea.refactoring.inline.KotlinInlineValHandler
import org.jetbrains.kotlin.idea.refactoring.introduce.introduceVariable.KotlinIntroduceVariableHandler
import org.jetbrains.kotlin.idea.refactoring.isMultiLine
import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.idea.resolve.frontendService
import org.jetbrains.kotlin.idea.util.getResolutionScope
@@ -306,14 +305,6 @@ internal fun KtIfExpression.shouldBeTransformed(): Boolean {
val baseClause = (if (condition.operationToken == KtTokens.EQEQ) `else` else then)?.unwrapBlockOrParenthesis()
!baseClause.isClauseTransformableToLetOnly()
}
is KtIsExpression -> {
val baseClause = (if (condition.isNegated) `else` else then)?.unwrapBlockOrParenthesis()
when {
baseClause.isClauseTransformableToLetOnly() -> false
!isMultiLine() -> true
else -> baseClause !is KtDotQualifiedExpression
}
}
else -> false
}
}
@@ -95,22 +95,6 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Foldable if-then</description>
</problem>
<problem>
<file>isCondition.kt</file>
<line>1</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/src/isCondition.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Foldable if-then</description>
</problem>
<problem>
<file>isNotCondition.kt</file>
<line>1</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/src/isNotCondition.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Foldable if-then</description>
</problem>
<problem>
<file>nullCheckWithSelectorCallChain.kt</file>
<line>5</line>
@@ -119,22 +103,6 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Foldable if-then</description>
</problem>
<problem>
<file>isCheckWithSelectorChain.kt</file>
<line>4</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/isCheckWithSelectorChain.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Foldable if-then</description>
</problem>
<problem>
<file>isCheckSimple.kt</file>
<line>4</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/isCheckSimple.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Foldable if-then</description>
</problem>
<problem>
<file>nullCheckSimple.kt</file>
<line>2</line>
@@ -151,14 +119,6 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Foldable if-then</description>
</problem>
<problem>
<file>property.kt</file>
<line>10</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/property.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Foldable if-then</description>
</problem>
<problem>
<file>propertyNotNull.kt</file>
<line>9</line>
@@ -1,3 +1,4 @@
// HIGHLIGHT: INFORMATION
class My(val x: Int)
fun foo(arg: Any?): My? {
@@ -1,3 +1,4 @@
// HIGHLIGHT: INFORMATION
class My(val x: Int)
fun foo(arg: Any?): My? {
@@ -1,3 +1,4 @@
// HIGHLIGHT: INFORMATION
class My(val x: Int)
fun foo(arg: Any?): Int? {
@@ -1,3 +1,4 @@
// HIGHLIGHT: INFORMATION
class My(val x: Int)
fun foo(arg: Any?): Int? {
@@ -1 +1,2 @@
// HIGHLIGHT: INFORMATION
fun foo(arg: Any) = <caret>if (arg is String) arg.length else null
@@ -1 +1,2 @@
// HIGHLIGHT: INFORMATION
fun foo(arg: Any) = (arg as? String)?.length
@@ -1 +1,2 @@
// HIGHLIGHT: INFORMATION
fun foo(arg: Any) = <caret>if (arg !is String) null else arg.length
@@ -1 +1,2 @@
// HIGHLIGHT: INFORMATION
fun foo(arg: Any) = (arg as? String)?.length
@@ -1,4 +1,4 @@
// HIGHLIGHT: INFORMATION
// FIX: Replace 'if' expression with safe cast expression
interface Foo
@@ -1,4 +1,4 @@
// HIGHLIGHT: INFORMATION
// FIX: Replace 'if' expression with safe cast expression
interface Foo
@@ -31,38 +31,6 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?:'.</problem_class>
<description>Replace 'if' expression with elvis expression</description>
</problem>
<problem>
<file>notIsCheck.kt</file>
<line>4</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/notIsCheck.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?:'</problem_class>
<description>Replace 'if' expression with elvis expression</description>
</problem>
<problem>
<file>isCheck.kt</file>
<line>4</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/isCheck.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?:'</problem_class>
<description>Replace 'if' expression with elvis expression</description>
</problem>
<problem>
<file>isCheckWithSelector.kt</file>
<line>4</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="isCheckWithSelector.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?:'</problem_class>
<description>Replace 'if' expression with elvis expression</description>
</problem>
<problem>
<file>isCheckWithSelectorChain.kt</file>
<line>4</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="isCheckWithSelectorChain.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?:'</problem_class>
<description>Replace 'if' expression with elvis expression</description>
</problem>
<problem>
<file>nullCheckWithSelector.kt</file>
<line>4</line>
@@ -103,14 +71,6 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?:'</problem_class>
<description>Replace 'if' expression with elvis expression</description>
</problem>
<problem>
<file>kt19666.kt</file>
<line>7</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/kt19666.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?:'</problem_class>
<description>Replace 'if' expression with elvis expression</description>
</problem>
<problem>
<file>applicableForLocalStableVar.kt</file>
<line>8</line>
@@ -119,4 +79,12 @@
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?:'</problem_class>
<description>Replace 'if' expression with elvis expression</description>
</problem>
<problem>
<file>extensionFunctionInClass.kt</file>
<line>5</line>
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/extensionFunctionInClass.kt" />
<problem_class severity="INFO" attribute_key="INFO_ATTRIBUTES">If-Then foldable to '?:'</problem_class>
<description>Replace 'if' expression with elvis expression</description>
</problem>
</problems>