Refactor: Move 'isIdentifier' and 'quoteIfNeeded' functions to frontend

This commit is contained in:
Alexey Sedunov
2018-02-06 19:28:07 +03:00
parent fddfbf225f
commit 428b086458
36 changed files with 100 additions and 103 deletions
@@ -28,6 +28,7 @@ import com.intellij.psi.tree.TokenSet
import org.jetbrains.kotlin.KtNodeTypes
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.lexer.KotlinLexer
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.name.Name
@@ -573,4 +574,16 @@ fun KtExpression.getLabeledParent(labelName: String): KtLabeledExpression? {
fun PsiElement.astReplace(newElement: PsiElement) = parent.node.replaceChild(node, newElement.node)
var KtElement.parentSubstitute: PsiElement? by UserDataProperty(Key.create<PsiElement>("PARENT_SUBSTITUTE"))
var KtElement.parentSubstitute: PsiElement? by UserDataProperty(Key.create<PsiElement>("PARENT_SUBSTITUTE"))
fun String?.isIdentifier(): Boolean {
if (this == null || isEmpty()) return false
val lexer = KotlinLexer()
lexer.start(this, 0, length)
if (lexer.tokenType !== KtTokens.IDENTIFIER) return false
lexer.advance()
return lexer.tokenType == null
}
fun String.quoteIfNeeded(): String = if (this.isIdentifier()) this else "`$this`"