Remove Redundant Backticks: Fix inspection applicability
#KT-22804 Fixed
This commit is contained in:
+12
-6
@@ -15,14 +15,20 @@
|
|||||||
*/
|
*/
|
||||||
package org.jetbrains.kotlin.idea.inspections
|
package org.jetbrains.kotlin.idea.inspections
|
||||||
|
|
||||||
import com.intellij.codeInspection.*
|
import com.intellij.codeInspection.LocalQuickFix
|
||||||
|
import com.intellij.codeInspection.ProblemDescriptor
|
||||||
|
import com.intellij.codeInspection.ProblemHighlightType
|
||||||
|
import com.intellij.codeInspection.ProblemsHolder
|
||||||
import com.intellij.lang.ASTNode
|
import com.intellij.lang.ASTNode
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.PsiElementVisitor
|
import com.intellij.psi.PsiElementVisitor
|
||||||
import com.intellij.psi.impl.source.tree.SharedImplUtil
|
import com.intellij.psi.impl.source.tree.SharedImplUtil
|
||||||
|
import org.jetbrains.kotlin.idea.core.unquote
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.KtElement
|
||||||
|
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||||
|
import org.jetbrains.kotlin.psi.KtVisitorVoid
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.isIdentifier
|
import org.jetbrains.kotlin.psi.psiUtil.isIdentifier
|
||||||
|
|
||||||
class RemoveRedundantBackticksInspection : AbstractKotlinInspection() {
|
class RemoveRedundantBackticksInspection : AbstractKotlinInspection() {
|
||||||
@@ -44,10 +50,10 @@ class RemoveRedundantBackticksInspection : AbstractKotlinInspection() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun isRedundantBackticks(node: ASTNode): Boolean {
|
private fun isRedundantBackticks(node: ASTNode): Boolean {
|
||||||
return (node.text.startsWith("`") &&
|
val text = node.text
|
||||||
node.text.endsWith("`") &&
|
if (!(text.startsWith("`") && text.endsWith("`"))) return false
|
||||||
node.text.isIdentifier() &&
|
val unquotedText = text.unquote()
|
||||||
!isKeyword(node.text.removePrefix("`").removeSuffix("`")))
|
return unquotedText.isIdentifier() && !isKeyword(unquotedText)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun registerProblem(holder: ProblemsHolder, element: PsiElement) {
|
private fun registerProblem(holder: ProblemsHolder, element: PsiElement) {
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
// PROBLEM: none
|
// PROBLEM: none
|
||||||
fun foo() {
|
fun foo() {
|
||||||
<caret>val ` two words ` = "two words"
|
val <caret>` two words ` = "two words"
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user