<commit_before>package org.jetbrains.plugins.scala.lang.refactoring

import _root_.scala.collection.mutable.HashSet
import psi.types._
import psi.api.expr._
import java.util.regex.Matcher
import java.util.regex.Pattern
import org.jetbrains.plugins.scala.lang.psi.api.base.ScReferenceElement
import _root_.scala.collection.mutable.ArrayBuffer
/**
* User: Alexander.Podkhalyuz
* Date: 26.06.2008
*/

object NameSuggester {
  def suggestNames(expr: ScExpression, validator: NameValidator): Array[String] = {
    val names = new HashSet[String]
    generateNamesByType(expr.getType, names, validator)
    generateNamesByExpr(expr, names, validator)
    if (names.size == 0) {
      names += validator.validateName("value", true)
    }
    names.filter((s: String) => ScalaNamesUtil.isIdentifier(s))

    return (for (name <- names if name != "") yield {
      if (name != "class") name else "clazz"
    }).toList.reverse.toArray
  }

  private def generateNamesByType(typez: ScType, names: HashSet[String], validator: NameValidator): Unit = {
    def add(s: String) {
      names += validator.validateName(s, true)
    }
    typez match {
      case ValType(name, _) => {
        name match {
          case "Int" => add("i")
          case "Unit" => add("unit")
          case "Byte" => add("byte")
          case "Long" => add("l")
          case "Float" => add("fl")
          case "Double" => add("d")
          case "Short" => add("sh")<commit_msg>SCL-216 Name suggester<commit_after>package org.jetbrains.plugins.scala.lang.refactoring

import _root_.scala.collection.mutable.HashSet
import psi.types._
import psi.api.expr._
import java.util.regex.Matcher
import java.util.regex.Pattern
import org.jetbrains.plugins.scala.lang.psi.api.base.ScReferenceElement
import _root_.scala.collection.mutable.ArrayBuffer

/**
* User: Alexander.Podkhalyuz
* Date: 26.06.2008
*/

object NameSuggester {
  def suggestNames(expr: ScExpression, validator: NameValidator): Array[String] = {
    val names = new HashSet[String]
    generateNamesByType(expr.getType, names, validator)
    generateNamesByExpr(expr, names, validator)
    if (names.size == 0) {
      names += validator.validateName("value", true)
    }

    return (for (name <- names if name != "" && ScalaNamesUtil.isIdentifier(name) || name == "class") yield {
      if (name != "class") name else "clazz"
    }).toList.reverse.toArray
  }

  private def generateNamesByType(typez: ScType, names: HashSet[String], validator: NameValidator): Unit = {
    def add(s: String) {
      names += validator.validateName(s, true)
    }
    typez match {
      case ValType(name, _) => {
        name match {
          case "Int" => add("i")
          case "Unit" => add("unit")
          case "Byte" => add("byte")
          case "Long" => add("l")
          case "Float" => add("fl")
          case "Double" => add("d")
          case "Short" => add("sh")
{'fraction_non_alphanumeric': 0.14310344827586208, 'fraction_numerical': 0.007241379310344828, 'mean_word_length': 3.241228070175439, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 20, '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': '682508', 'n_tokens_mistral': 944, 'n_tokens_neox': 911, 'n_words': 207}