<commit_before>package org.jetbrains.plugins.scala
package lang
package resolve
package processor

import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.util.Key
import com.intellij.psi.scope._
import com.intellij.psi._
import _root_.scala.collection.Set
import org.jetbrains.plugins.scala.lang.psi.api._
import expr.ScReferenceExpression
import statements.{ScTypeAlias}
import psi.types._
import psi.ScalaPsiElement
import psi.impl.toplevel.typedef.TypeDefinitionMembers
import toplevel.imports.usages.ImportUsed
import ResolveTargets._
import psi.impl.toplevel.synthetic.SyntheticClasses
import _root_.scala.collection.mutable.HashSet
import com.intellij.psi.util.PsiTreeUtil
import toplevel.typedef.ScTemplateDefinition


object BaseProcessor {
  def unapply(p: BaseProcessor) = Some(p.kinds)

  val boundClassKey: Key[PsiClass] = Key.create("bound.class.key")
}

abstract class BaseProcessor(val kinds: Set[ResolveTargets.Value]) extends PsiScopeProcessor {
  protected val candidatesSet: HashSet[ScalaResolveResult] = new HashSet[ScalaResolveResult]

  def changedLevel = true

  def candidates[T >: ScalaResolveResult : ClassManifest]: Array[T] = candidatesSet.toArray[T]

  //java compatibility
  object MyElementClassHint extends ElementClassHint {
    import ElementClassHint.DeclaractionKind
    def shouldProcess(kind: DeclaractionKind): Boolean = {
      kind match {
        case null => true
        case DeclaractionKind.PACKAGE => kinds contains ResolveTargets.PACKAGE
        case DeclaractionKind.CLASS => (kinds contains ResolveTargets.CLASS) || (kinds contains ResolveTargets.OBJECT) ||
                (kinds contains ResolveTargets.METHOD) //case classes get 'apply' generated
        case DeclaractionKind.VARIABLE => (kinds contains ResolveTargets.VAR) || (kinds contains ResolveTargets.VAL)
        case DeclaractionKind.FIELD => (kinds contains ResolveTargets.VAR) || (kinds contains ResolveTargets.VAL)
        case DeclaractionKind.METHOD => kinds contains (ResolveTargets.METHOD)
        case _ => false
      }
    }
  }

  def getHint[T](hintKey: Key[T]): T = {
    if (hintKey == ElementClassHint.KEY) {
      return MyElementClassHint.asInstanceOf[T]
    } else {
      return null.asInstanceOf[T]
    }
  }

  def handleEvent(event: PsiScopeProcessor.Event, associated: Object) = {}

  protected def kindMatches(element: PsiElement): Boolean = ResolveUtils.kindMatches(element, kinds)

  def processType(t: ScType, place: ScalaPsiElement): Boolean = processType(t, place, ResolveState.initial)

