<commit_before>package org.jetbrains.jps.incremental.scala

import java.io._

import com.intellij.openapi.util.Key
import com.intellij.openapi.util.io.FileUtil
import org.jetbrains.jps.ModuleChunk
import org.jetbrains.jps.builders.DirtyFilesHolder
import org.jetbrains.jps.builders.java.{JavaBuilderUtil, JavaSourceRootDescriptor}
import org.jetbrains.jps.incremental.messages.{BuildMessage, CompilerMessage}
import org.jetbrains.jps.incremental.scala.ScalaBuilder.projectSettings
import org.jetbrains.jps.incremental.scala.model.IncrementalityType
import org.jetbrains.jps.incremental._
import org.jetbrains.jps.incremental.scala.InitialScalaBuilder._
import org.jetbrains.jps.model.module.JpsModule

import _root_.scala.collection.JavaConverters._


/**
  * For tasks that should be performed once per compilation
  */
class InitialScalaBuilder extends ModuleLevelBuilder(buildCategory) {

  override def getPresentableName = "Collect modules with scala"

  override def buildStarted(context: CompileContext): Unit = {
    val scalaModules = collectAndStoreScalaModules(context)

    if (scalaModules.nonEmpty) {
      checkIncrementalTypeChange(context)
    }
  }

  override def build(context: CompileContext,
                     chunk: ModuleChunk,
                     dirtyFilesHolder: DirtyFilesHolder[JavaSourceRootDescriptor, ModuleBuildTarget],
                     outputConsumer: ModuleLevelBuilder.OutputConsumer): ModuleLevelBuilder.ExitCode =
    ModuleLevelBuilder.ExitCode.NOTHING_DONE
}

object InitialScalaBuilder {
  //should be before other scala builders
  private def buildCategory = BuilderCategory.SOURCE_INSTRUMENTER

  private val scalaModulesKey: Key[Set[JpsModule]] =
    Key.create[Set[JpsModule]]("jps.scala.modules")

  def hasScala(context: CompileContext, module: JpsModule): Boolean =
    Option(context.getUserData(scalaModulesKey)).exists(_.contains(module))

  def hasScalaModules(context: CompileContext, chunk: ModuleChunk): Boolean =
    chunk.getModules.asScala.exists(hasScala(context, _))

  def isScalaProject(context: CompileContext): Boolean =
    Option(context.getUserData(scalaModulesKey)).exists(_.nonEmpty)


  private def storeScalaModules(context: CompileContext, scalaModules: Set[JpsModule]): Unit = {<commit_msg>proper override for ModuleLevelBuilder#getCompilableFileExtensions #SCL-14597 fixed<commit_after>package org.jetbrains.jps.incremental.scala

import java.io._
import java.util

import com.intellij.openapi.util.Key
import com.intellij.openapi.util.io.FileUtil
import org.jetbrains.jps.ModuleChunk
import org.jetbrains.jps.builders.DirtyFilesHolder
import org.jetbrains.jps.builders.java.{JavaBuilderUtil, JavaSourceRootDescriptor}
import org.jetbrains.jps.incremental.messages.{BuildMessage, CompilerMessage}
import org.jetbrains.jps.incremental.scala.ScalaBuilder.projectSettings
import org.jetbrains.jps.incremental.scala.model.IncrementalityType
import org.jetbrains.jps.incremental._
import org.jetbrains.jps.incremental.scala.InitialScalaBuilder._
import org.jetbrains.jps.model.module.JpsModule

import _root_.scala.collection.JavaConverters._


/**
  * For tasks that should be performed once per compilation
  */
class InitialScalaBuilder extends ModuleLevelBuilder(buildCategory) {

  override def getPresentableName = "Collect modules with scala"

  override def buildStarted(context: CompileContext): Unit = {
    val scalaModules = collectAndStoreScalaModules(context)

    if (scalaModules.nonEmpty) {
      checkIncrementalTypeChange(context)
    }
  }

  override def build(context: CompileContext,
                     chunk: ModuleChunk,
                     dirtyFilesHolder: DirtyFilesHolder[JavaSourceRootDescriptor, ModuleBuildTarget],
                     outputConsumer: ModuleLevelBuilder.OutputConsumer): ModuleLevelBuilder.ExitCode =
    ModuleLevelBuilder.ExitCode.NOTHING_DONE

  override def getCompilableFileExtensions: util.List[String] = util.Arrays.asList("scala", "java")
}

object InitialScalaBuilder {
  //should be before other scala builders
  private def buildCategory = BuilderCategory.SOURCE_INSTRUMENTER

  private val scalaModulesKey: Key[Set[JpsModule]] =
    Key.create[Set[JpsModule]]("jps.scala.modules")

  def hasScala(context: CompileContext, module: JpsModule): Boolean =
    Option(context.getUserData(scalaModulesKey)).exists(_.contains(module))

  def hasScalaModules(context: CompileContext, chunk: ModuleChunk): Boolean =
    chunk.getModules.asScala.exists(hasScala(context, _))

  def isScalaProject(context: CompileContext): Boolean =
    Option(context.getUserData(scalaModulesKey)).exists(_.nonEmpty)


  private def storeScalaModules(context: CompileContext, scalaModules: Set[JpsModule]): Unit = {
{'fraction_non_alphanumeric': 0.0879492600422833, 'fraction_numerical': 0.0010570824524312897, 'mean_word_length': 5.266225165562914, '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': '3024711', 'n_tokens_mistral': 1441, 'n_tokens_neox': 1373, 'n_words': 247}