Unused unary operator: highlight whole expression in yellow

#KT-37156 Fixed
This commit is contained in:
Toshiaki Kameyama
2020-03-02 19:14:54 +09:00
committed by Yan Zhulanow
parent 43b106fc72
commit 7abd0831a1
2 changed files with 2 additions and 10 deletions
@@ -7,14 +7,12 @@ package org.jetbrains.kotlin.idea.inspections
import com.intellij.codeInspection.LocalQuickFix
import com.intellij.codeInspection.ProblemDescriptor
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.util.textRangeIn
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtPrefixExpression
import org.jetbrains.kotlin.psi.prefixExpressionVisitor
@@ -33,13 +31,7 @@ class UnusedUnaryOperatorInspection : AbstractKotlinInspection() {
val operatorDescriptor = prefix.operationReference.getResolvedCall(context)?.resultingDescriptor as? DeclarationDescriptor ?: return
if (!KotlinBuiltIns.isUnderKotlinPackage(operatorDescriptor)) return
holder.registerProblem(
prefix,
KotlinBundle.message("unused.unary.operator"),
ProblemHighlightType.LIKE_UNUSED_SYMBOL,
prefix.operationReference.textRangeIn(prefix),
RemoveUnaryOperatorFix()
)
holder.registerProblem(prefix, KotlinBundle.message("unused.unary.operator"), RemoveUnaryOperatorFix())
})
private class RemoveUnaryOperatorFix : LocalQuickFix {
@@ -1,6 +1,6 @@
// "Remove unused unary operator" "true"
fun test(foo: Int?): Int {
val a = 1 + 2
<caret>- 3
- 3<caret>
return a
}