<commit_before>package enumeratum

import scala.reflect.macros.Context
import scala.util.control.NonFatal

// TODO switch to blackbox.Context when dropping support for 2.10.x

object EnumMacros {

  def findValuesImpl[A: c.WeakTypeTag](c: Context): c.Expr[IndexedSeq[A]] = {
    import c.universe._
    val resultType = implicitly[c.WeakTypeTag[A]].tpe
    val typeSymbol = weakTypeOf[A].typeSymbol
    validateType(c)(typeSymbol)
    val subclassSymbols = enclosedSubClasses(c)(typeSymbol)
    if (subclassSymbols.isEmpty) {
      c.Expr[IndexedSeq[A]](reify(IndexedSeq.empty[A]).tree)
    } else {
      c.Expr[IndexedSeq[A]](
        Apply(
          Select(reify(IndexedSeq).tree, newTermName("apply")),
          subclassSymbols.map(Ident(_)).toList
        )
      )
    }
  }

  private[this] def validateType(c: Context)(typeSymbol: c.universe.Symbol): Unit = {
    if (!typeSymbol.asClass.isSealed)
      c.abort(
        c.enclosingPosition,
        "You can only use findValues on sealed traits or classes"
      )
  }

  private[this] def enclosedSubClasses(c: Context)(typeSymbol: c.universe.Symbol): Seq[c.universe.Symbol] = {
    import c.universe._
    val enclosingBodySubclasses: List[Symbol] = try {
      /*
        When moving beyond 2.11, we should use this instead, because enclosingClass will be deprecated.
<commit_msg>Try adding explicit return type<commit_after>package enumeratum

import scala.reflect.macros.Context
import scala.util.control.NonFatal

// TODO switch to blackbox.Context when dropping support for 2.10.x

object EnumMacros {

  def findValuesImpl[A: c.WeakTypeTag](c: Context): c.Expr[IndexedSeq[A]] = {
    import c.universe._
    val resultType = implicitly[c.WeakTypeTag[A]].tpe
    val typeSymbol = weakTypeOf[A].typeSymbol
    validateType(c)(typeSymbol)
    val subclassSymbols = enclosedSubClasses(c)(typeSymbol)
    if (subclassSymbols.isEmpty) {
      c.Expr[IndexedSeq[A]](reify(IndexedSeq.empty[A]).tree)
    } else {
      c.Expr[IndexedSeq[A]](
        Typed(
          Apply(
            Select(reify(IndexedSeq).tree, newTermName("apply")),
            subclassSymbols.map(Ident(_)).toList
          ),
          AppliedTypeTree(
            Select(Select(Ident(newTermName("scala")), newTermName("collection")), newTypeName("IndexedSeq")),
            List(TypeTree(resultType))
          )
        )
      )
    }
  }

  private[this] def validateType(c: Context)(typeSymbol: c.universe.Symbol): Unit = {
    if (!typeSymbol.asClass.isSealed)
      c.abort(
        c.enclosingPosition,
        "You can only use findValues on sealed traits or classes"
      )
  }

  private[this] def enclosedSubClasses(c: Context)(typeSymbol: c.universe.Symbol): Seq[c.universe.Symbol] = {
    import c.universe._
    val enclosingBodySubclasses: List[Symbol] = try {
      /*
        When moving beyond 2.11, we should use this instead, because enclosingClass will be deprecated.

{'fraction_non_alphanumeric': 0.11608057357459883, 'fraction_numerical': 0.004096961420279959, 'mean_word_length': 3.19170243204578, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6009', 'n_tokens_mistral': 959, 'n_tokens_neox': 920, 'n_words': 188}