<commit_before>package org.jetbrains.sbt
package project.data

import java.util
import com.intellij.openapi.externalSystem.model.{ProjectKeys, ExternalSystemException, DataNode}
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.libraries.Library
import com.intellij.openapi.externalSystem.service.project.{ProjectStructureHelper, PlatformFacade}
import org.jetbrains.plugins.scala.project._
import collection.JavaConverters._

/**
 * @author <NAME>
 */
class ScalaSdkDataService(platformFacade: PlatformFacade, helper: ProjectStructureHelper)
  extends AbstractDataService[ScalaSdkData, Library](ScalaSdkData.Key) {

  def doImportData(toImport: util.Collection[DataNode[ScalaSdkData]], project: Project) {
    toImport.asScala.foreach(doImport(_, project))
  }

  private def doImport(sdkNode: DataNode[ScalaSdkData], project: Project) {
    val sdkData = sdkNode.getData

    val compilerOptions = sdkData.compilerOptions
    project.scalaCompilerSettigns.configureFrom(compilerOptions)

    val compilerVersion = sdkData.scalaVersion

    val scalaLibrary = project.libraries
            .filter(_.getName.contains("scala-library"))
            .find(_.scalaVersion == Some(compilerVersion))
            .getOrElse(throw new ExternalSystemException("Cannot find project Scala library " +
                         compilerVersion.number + " for module " + sdkNode.getData(ProjectKeys.MODULE).getExternalName))

    if (!scalaLibrary.isScalaSdk) {
      val languageLevel = compilerVersion.toLanguageLevel.getOrElse(ScalaLanguageLevel.Default)
      val compilerClasspath = sdkData.compilerClasspath
      scalaLibrary.convertToScalaSdkWith(languageLevel, compilerClasspath)
    }
  }<commit_msg>ScalaSdkDataService: reply on Scala language level as Plan B (cherry picked from commit b7f615c)<commit_after>package org.jetbrains.sbt
package project.data

import java.util
import com.intellij.openapi.externalSystem.model.{ProjectKeys, ExternalSystemException, DataNode}
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.libraries.Library
import com.intellij.openapi.externalSystem.service.project.{ProjectStructureHelper, PlatformFacade}
import org.jetbrains.plugins.scala.project._
import collection.JavaConverters._

/**
 * @author <NAME>
 */
class ScalaSdkDataService(platformFacade: PlatformFacade, helper: ProjectStructureHelper)
  extends AbstractDataService[ScalaSdkData, Library](ScalaSdkData.Key) {

  def doImportData(toImport: util.Collection[DataNode[ScalaSdkData]], project: Project) {
    toImport.asScala.foreach(doImport(_, project))
  }

  private def doImport(sdkNode: DataNode[ScalaSdkData], project: Project) {
    val sdkData = sdkNode.getData

    val compilerOptions = sdkData.compilerOptions
    project.scalaCompilerSettigns.configureFrom(compilerOptions)

    val compilerVersion = sdkData.scalaVersion

    val scalaLibraries = project.libraries.filter(_.getName.contains("scala-library"))

    // TODO Why SBT's scala-libary module version sometimes differs from SBT's declared scalaVersion?
    val scalaLibrary = scalaLibraries
            .find(_.scalaVersion == Some(compilerVersion))
            .orElse(scalaLibraries.find(_.scalaVersion.exists(_.toLanguageLevel == compilerVersion.toLanguageLevel)))
            .getOrElse(throw new ExternalSystemException("Cannot find project Scala library " +
                         compilerVersion.number + " for module " + sdkNode.getData(ProjectKeys.MODULE).getExternalName))

    if (!scalaLibrary.isScalaSdk) {
      val languageLevel = compilerVersion.toLanguageLevel.getOrElse(ScalaLanguageLevel.Default)
      val compilerClasspath = sdkData.compilerClasspath
      scalaLibrary.convertToScalaSdkWith(languageLevel, compilerClasspath)
    }
  }
{'fraction_non_alphanumeric': 0.08886537952922507, 'fraction_numerical': 0.0010579211848717272, 'mean_word_length': 4.918622848200313, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4443848', 'n_tokens_mistral': 1111, 'n_tokens_neox': 1063, 'n_words': 191}