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

import java.io.File
import java.util
import com.intellij.openapi.externalSystem.model.DataNode
import com.intellij.openapi.project.Project
import com.intellij.openapi.externalSystem.service.project.{ProjectStructureHelper, PlatformFacade}
import com.intellij.openapi.projectRoots.{Sdk, ProjectJdkTable, JavaSdk}
import com.intellij.openapi.roots.{LanguageLevelProjectExtension, ProjectRootManager}
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil._
import collection.JavaConverters._
import org.jetbrains.plugins.scala.components.HighlightingAdvisor
import com.intellij.compiler.impl.javaCompiler.javac.JavacConfiguration
import com.intellij.pom.java.LanguageLevel
import SbtProjectDataService._
import com.intellij.openapi.roots.impl.{LanguageLevelProjectExtensionImpl, DirectoryIndex, JavaLanguageLevelPusher}
import org.jdom.Element

/**
 * @author <NAME>
 */
class SbtProjectDataService(platformFacade: PlatformFacade, helper: ProjectStructureHelper)
  extends AbstractDataService[ScalaProjectData, Project](ScalaProjectData.Key) {

  def doImportData(toImport: util.Collection[DataNode[ScalaProjectData]], project: Project) {
    toImport.asScala.foreach { node =>
      val data = node.getData

      val projectJdk = findJdkBy(data.javaHome).orElse(allJdks.headOption)

      projectJdk.foreach(ProjectRootManager.getInstance(project).setProjectSdk)

      val javacOptions = data.javacOptions

      updateJavaCompilerOptionsIn(project, javacOptions)

      val javaLanguageLevel = javaLanguageLevelFrom(javacOptions)
              .orElse(projectJdk.flatMap(defaultJavaLanguageLevelIn))

      javaLanguageLevel.foreach(upgradeJavaLanguageLevelIn(project, _))
    }

    configureHighlightingIn(project)
  }
<commit_msg>SBT: don't change existing project SDK on project refresh (cherry picked from commit 04d3379)<commit_after>package org.jetbrains.sbt
package project.data

import java.io.File
import java.util
import com.intellij.openapi.externalSystem.model.DataNode
import com.intellij.openapi.project.Project
import com.intellij.openapi.externalSystem.service.project.{ProjectStructureHelper, PlatformFacade}
import com.intellij.openapi.projectRoots.{Sdk, ProjectJdkTable, JavaSdk}
import com.intellij.openapi.roots.{LanguageLevelProjectExtension, ProjectRootManager}
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil._
import collection.JavaConverters._
import org.jetbrains.plugins.scala.components.HighlightingAdvisor
import com.intellij.compiler.impl.javaCompiler.javac.JavacConfiguration
import com.intellij.pom.java.LanguageLevel
import SbtProjectDataService._
import com.intellij.openapi.roots.impl.{LanguageLevelProjectExtensionImpl, DirectoryIndex, JavaLanguageLevelPusher}
import org.jdom.Element

/**
 * @author <NAME>
 */
class SbtProjectDataService(platformFacade: PlatformFacade, helper: ProjectStructureHelper)
  extends AbstractDataService[ScalaProjectData, Project](ScalaProjectData.Key) {

  def doImportData(toImport: util.Collection[DataNode[ScalaProjectData]], project: Project) {
    toImport.asScala.foreach { node =>
      val data = node.getData

      val existingJdk = Option(ProjectRootManager.getInstance(project).getProjectSdk)

      val projectJdk = existingJdk.orElse(findJdkBy(data.javaHome)).orElse(allJdks.headOption)

      projectJdk.foreach(ProjectRootManager.getInstance(project).setProjectSdk)

      val javacOptions = data.javacOptions

      updateJavaCompilerOptionsIn(project, javacOptions)

      val javaLanguageLevel = javaLanguageLevelFrom(javacOptions)
              .orElse(projectJdk.flatMap(defaultJavaLanguageLevelIn))

      javaLanguageLevel.foreach(upgradeJavaLanguageLevelIn(project, _))
    }

    configureHighlightingIn(project)
  }

{'fraction_non_alphanumeric': 0.08497246262785209, 'fraction_numerical': 0.0015735641227380016, 'mean_word_length': 6.169172932330827, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3318810', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1102, 'n_words': 166}