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 com.intellij.psi.PsiElementVisitor
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||||
|
|
||||||
class RedundantGetterInspection : AbstractKotlinInspection(), CleanupLocalInspectionTool {
|
class RedundantGetterInspection : AbstractKotlinInspection(), CleanupLocalInspectionTool {
|
||||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
|
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
|
||||||
return propertyAccessorVisitor { accessor ->
|
return propertyAccessorVisitor { accessor ->
|
||||||
|
val rangeInElement = accessor.namePlaceholder.textRange?.shiftRight(-accessor.startOffset) ?: return@propertyAccessorVisitor
|
||||||
if (accessor.isRedundantGetter()) {
|
if (accessor.isRedundantGetter()) {
|
||||||
holder.registerProblem(
|
holder.registerProblem(
|
||||||
accessor,
|
accessor,
|
||||||
"Redundant getter",
|
"Redundant getter",
|
||||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||||
|
rangeInElement,
|
||||||
RemoveRedundantGetterFix()
|
RemoveRedundantGetterFix()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,15 +11,18 @@ import com.intellij.psi.PsiElementVisitor
|
|||||||
import org.jetbrains.kotlin.idea.references.mainReference
|
import org.jetbrains.kotlin.idea.references.mainReference
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||||
|
|
||||||
class RedundantSetterInspection : AbstractKotlinInspection(), CleanupLocalInspectionTool {
|
class RedundantSetterInspection : AbstractKotlinInspection(), CleanupLocalInspectionTool {
|
||||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
|
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
|
||||||
return propertyAccessorVisitor { accessor ->
|
return propertyAccessorVisitor { accessor ->
|
||||||
|
val rangeInElement = accessor.namePlaceholder.textRange?.shiftRight(-accessor.startOffset) ?: return@propertyAccessorVisitor
|
||||||
if (accessor.isRedundantSetter()) {
|
if (accessor.isRedundantSetter()) {
|
||||||
holder.registerProblem(
|
holder.registerProblem(
|
||||||
accessor,
|
accessor,
|
||||||
"Redundant setter",
|
"Redundant setter",
|
||||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||||
|
rangeInElement,
|
||||||
RemoveRedundantSetterFix()
|
RemoveRedundantSetterFix()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// PROBLEM: none
|
// PROBLEM: none
|
||||||
class Test {
|
class Test {
|
||||||
var x = 1
|
var x = 1
|
||||||
<caret>private set
|
private <caret>set
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
// PROBLEM: none
|
// PROBLEM: none
|
||||||
class Test {
|
class Test {
|
||||||
internal var x = 1
|
internal var x = 1
|
||||||
<caret>private set
|
private <caret>set
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
// PROBLEM: none
|
// PROBLEM: none
|
||||||
class Test {
|
class Test {
|
||||||
protected var x = 1
|
protected var x = 1
|
||||||
<caret>private set
|
private <caret>set
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
class Test {
|
class Test {
|
||||||
internal var x = 1
|
internal var x = 1
|
||||||
<caret>internal set
|
internal <caret>set
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
class Test {
|
class Test {
|
||||||
protected var x = 1
|
protected var x = 1
|
||||||
<caret>protected set
|
protected <caret>set
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
class Test {
|
class Test {
|
||||||
private var x = 1
|
private var x = 1
|
||||||
<caret>private set
|
private <caret>set
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user