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

import com.intellij.psi.PsiElement
import com.intellij.psi.tree.IElementType
import com.intellij.psi.tree.TokenSet

import com.intellij.lang.ASTNode
import com.intellij.extapi.psi.ASTWrapperPsiElement
import com.intellij.openapi.util.Key
import org.jetbrains.annotations.Nullable

import java.util.List;

trait ScalaPsiElement extends PsiElement {
  def childSatisfyPredicateForPsiElement(predicate: PsiElement => Boolean): PsiElement = {
    childSatisfyPredicateForPsiElement(predicate, getFirstChild, (e: PsiElement) => e.getNextSibling)
  }

  def childSatisfyPredicateForPsiElement(predicate: PsiElement => Boolean, startsWith: PsiElement): PsiElement = {
    childSatisfyPredicateForPsiElement(predicate, startsWith, (e: PsiElement) => e.getNextSibling)
  }

  def childSatisfyPredicateForPsiElement(predicate: PsiElement => Boolean, startsWith: PsiElement, direction: PsiElement => PsiElement): PsiElement = {
    def inner(e: PsiElement): PsiElement = if (e == null || predicate(e)) e else inner(direction(e))

    if (startsWith != null) inner(startsWith) else inner(getFirstChild)
  }

  def childSatisfyPredicateForElementType(predicate: IElementType => Boolean, startsWith: PsiElement): PsiElement = {
    childSatisfyPredicateForElementType(predicate, startsWith, (e: PsiElement) => e.getNextSibling)
  }

  def childSatisfyPredicateForElementType(predicate: IElementType => Boolean, startsWith: PsiElement, direction: PsiElement => PsiElement): PsiElement = {
    def inner(e: PsiElement): PsiElement = if (e == null || predicate(e.getNode.getElementType)) e else inner(direction(e))

    if (startsWith != null) inner(startsWith) else inner(getFirstChild)
  }

  def childSatisfyPredicateForElementType(predicate: IElementType => Boolean): PsiElement = {
    childSatisfyPredicateForElementType(predicate, getFirstChild, (e: PsiElement) => e.getNextSibling)
  }

  def childrenOfType[T >: Null <: PsiElement](tokSet: TokenSet): Iterable[T] = new Iterable[T] () {
    def elements = new Iterator[T] () {
      private def findChild(child: ASTNode): ASTNode = child match {
        case null => null
        case _ => if (tokSet.contains(child.getElementType())) child else findChild(child.getTreeNext)
      }

      val first = getFirstChild
      var n: ASTNode = if (first == null) null else findChild(first.getNode)

      def hasNext = n != null

      def next: T =  if (n == null) null else {
        val res = n
        n = findChild(n.getTreeNext)
        res.getPsi().asInstanceOf[T]
      }
    }
  }



