<commit_before>package org.jetbrains.plugins.scala
package lang
package psi
package types

/**
 * @author ilyas
 */

import api.statements.{ScTypeAliasDefinition, ScTypeAlias}
import api.toplevel.{ScTypeParametersOwner}
import com.intellij.psi.{PsiTypeParameterListOwner, PsiNamedElement}
import api.statements.params.ScTypeParam
import nonvalue.NonValueType
import psi.impl.ScalaPsiManager
import result.TypingContext
import api.base.{ScStableCodeReferenceElement, ScPathElement}
import resolve.ScalaResolveResult

case class ScDesignatorType(val element: PsiNamedElement) extends ValueType {
  override def equiv(t: ScType) = t match {
    case ScDesignatorType(element1) => element eq element1
    case p : ScProjectionType => p equiv this
    case ScSingletonType(path: ScPathElement) => path match {
      case ref: ScStableCodeReferenceElement => {
        ref.bind match {
          case Some(ScalaResolveResult(el: PsiNamedElement, _)) => el == element
          case _ => false
        }
      }
      case _ => false
    }
    case _ => false
  }
}

import _root_.scala.collection.immutable.{Map, HashMap}
import com.intellij.psi.{PsiTypeParameter, PsiClass}

case class ScParameterizedType(designator : ScType, typeArgs : Seq[ScType]) extends ValueType {
  def designated: Option[PsiNamedElement] = ScType.extractDesignated(designator) match {
    case Some((e, _)) => Some(e)
    case _ => None
  }

  val substitutor : ScSubstitutor = {
    val (params, initial): (Seq[ScTypeParameterType], ScSubstitutor) = designator match {
      case ScPolymorphicType(_, args, _, _) => (args, ScSubstitutor.empty)
      case _ => ScType.extractDesignated(designator) match {
        case Some((owner: ScTypeParametersOwner, s)) => (owner.typeParameters.map{tp => ScalaPsiManager.typeVariable(tp)}, s)
        case Some((owner: PsiTypeParameterListOwner, s)) => (owner.getTypeParameters.map({tp => ScalaPsiManager.typeVariable(tp)}).toSeq, s)
        case _ => (Seq.empty, ScSubstitutor.empty)
      }
    }

    params match {
      case Seq() => initial
      case _ => {
        var res = initial
        for (p <- params.toArray zip typeArgs) {
          res = res bindT (p._1.name, p._2)
        }
        res
      }
    }<commit_msg>performance improvement (substitutor is lazy for Parameterized type)<commit_after>package org.jetbrains.plugins.scala
package lang
package psi
package types

/**
 * @author ilyas
 */

import api.statements.{ScTypeAliasDefinition, ScTypeAlias}
import api.toplevel.{ScTypeParametersOwner}
import com.intellij.psi.{PsiTypeParameterListOwner, PsiNamedElement}
import api.statements.params.ScTypeParam
import nonvalue.NonValueType
import psi.impl.ScalaPsiManager
import result.TypingContext
import api.base.{ScStableCodeReferenceElement, ScPathElement}
import resolve.ScalaResolveResult

case class ScDesignatorType(val element: PsiNamedElement) extends ValueType {
  override def equiv(t: ScType) = t match {
    case ScDesignatorType(element1) => element eq element1
    case p : ScProjectionType => p equiv this
    case ScSingletonType(path: ScPathElement) => path match {
      case ref: ScStableCodeReferenceElement => {
        ref.bind match {
          case Some(ScalaResolveResult(el: PsiNamedElement, _)) => el == element
          case _ => false
        }
      }
      case _ => false
    }
    case _ => false
  }
}

import _root_.scala.collection.immutable.{Map, HashMap}
import com.intellij.psi.{PsiTypeParameter, PsiClass}

case class ScParameterizedType(designator : ScType, typeArgs : Seq[ScType]) extends ValueType {
  def designated: Option[PsiNamedElement] = ScType.extractDesignated(designator) match {
    case Some((e, _)) => Some(e)
    case _ => None
  }

  lazy val substitutor : ScSubstitutor = {
    val (params, initial): (Seq[ScTypeParameterType], ScSubstitutor) = designator match {
      case ScPolymorphicType(_, args, _, _) => (args, ScSubstitutor.empty)
      case _ => ScType.extractDesignated(designator) match {
        case Some((owner: ScTypeParametersOwner, s)) => (owner.typeParameters.map{tp => ScalaPsiManager.typeVariable(tp)}, s)
        case Some((owner: PsiTypeParameterListOwner, s)) => (owner.getTypeParameters.map({tp => ScalaPsiManager.typeVariable(tp)}).toSeq, s)
        case _ => (Seq.empty, ScSubstitutor.empty)
      }
    }

    params match {
      case Seq() => initial
      case _ => {
        var res = initial
        for (p <- params.toArray zip typeArgs) {
          res = res bindT (p._1.name, p._2)
        }
        res
      }
    }
{'fraction_non_alphanumeric': 0.10572687224669604, 'fraction_numerical': 0.001762114537444934, 'mean_word_length': 3.6008105369807497, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, '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': '5219158', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1378, 'n_words': 318}