  def processType(t: ScType, place: ScalaPsiElement, state: ResolveState): Boolean = {
    ProgressManager.checkCanceled

    def isInApplyCall = place.getContext match {
      case expr: ScReferenceExpression => expr.nameId.getText == "apply"
      case _ => false
    }

    t match {
      case ScDesignatorType(e) => processElement(e, ScSubstitutor.empty, place, state)
      case ScPolymorphicType(_, Nil, _, upper) => processType(upper.v, place)
      case j: JavaArrayType => processType(j.getParameterizedType(place.getProject, place.getResolveScope).getOrElse(return true), place, state)
      case p@ScParameterizedType(des, typeArgs) => {
        p.designator match {
          case ScPolymorphicType(_, _, _, upper) => processType(p.substitutor.subst(upper.v), place)
          case _ => p.designated match {
            case Some(des) => processElement(des, p.substitutor, place, state)
            case None => true
          }
        }
      }
      //resolve dependent types case
      case proj@ScProjectionType(des, ref) => proj.resolveResult match {
        case Some(res) => {
          val clazz = PsiTreeUtil.getContextOfType(res.element, classOf[PsiClass], true)
          val subst = if (clazz != null) {
            des match {
              case ScDesignatorType(c: PsiClass) if c != clazz =>
                {
                  Bounds.superSubstitutor(clazz, c, res.substitutor.bindD(clazz, c)) match {
                    case Some(s) => {
                      if (c.isInstanceOf[ScTemplateDefinition]) {
                        Bounds.putAliases(c.asInstanceOf[ScTemplateDefinition], s)
                      } else s
                    }
                    case _ => res.substitutor.bindD(clazz, c)
                  }
                }
              case ScDesignatorType(elem) if elem != clazz => res.substitutor.bindD(clazz, elem)
              case s@ScSingletonType(path) => {
                s.pathType match {
                  case ScDesignatorType(c: PsiClass) => {
                    Bounds.superSubstitutor(clazz, c, res.substitutor.bindD(clazz, c)) match {
                      case Some(s) => {
                        if (c.isInstanceOf[ScTemplateDefinition]) {
                          Bounds.putAliases(c.asInstanceOf[ScTemplateDefinition], s)
                        } else s
                      }
                      case _ => res.substitutor.bindD(clazz, c)
                    }
                  }
                  case ScDesignatorType(elem) if elem != clazz => res.substitutor.bindD(clazz, elem)
                  case _ => res.substitutor
                }
              }
              case _ => res.substitutor
            }
          } else res.substitutor
          processElement(res.element, subst, place, state)
        }
        case None => true
      }

      case StdType(name, tSuper) => (SyntheticClasses.get(place.getProject).byName(name): @unchecked) match {
        case Some(c) => {
          c.processDeclarations(this, state, null, place) &&
                  (tSuper match {
                    case Some(ts) => processType(ts, place)
                    case _ => true
                  })
        }
        case None => true//nothing to do
      }
<commit_msg>fix for calling toString, hashCode, equals from primitive types.<commit_after>package org.jetbrains.plugins.scala
package lang
package resolve
package processor

import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.util.Key
import com.intellij.psi.scope._
import com.intellij.psi._
import _root_.scala.collection.Set
import org.jetbrains.plugins.scala.lang.psi.api._
import expr.ScReferenceExpression
import statements.{ScTypeAlias}
import psi.types._
import psi.ScalaPsiElement
import psi.impl.toplevel.typedef.TypeDefinitionMembers
import toplevel.imports.usages.ImportUsed
import ResolveTargets._
import psi.impl.toplevel.synthetic.SyntheticClasses
import _root_.scala.collection.mutable.HashSet
import com.intellij.psi.util.PsiTreeUtil
import toplevel.typedef.ScTemplateDefinition


object BaseProcessor {
  def unapply(p: BaseProcessor) = Some(p.kinds)

  val boundClassKey: Key[PsiClass] = Key.create("bound.class.key")
}

abstract class BaseProcessor(val kinds: Set[ResolveTargets.Value]) extends PsiScopeProcessor {
  protected val candidatesSet: HashSet[ScalaResolveResult] = new HashSet[ScalaResolveResult]

  def changedLevel = true

  def candidates[T >: ScalaResolveResult : ClassManifest]: Array[T] = candidatesSet.toArray[T]

  //java compatibility
  object MyElementClassHint extends ElementClassHint {
    import ElementClassHint.DeclaractionKind
    def shouldProcess(kind: DeclaractionKind): Boolean = {
      kind match {
        case null => true
        case DeclaractionKind.PACKAGE => kinds contains ResolveTargets.PACKAGE
        case DeclaractionKind.CLASS => (kinds contains ResolveTargets.CLASS) || (kinds contains ResolveTargets.OBJECT) ||
                (kinds contains ResolveTargets.METHOD) //case classes get 'apply' generated
        case DeclaractionKind.VARIABLE => (kinds contains ResolveTargets.VAR) || (kinds contains ResolveTargets.VAL)
        case DeclaractionKind.FIELD => (kinds contains ResolveTargets.VAR) || (kinds contains ResolveTargets.VAL)
        case DeclaractionKind.METHOD => kinds contains (ResolveTargets.METHOD)
        case _ => false
      }
    }
  }

  def getHint[T](hintKey: Key[T]): T = {
    if (hintKey == ElementClassHint.KEY) {
      return MyElementClassHint.asInstanceOf[T]
    } else {
      return null.asInstanceOf[T]
    }
  }

  def handleEvent(event: PsiScopeProcessor.Event, associated: Object) = {}

  protected def kindMatches(element: PsiElement): Boolean = ResolveUtils.kindMatches(element, kinds)

  def processType(t: ScType, place: ScalaPsiElement): Boolean = processType(t, place, ResolveState.initial)

  def processType(t: ScType, place: ScalaPsiElement, state: ResolveState): Boolean = {
    ProgressManager.checkCanceled

    def isInApplyCall = place.getContext match {
      case expr: ScReferenceExpression => expr.nameId.getText == "apply"
      case _ => false
    }

    t match {
      case ScDesignatorType(e) => processElement(e, ScSubstitutor.empty, place, state)
      case ScPolymorphicType(_, Nil, _, upper) => processType(upper.v, place)
      case j: JavaArrayType => processType(j.getParameterizedType(place.getProject, place.getResolveScope).getOrElse(return true), place, state)
      case p@ScParameterizedType(des, typeArgs) => {
        p.designator match {
          case ScPolymorphicType(_, _, _, upper) => processType(p.substitutor.subst(upper.v), place)
          case _ => p.designated match {
            case Some(des) => processElement(des, p.substitutor, place, state)
            case None => true
          }
        }
      }
      //resolve dependent types case
      case proj@ScProjectionType(des, ref) => proj.resolveResult match {
        case Some(res) => {
          val clazz = PsiTreeUtil.getContextOfType(res.element, classOf[PsiClass], true)
          val subst = if (clazz != null) {
            des match {
              case ScDesignatorType(c: PsiClass) if c != clazz =>
                {
                  Bounds.superSubstitutor(clazz, c, res.substitutor.bindD(clazz, c)) match {
                    case Some(s) => {
                      if (c.isInstanceOf[ScTemplateDefinition]) {
                        Bounds.putAliases(c.asInstanceOf[ScTemplateDefinition], s)
                      } else s
                    }
                    case _ => res.substitutor.bindD(clazz, c)
                  }
                }
              case ScDesignatorType(elem) if elem != clazz => res.substitutor.bindD(clazz, elem)
              case s@ScSingletonType(path) => {
                s.pathType match {
                  case ScDesignatorType(c: PsiClass) => {
                    Bounds.superSubstitutor(clazz, c, res.substitutor.bindD(clazz, c)) match {
                      case Some(s) => {
                        if (c.isInstanceOf[ScTemplateDefinition]) {
                          Bounds.putAliases(c.asInstanceOf[ScTemplateDefinition], s)
                        } else s
                      }
                      case _ => res.substitutor.bindD(clazz, c)
                    }
                  }
                  case ScDesignatorType(elem) if elem != clazz => res.substitutor.bindD(clazz, elem)
                  case _ => res.substitutor
                }
              }
              case _ => res.substitutor
            }
          } else res.substitutor
          processElement(res.element, subst, place, state)
        }
        case None => true
      }

      case StdType(name, tSuper) => (SyntheticClasses.get(place.getProject).byName(name): @unchecked) match {
        case Some(c) => {
          if (!c.processDeclarations(this, state, null, place) ||
                  !(tSuper match {
                    case Some(ts) => processType(ts, place)
                    case _ => true
                  })) return false

          if (name == "Any") {
            for (m <- c.methods) {
              m._1 match {
                case "toString" | "hashCode" | "equals" => for (meth <- m._2) this.execute(meth, state)
                case _ => //do nothing
              }
            }
          }
          true
        }
        case None => true//nothing to do
      }

{'fraction_non_alphanumeric': 0.09822099724379854, 'fraction_numerical': 0.00016704251231938527, 'mean_word_length': 2.3644282101713965, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 79, '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': '4760323', 'n_tokens_mistral': 3508, 'n_tokens_neox': 3370, 'n_words': 736}