  def childrenSatisfyPredicateForPsiElement[T >: Null <: ScalaPsiElementImpl](predicate: PsiElement => Boolean) = new Iterable[T] () {
    def elements = new Iterator[T] () {
      private def findChild(child: ASTNode): ASTNode = child match {
        case null => null
        case _ => if (predicate(child.getPsi)) child else findChild(child.getTreeNext)
      }

      val first = getFirstChild
      var n: ASTNode = if (first == null) null else findChild(first.getNode)

      def hasNext = n != null

      def next: T =  if (n == null) null else {
        val res = n<commit_msg>Rejected commit: Default<commit_after>package org.jetbrains.plugins.scala.lang.psi

import com.intellij.psi.PsiElement
import com.intellij.psi.tree.IElementType
import com.intellij.psi.tree.TokenSet

import com.intellij.lang.ASTNode
import com.intellij.extapi.psi.ASTWrapperPsiElement
import com.intellij.openapi.util.Key
import org.jetbrains.annotations.Nullable

import java.util.List;

trait ScalaPsiElement extends PsiElement {
  def childSatisfyPredicateForPsiElement(predicate: PsiElement => Boolean): PsiElement = {
    childSatisfyPredicateForPsiElement(predicate, getFirstChild, (e: PsiElement) => e.getNextSibling)
  }

  def childSatisfyPredicateForPsiElement(predicate: PsiElement => Boolean, startsWith: PsiElement): PsiElement = {
    childSatisfyPredicateForPsiElement(predicate, startsWith, (e: PsiElement) => e.getNextSibling)
  }

  def childSatisfyPredicateForPsiElement(predicate: PsiElement => Boolean, startsWith: PsiElement, direction: PsiElement => PsiElement): PsiElement = {
    def inner(e: PsiElement): PsiElement = if (e == null || predicate(e)) e else inner(direction(e))

    if (startsWith != null) inner(startsWith) else inner(getFirstChild)
  }

  def childSatisfyPredicateForElementType(predicate: IElementType => Boolean, startsWith: PsiElement): PsiElement = {
    childSatisfyPredicateForElementType(predicate, startsWith, (e: PsiElement) => e.getNextSibling)
  }

  def childSatisfyPredicateForElementType(predicate: IElementType => Boolean, startsWith: PsiElement, direction: PsiElement => PsiElement): PsiElement = {
    def inner(e: PsiElement): PsiElement = if (e == null || predicate(e.getNode.getElementType)) e else inner(direction(e))

    if (startsWith != null) inner(startsWith) else inner(getFirstChild)
  }

  def childSatisfyPredicateForElementType(predicate: IElementType => Boolean): PsiElement = {
    childSatisfyPredicateForElementType(predicate, getFirstChild, (e: PsiElement) => e.getNextSibling)
  }

  def childrenOfType[T >: Null <: PsiElement](tokSet: TokenSet): Iterable[T] = new Iterable[T] () {
    def elements = new Iterator[T] () {
      private def findChild(child: ASTNode): ASTNode = child match {
        case null => null
        case _ => if (tokSet.contains(child.getElementType())) child else findChild(child.getTreeNext)
      }

      val first = getFirstChild
      var n: ASTNode = if (first == null) null else findChild(first.getNode)

      def hasNext = n != null

      def next: T =  if (n == null) null else {
        val res = n
        n = findChild(n.getTreeNext)
        res.getPsi().asInstanceOf[T]
      }
    }
  }

  // TODO Implement it!
  def allChildrenOfType[T >: Null <: PsiElement](tokSet: TokenSet): Iterable[T] = new Iterable[T] () {
    def elements = new Iterator[T] () {

      val q = new LinkedList[PsiElement]

      private def findChild(child: ASTNode): ASTNode = child match {
        case null => null
        case _ => if (tokSet.contains(child.getElementType())) {
          child
        } else {
          findChild(child.getTreeNext)
        }
      }

      val first = getFirstChild
      var n: ASTNode =
        if (first == null) null
        else {
          findChild(first.getNode)
        }

      def hasNext = n != null

      def next: T =
        if (n == null)
          null
        else {
          val res = n
          n = findChild(n.getTreeNext)
          res.getPsi().asInstanceOf[T]
        }
    }
  }





  def childrenSatisfyPredicateForPsiElement[T >: Null <: ScalaPsiElementImpl](predicate: PsiElement => Boolean) = new Iterable[T] () {
    def elements = new Iterator[T] () {
      private def findChild(child: ASTNode): ASTNode = child match {
        case null => null
        case _ => if (predicate(child.getPsi)) child else findChild(child.getTreeNext)
      }

      val first = getFirstChild
      var n: ASTNode = if (first == null) null else findChild(first.getNode)

      def hasNext = n != null

      def next: T =  if (n == null) null else {
        val res = n
{'fraction_non_alphanumeric': 0.10793165717460758, 'fraction_numerical': 0.0, 'mean_word_length': 3.6632124352331608, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 44, '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': '14565', 'n_tokens_mistral': 2299, 'n_tokens_neox': 2257, 'n_words': 532}