<commit_before>package org.jetbrains.plugins.scala.lang.psi.impl.base.patterns

import api.expr.ScMatchStmt
import _root_.org.jetbrains.plugins.scala.lang.psi.types.ScType
import api.statements.{ScValue, ScVariable}
import api.base.patterns._
import api.toplevel.ScTyped
import api.base.ScPatternList
import com.intellij.lang.ASTNode
import _root_.scala.collection.mutable.ArrayBuffer
import com.intellij.psi._
import com.intellij.psi.scope._

class ScPatternImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScPattern {
  def bindings : Seq[ScBindingPattern] = {
    val b = new ArrayBuffer[ScBindingPattern]
    _bindings(this, b)
    b
  }

  private def _bindings(p : ScPattern, b : ArrayBuffer[ScBindingPattern]) : Unit = {
    p match {
      case binding: ScBindingPattern => b += binding
      case _ =>
    }

    for (sub <- p.subpatterns) {
      _bindings(sub, b)
    }
  }

  def subpatterns : Seq[ScPattern] = {
    if (!this.isInstanceOf[ScTuplePattern])
      findChildrenByClass(classOf[ScPattern])
    else
      findChildByClass(classOf[ScPatterns]).patterns
  }

  def expectedType :Option[ScType] = getParent match {
    case list : ScPatternList => list.getParent match {
      case _var : ScVariable => Some(_var.getType)
      case _val : ScValue => Some(_val.getType)
    }
    case argList : ScPatternArgumentList => {
      argList.getParent match {
        case constr : ScConstructorPattern => constr.bindParamTypes match {
          case Some(ts) =>
            for ((p, t) <- constr.args.patterns.elements zip ts.elements) {
              if (p == this) return Some(t)
            }
            None
          case _ => None
        }
      }
    }
    case clause : ScCaseClause => clause.getParent/*clauses*/.getParent match {
      case matchStat : ScMatchStmt => matchStat.expr match {
        case Some(e) => Some(e.getType)
        case _ => None
      }
    }
    case _ => None //todo
  }
}<commit_msg>SCL-221<commit_after>package org.jetbrains.plugins.scala.lang.psi.impl.base.patterns

import _root_.org.jetbrains.plugins.scala.lang.psi.types.ScDesignatorType
import api.expr.{ScMatchStmt, ScCatchBlock}
import _root_.org.jetbrains.plugins.scala.lang.psi.types.ScType
import api.statements.{ScValue, ScVariable}
import api.base.patterns._
import api.toplevel.ScTyped
import api.base.ScPatternList
import com.intellij.lang.ASTNode
import _root_.scala.collection.mutable.ArrayBuffer
import com.intellij.psi._
import com.intellij.psi.scope._

class ScPatternImpl(node: ASTNode) extends ScalaPsiElementImpl(node) with ScPattern {
  def bindings : Seq[ScBindingPattern] = {
    val b = new ArrayBuffer[ScBindingPattern]
    _bindings(this, b)
    b
  }

  private def _bindings(p : ScPattern, b : ArrayBuffer[ScBindingPattern]) : Unit = {
    p match {
      case binding: ScBindingPattern => b += binding
      case _ =>
    }

    for (sub <- p.subpatterns) {
      _bindings(sub, b)
    }
  }

  def subpatterns : Seq[ScPattern] = {
    if (!this.isInstanceOf[ScTuplePattern])
      findChildrenByClass(classOf[ScPattern])
    else
      findChildByClass(classOf[ScPatterns]).patterns
  }

  def expectedType :Option[ScType] = getParent match {
    case list : ScPatternList => list.getParent match {
      case _var : ScVariable => Some(_var.getType)
      case _val : ScValue => Some(_val.getType)
    }
    case argList : ScPatternArgumentList => {
      argList.getParent match {
        case constr : ScConstructorPattern => constr.bindParamTypes match {
          case Some(ts) =>
            for ((p, t) <- constr.args.patterns.elements zip ts.elements) {
              if (p == this) return Some(t)
            }
            None
          case _ => None
        }
      }
    }
    case clause : ScCaseClause => clause.getParent/*clauses*/.getParent match {
      case matchStat : ScMatchStmt => matchStat.expr match {
        case Some(e) => Some(e.getType)
        case _ => None
      }
      case _ : ScCatchBlock => {
        val thr = JavaPsiFacade.getInstance(getProject).findClass("java.lang.Throwable")
        if (thr != null) Some(new ScDesignatorType(thr)) else None 
      }
    }
    case _ => None //todo
  }
}
{'fraction_non_alphanumeric': 0.10903873744619799, 'fraction_numerical': 0.0007173601147776184, 'mean_word_length': 2.834097158570119, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 32, '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': '1378341', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1324, 'n_words': 275}