Redundant getter/setter: reduce hightlight range to header
#KT-30559 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
0cf641398c
commit
3b569737ad
@@ -10,15 +10,18 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiElementVisitor
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
|
||||
class RedundantGetterInspection : AbstractKotlinInspection(), CleanupLocalInspectionTool {
|
||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
|
||||
return propertyAccessorVisitor { accessor ->
|
||||
val rangeInElement = accessor.namePlaceholder.textRange?.shiftRight(-accessor.startOffset) ?: return@propertyAccessorVisitor
|
||||
if (accessor.isRedundantGetter()) {
|
||||
holder.registerProblem(
|
||||
accessor,
|
||||
"Redundant getter",
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||
rangeInElement,
|
||||
RemoveRedundantGetterFix()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -11,15 +11,18 @@ import com.intellij.psi.PsiElementVisitor
|
||||
import org.jetbrains.kotlin.idea.references.mainReference
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
|
||||
class RedundantSetterInspection : AbstractKotlinInspection(), CleanupLocalInspectionTool {
|
||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
|
||||
return propertyAccessorVisitor { accessor ->
|
||||
val rangeInElement = accessor.namePlaceholder.textRange?.shiftRight(-accessor.startOffset) ?: return@propertyAccessorVisitor
|
||||
if (accessor.isRedundantSetter()) {
|
||||
holder.registerProblem(
|
||||
accessor,
|
||||
"Redundant setter",
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||
rangeInElement,
|
||||
RemoveRedundantSetterFix()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// PROBLEM: none
|
||||
class Test {
|
||||
var x = 1
|
||||
<caret>private set
|
||||
private <caret>set
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
// PROBLEM: none
|
||||
class Test {
|
||||
internal var x = 1
|
||||
<caret>private set
|
||||
private <caret>set
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
// PROBLEM: none
|
||||
class Test {
|
||||
protected var x = 1
|
||||
<caret>private set
|
||||
private <caret>set
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
class Test {
|
||||
internal var x = 1
|
||||
<caret>internal set
|
||||
internal <caret>set
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
class Test {
|
||||
protected var x = 1
|
||||
<caret>protected set
|
||||
protected <caret>set
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
class Test {
|
||||
private var x = 1
|
||||
<caret>private set
|
||||
private <caret>set
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user