<commit_before>package org.rust.lang.refactoring

import com.intellij.lang.refactoring.NamesValidator
import com.intellij.openapi.project.Project
import com.intellij.psi.tree.IElementType
import org.rust.lang.core.lexer.RsLexer
import org.rust.lang.core.psi.RS_KEYWORDS
import org.rust.lang.core.psi.RsElementTypes.IDENTIFIER
import org.rust.lang.core.psi.RsElementTypes.QUOTE_IDENTIFIER

class RsNamesValidator : NamesValidator {
    override fun isKeyword(name: String, project: Project?): Boolean =
        isKeyword(name, project, true)

    fun isKeyword(name: String, @Suppress("UNUSED_PARAMETER") project: Project?, withPrimitives: Boolean): Boolean =
        getLexerType(name) in RS_KEYWORDS || (withPrimitives && name in PrimitiveTypes)

    override fun isIdentifier(name: String, project: Project?): Boolean =
        isIdentifier(name, project, true)

    fun isIdentifier(name: String, @Suppress("UNUSED_PARAMETER") project: Project?, withPrimitives: Boolean): Boolean =
        when (getLexerType(name)) {
            IDENTIFIER -> !withPrimitives || name !in PrimitiveTypes
            QUOTE_IDENTIFIER -> true
            else -> false
        }

    private fun getLexerType(text: String): IElementType? {
        val lexer = RsLexer()
        lexer.start(text)
        if (lexer.tokenEnd == text.length) {
            return lexer.tokenType
        } else {
            return null
        }
    }

    companion object {
        val PrimitiveTypes = arrayOf(
            "bool",
            "char",
            "i8",
            "i16",
            "i32",
            "i64",
            "u8",
            "u16",
            "u32",
            "u64",
            "isize",
            "usize",
            "f32",
            "f64",
            "str"
        )

        val PredefinedLifetimes = arrayOf("'static")
    }
}<commit_msg>REN: Allow to use primitive type names in renaming<commit_after>package org.rust.lang.refactoring

import com.intellij.lang.refactoring.NamesValidator
import com.intellij.openapi.project.Project
import com.intellij.psi.tree.IElementType
import org.rust.lang.core.lexer.RsLexer
import org.rust.lang.core.psi.RS_KEYWORDS
import org.rust.lang.core.psi.RsElementTypes.IDENTIFIER
import org.rust.lang.core.psi.RsElementTypes.QUOTE_IDENTIFIER

class RsNamesValidator : NamesValidator {

    override fun isKeyword(name: String, project: Project?): Boolean = getLexerType(name) in RS_KEYWORDS

    override fun isIdentifier(name: String, project: Project?): Boolean =
        when (getLexerType(name)) {
            IDENTIFIER, QUOTE_IDENTIFIER -> true
            else -> false
        }

    private fun getLexerType(text: String): IElementType? {
        val lexer = RsLexer()
        lexer.start(text)
        return if (lexer.tokenEnd == text.length) lexer.tokenType else null
    }

    companion object {
        val PredefinedLifetimes = arrayOf("'static")
    }
}
{'fraction_non_alphanumeric': 0.1032590051457976, 'fraction_numerical': 0.0061749571183533445, 'mean_word_length': 2.631382316313823, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2402781', 'n_tokens_mistral': 922, 'n_tokens_neox': 878, 'n_words': 187}