<commit_before>package dotty.tools.dotc.transform

import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Types
import dotty.tools.dotc.transform.MegaPhase._
import java.io.{File => _}

import dotty.tools.dotc.core._
import SymDenotations._
import Contexts._
import Types._
import Symbols._
import Phases._
import dotty.tools.dotc.util.SourcePosition
import Decorators._
import StdNames.nme
import dotty.tools.io.JarArchive
import dotty.tools.backend.jvm.GenBCode

/**
 * Small phase to be run to collect main classes and store them in the context.
 * The general rule to run this phase is either:
 * - The output of compilation is JarArchive and there is no `-Xmain-class` defined
 * - The compiler is run from sbt and is forced by flags forcing `ExtractorAPI`
 *
 * The following flags affect this phase:
 *   -d path.jar
 *   -Xmain-class
 *   -Yforce-sbt-phases
 *   -Ydump-sbt-inc
 */
class CollectEntryPoints extends MiniPhase:
  def phaseName: String = "Collect entry points"

  override def isRunnable(using Context): Boolean =
    def forceRun = (ctx.settings.XmainClass.isDefault && ctx.settings.outputDir.value.isInstanceOf[JarArchive]) ||
                    ctx.settings.YdumpSbtInc.value ||
                    ctx.settings.YforceSbtPhases.value
    super.isRunnable && (ctx.sbtCallback != null || forceRun)


  override def transformTypeDef(tree: tpd.TypeDef)(using Context): tpd.Tree =
    getEntryPoint(tree).map(registerEntryPoint)
    tree

  private def getEntryPoint(tree: tpd.TypeDef)(using Context): Option[String] =
    val sym = tree.symbol
    import dotty.tools.dotc.core.NameOps.stripModuleClassSuffix
    val name = sym.fullName.stripModuleClassSuffix.toString
    Option.when(sym.isStatic && !sym.is(Flags.Trait) && ctx.platform.hasMainMethod(sym))(name)

  private def registerEntryPoint(s: String)(using Context) = {
    genBCodePhase match {
      case genBCodePhase: GenBCode =><commit_msg>Remove spare checks from CollectEntryPoints<commit_after>package dotty.tools.dotc.transform

import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Types
import dotty.tools.dotc.transform.MegaPhase._
import java.io.{File => _}

import dotty.tools.dotc.core._
import SymDenotations._
import Contexts._
import Types._
import Symbols._
import Phases._
import dotty.tools.dotc.util.SourcePosition
import Decorators._
import StdNames.nme
import dotty.tools.io.JarArchive
import dotty.tools.backend.jvm.GenBCode

/**
 * Small phase to be run to collect main classes and store them in the context.
 * The general rule to run this phase is:
 * - The output of compilation is JarArchive
 * - There is no `-Xmain-class` defined
 *
 * The following flags affect this phase:
 *   -d path.jar
 *   -Xmain-class
 */
class CollectEntryPoints extends MiniPhase:
  def phaseName: String = "Collect entry points"

  override def isRunnable(using Context): Boolean =
    def forceRun = ctx.settings.XmainClass.isDefault && ctx.settings.outputDir.value.isInstanceOf[JarArchive]
    super.isRunnable && forceRun

  override def transformTypeDef(tree: tpd.TypeDef)(using Context): tpd.Tree =
    getEntryPoint(tree).map(registerEntryPoint)
    tree

  private def getEntryPoint(tree: tpd.TypeDef)(using Context): Option[String] =
    val sym = tree.symbol
    import dotty.tools.dotc.core.NameOps.stripModuleClassSuffix
    val name = sym.fullName.stripModuleClassSuffix.toString
    Option.when(sym.isStatic && !sym.is(Flags.Trait) && ctx.platform.hasMainMethod(sym))(name)

  private def registerEntryPoint(s: String)(using Context) = {
    genBCodePhase match {
      case genBCodePhase: GenBCode =>
{'fraction_non_alphanumeric': 0.09789644012944984, 'fraction_numerical': 0.0, 'mean_word_length': 4.12292817679558, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3522084', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1143, 'n_words': 291}