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

import com.intellij.openapi.util.Key
import com.intellij.openapi.util.text.StringUtil
import com.intellij.psi._
import com.intellij.psi.scope._
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.plugins.scala.extensions._
import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil
import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScSuperReference, ScThisReference}
import org.jetbrains.plugins.scala.lang.psi.api.statements.ScTypeAlias
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypedDefinition
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScObject, ScTrait}
import org.jetbrains.plugins.scala.lang.psi.impl.ScPackageImpl
import org.jetbrains.plugins.scala.lang.psi.types.{ApplicabilityProblem, TypeIsNotStable}
import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil
import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveState.ResolveStateExt
import org.jetbrains.plugins.scala.lang.resolve.processor.precedence._

class ResolveProcessor(override val kinds: Set[ResolveTargets.Value],
                       val ref: PsiElement,
                       val name: String) extends BaseProcessor(kinds)(ref) with PrecedenceHelper {

  private object ResolveStrategy extends NameUniquenessStrategy {

    override def isValid(result: ScalaResolveResult): Boolean = result.qualifiedNameId != null

    override def hashCode(result: ScalaResolveResult): Int = result.qualifiedNameId match {
      case null => 0
      case id   => id.hashCode
    }

    override def equals(left: ScalaResolveResult, right: ScalaResolveResult): Boolean =
      if (left == null || right == null) false
      else left.qualifiedNameId == right.qualifiedNameId
  }

  @volatile
  private var resolveScope: GlobalSearchScope = _

  def getResolveScope: GlobalSearchScope = {
    if (resolveScope == null) {
      resolveScope = ref.resolveScope
    }
    resolveScope
  }

  override protected def getPlace: PsiElement = ref

  private[this] val isThisOrSuperResolve = ref.getParent match {
    case _: ScThisReference | _: ScSuperReference => true
    case _                                        => false
  }

  override protected def nameUniquenessStrategy: NameUniquenessStrategy = ResolveStrategy

  override protected val holder: SimpleTopPrecedenceHolder = new SimpleTopPrecedenceHolder

  /**
    * This method useful for resetting precednce if we dropped<commit_msg>Fix ResolveStrategy equals implementation<commit_after>package org.jetbrains.plugins.scala
package lang
package resolve
package processor

import com.intellij.openapi.util.Key
import com.intellij.openapi.util.text.StringUtil
import com.intellij.psi._
import com.intellij.psi.scope._
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.plugins.scala.extensions._
import org.jetbrains.plugins.scala.lang.psi.ScalaPsiUtil
import org.jetbrains.plugins.scala.lang.psi.api.expr.{ScSuperReference, ScThisReference}
import org.jetbrains.plugins.scala.lang.psi.api.statements.ScTypeAlias
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScTypedDefinition
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ScClass, ScObject, ScTrait}
import org.jetbrains.plugins.scala.lang.psi.impl.ScPackageImpl
import org.jetbrains.plugins.scala.lang.psi.types.{ApplicabilityProblem, TypeIsNotStable}
import org.jetbrains.plugins.scala.lang.refactoring.util.ScalaNamesUtil
import org.jetbrains.plugins.scala.lang.resolve.ScalaResolveState.ResolveStateExt
import org.jetbrains.plugins.scala.lang.resolve.processor.precedence._

class ResolveProcessor(override val kinds: Set[ResolveTargets.Value],
                       val ref: PsiElement,
                       val name: String) extends BaseProcessor(kinds)(ref) with PrecedenceHelper {

  private object ResolveStrategy extends NameUniquenessStrategy {

    override def isValid(result: ScalaResolveResult): Boolean = result.qualifiedNameId != null

    override def hashCode(result: ScalaResolveResult): Int = result.qualifiedNameId match {
      case null => 0
      case id   => id.hashCode
    }

    override def equals(left: ScalaResolveResult, right: ScalaResolveResult): Boolean =
      if (left == null && right == null) true
      else if (left == null || right == null) false
      else left.qualifiedNameId == right.qualifiedNameId
  }

  @volatile
  private var resolveScope: GlobalSearchScope = _

  def getResolveScope: GlobalSearchScope = {
    if (resolveScope == null) {
      resolveScope = ref.resolveScope
    }
    resolveScope
  }

  override protected def getPlace: PsiElement = ref

  private[this] val isThisOrSuperResolve = ref.getParent match {
    case _: ScThisReference | _: ScSuperReference => true
    case _                                        => false
  }

  override protected def nameUniquenessStrategy: NameUniquenessStrategy = ResolveStrategy

  override protected val holder: SimpleTopPrecedenceHolder = new SimpleTopPrecedenceHolder

  /**
    * This method useful for resetting precednce if we dropped
{'fraction_non_alphanumeric': 0.08360374117197938, 'fraction_numerical': 0.0003817522427944264, 'mean_word_length': 4.1171875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5400967', 'n_tokens_mistral': 1554, 'n_tokens_neox': 1475, 'n_words': 319}