Skip to content

Commit a194eb9

Browse files
committed
Remove Redundant Backticks: Fix inspection applicability
#KT-22804 Fixed
1 parent f65fe0d commit a194eb9

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

idea/src/org/jetbrains/kotlin/idea/inspections/RemoveRedundantBackticksInspection.kt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,20 @@
1515
*/
1616
package org.jetbrains.kotlin.idea.inspections
1717

18-
import com.intellij.codeInspection.*
18+
import com.intellij.codeInspection.LocalQuickFix
19+
import com.intellij.codeInspection.ProblemDescriptor
20+
import com.intellij.codeInspection.ProblemHighlightType
21+
import com.intellij.codeInspection.ProblemsHolder
1922
import com.intellij.lang.ASTNode
2023
import com.intellij.openapi.project.Project
2124
import com.intellij.psi.PsiElement
2225
import com.intellij.psi.PsiElementVisitor
2326
import com.intellij.psi.impl.source.tree.SharedImplUtil
27+
import org.jetbrains.kotlin.idea.core.unquote
2428
import org.jetbrains.kotlin.lexer.KtTokens
25-
import org.jetbrains.kotlin.psi.*
29+
import org.jetbrains.kotlin.psi.KtElement
30+
import org.jetbrains.kotlin.psi.KtPsiFactory
31+
import org.jetbrains.kotlin.psi.KtVisitorVoid
2632
import org.jetbrains.kotlin.psi.psiUtil.isIdentifier
2733

2834
class RemoveRedundantBackticksInspection : AbstractKotlinInspection() {
@@ -44,10 +50,10 @@ class RemoveRedundantBackticksInspection : AbstractKotlinInspection() {
4450
}
4551

4652
private fun isRedundantBackticks(node: ASTNode): Boolean {
47-
return (node.text.startsWith("`") &&
48-
node.text.endsWith("`") &&
49-
node.text.isIdentifier() &&
50-
!isKeyword(node.text.removePrefix("`").removeSuffix("`")))
53+
val text = node.text
54+
if (!(text.startsWith("`") && text.endsWith("`"))) return false
55+
val unquotedText = text.unquote()
56+
return unquotedText.isIdentifier() && !isKeyword(unquotedText)
5157
}
5258

5359
private fun registerProblem(holder: ProblemsHolder, element: PsiElement) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// PROBLEM: none
22
fun foo() {
3-
<caret>val ` two words ` = "two words"
3+
val <caret>` two words ` = "two words"
44
}

0 commit comments

Comments
 (0)