Remove Redundant Backticks: Fix inspection applicability

#KT-22804 Fixed
This commit is contained in:
Alexey Sedunov
2018-02-20 16:29:32 +03:00
parent f65fe0dd5f
commit a194eb94cf
2 changed files with 13 additions and 7 deletions
@@ -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,4 +1,4 @@
// PROBLEM: none // PROBLEM: none
fun foo() { fun foo() {
<caret>val ` two words ` = "two words" val <caret>` two words ` = "two words"
} }