Skip to content

Commit

Permalink
fixed name validation when refactoring (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
Danil42Russia authored Nov 12, 2024
1 parent 3698311 commit 86e3a16
Showing 1 changed file with 8 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,21 @@ package org.ton.intellij.tolk.refactor

import com.intellij.lang.refactoring.NamesValidator
import com.intellij.openapi.project.Project
import org.ton.intellij.tolk.psi.TOLK_KEYWORDS
import org.ton.intellij.tolk.psi.TolkTokenType

class TolkNamesValidator : NamesValidator {
override fun isKeyword(name: String, project: Project?): Boolean {
return when (name) {
"return",
"var",
"repeat",
"do",
"while",
"until",
"try",
"catch",
"if",
"ifnot",
"then",
"else",
"elseif",
"elseifnot",
"type",
"forall",
"extern",
"global",
"const",
"asm",
"impure",
"inline",
"inline_ref",
"method_id",
"infix",
"infixl",
"infixr",
"operator",
"auto_apply" -> true
private val KEYWORD_SET = TOLK_KEYWORDS.types.filterIsInstance<TolkTokenType>().map { it.name }.toSet()

else -> false
}
override fun isKeyword(name: String, project: Project?): Boolean {
return KEYWORD_SET.contains(name)
}

override fun isIdentifier(name: String, project: Project?): Boolean {
if (name.isBlank()) return false

if (KEYWORD_SET.contains(name)) return false

if (name.first() == '\"') return false
if (name.first() == '`' && name.last() == '`') {
return name.length >= 3
Expand Down

0 comments on commit 86e3a16

Please sign in to comment.