<commit_before>package org.jetbrains.plugins.scala
package worksheet.runconfiguration

import com.intellij.execution.configurations._
import com.intellij.openapi.vfs.{LocalFileSystem, JarFileSystem, VirtualFile}
import com.intellij.openapi.project.Project
import com.intellij.util.PathUtil
import java.lang.String
import org.jdom.Element
import com.intellij.openapi.options.SettingsEditor
import com.intellij.openapi.module.{ModuleManager, Module}
import com.intellij.openapi.projectRoots.{JdkUtil, JavaSdkType}
import java.io._
import collection.JavaConversions._
import com.intellij.openapi.roots.{CompilerModuleExtension, OrderRootType, ModuleRootManager}
import com.intellij.execution.runners.{ProgramRunner, ExecutionEnvironment}
import com.intellij.openapi.util._
import com.intellij.execution._
import config.{CompilerLibraryData, Libraries, ScalaFacet}
import compiler.ScalacSettings
import com.intellij.execution.process.{ProcessHandler, ProcessEvent, ProcessAdapter}
import ui.ConsoleViewContentType
import com.intellij.ide.util.EditorHelper
import com.intellij.psi._
import lang.psi.api.ScalaFile
import extensions._
import com.intellij.openapi.editor.{EditorFactory, Document, Editor}
import com.intellij.psi.impl.PsiManagerEx
import java.util
import worksheet.WorksheetFoldingBuilder
import com.intellij.lang.ASTNode
import lang.psi.api.toplevel.typedef.{ScClass, ScObject}
import lang.scaladoc.psi.api.ScDocComment
import lang.psi.api.toplevel.templates.{ScExtendsBlock, ScTemplateBody}
import collection.mutable
import com.intellij.execution.impl.ConsoleViewImpl
import java.awt.event._
import java.awt.{Dimension, BorderLayout}
import com.intellij.openapi.editor.impl.EditorImpl
import com.intellij.openapi.fileEditor.{FileEditorManagerAdapter, FileEditorManagerListener, FileEditorManager}
import settings.ScalaProjectSettings
import scala.Some
import lang.psi.api.expr.{ScMethodCall, ScInfixExpr}
import com.intellij.ui.JBSplitter
import com.intellij.ui.components.JBScrollPane
import lang.psi.api.toplevel.imports.ScImportStmt
import lang.psi.api.statements.ScPatternDefinition

/**
 * @author Ksenia.Sautina
 * @since 10/15/12
 */
class WorksheetRunConfiguration(val project: Project, val configurationFactory: ConfigurationFactory, val name: String)
  extends ModuleBasedConfiguration[RunConfigurationModule](name, new RunConfigurationModule(project), configurationFactory) {
  val SCALA_HOME = "-Dscala.home="
  val CLASSPATH = "-Denv.classpath=\"%CLASSPATH%\""
  val EMACS = "-Denv.emacs=\"%EMACS%\""
  val MAIN_CLASS = "org.jetbrains.plugins.scala.worksheet.WorksheetRunner"
  val MAX_RESULTS_COUNT = 35
  val END_MESSAGE = "Output exceeds cutoff limit."

  val ContinueString = "     | "
  val PromptString   = "scala> "
  var worksheetViewer: Editor = null

  private var javaOptions = "-Djline.terminal=NONE"
  private var workingDirectory = {
    val base = getProject.getBaseDir
    if (base != null) base.getPath
    else ""
  }

  private var worksheetField = ""

  def getJavaOptions = javaOptions

  def setJavaOptions(s: String) {javaOptions = s}

  def getWorkingDirectory = workingDirectory

  def setWorkingDirectory(s: String) {workingDirectory = s}

  def getWorksheetField = worksheetField

  def setWorksheetField(s: String) {worksheetField = s}

  def apply(params: WorksheetRunConfigurationForm) {
    setJavaOptions(params.getJavaOptions)
    setWorkingDirectory(params.getWorkingDirectory)
    setWorksheetField(params.getWorksheetField)
    setModule(params.getModule)
  }

  def getState(executor: Executor, env: ExecutionEnvironment): RunProfileState = {
    val lineNumbers = new util.ArrayList[Int]()
    var currentIndex = -1
    var addedLinesCount = 0
    var isFirstLine = true

    def createWorksheetViewer(editor: Editor, virtualFile: VirtualFile): Editor = {
      val prop = if (editor.getComponent.getComponentCount > 0 && editor.getComponent.getComponent(0).isInstanceOf[JBSplitter])
        editor.getComponent.getComponent(0).asInstanceOf[JBSplitter].getProportion else 0.5f
      val dimension = editor.getComponent.getSize()
      val prefDim = new Dimension((dimension.getWidth / 2).toInt, dimension.getHeight.toInt)

      if (worksheetViewer != null) {
        EditorFactory.getInstance.releaseEditor(worksheetViewer)
      }
      worksheetViewer = createBlankEditor(project)
      val model = editor.asInstanceOf[EditorImpl].getScrollPane.getVerticalScrollBar.getModel
      worksheetViewer.asInstanceOf[EditorImpl].getScrollPane.getVerticalScrollBar.setModel(model)
      worksheetViewer.getComponent.setPreferredSize(prefDim)

      val editorComponent = editor.getContentComponent
      editorComponent.setPreferredSize(prefDim)
      val pane = new JBSplitter(false, prop)<commit_msg>#SCL-5063 Fixed.<commit_after>package org.jetbrains.plugins.scala
package worksheet.runconfiguration

import com.intellij.execution.configurations._
import com.intellij.openapi.vfs.{LocalFileSystem, JarFileSystem, VirtualFile}
import com.intellij.openapi.project.Project
import com.intellij.util.PathUtil
import java.lang.String
import org.jdom.Element
import com.intellij.openapi.options.SettingsEditor
import com.intellij.openapi.module.{ModuleManager, Module}
import com.intellij.openapi.projectRoots.{JdkUtil, JavaSdkType}
import java.io._
import collection.JavaConversions._
import com.intellij.openapi.roots.{CompilerModuleExtension, OrderRootType, ModuleRootManager}
import com.intellij.execution.runners.{ProgramRunner, ExecutionEnvironment}
import com.intellij.openapi.util._
import com.intellij.execution._
import config.{CompilerLibraryData, Libraries, ScalaFacet}
import compiler.ScalacSettings
import com.intellij.execution.process.{ProcessHandler, ProcessEvent, ProcessAdapter}
import ui.ConsoleViewContentType
import com.intellij.ide.util.EditorHelper
import com.intellij.psi._
import lang.psi.api.ScalaFile
import extensions._
import com.intellij.openapi.editor.{EditorFactory, Document, Editor}
import com.intellij.psi.impl.PsiManagerEx
import java.util
import worksheet.WorksheetFoldingBuilder
import com.intellij.lang.ASTNode
import lang.psi.api.toplevel.typedef.{ScClass, ScObject}
import lang.scaladoc.psi.api.ScDocComment
import lang.psi.api.toplevel.templates.{ScExtendsBlock, ScTemplateBody}
import collection.mutable
import com.intellij.execution.impl.ConsoleViewImpl
import java.awt.event._
import java.awt.{Dimension, BorderLayout}
import com.intellij.openapi.editor.impl.EditorImpl
import com.intellij.openapi.fileEditor.{FileEditorManagerAdapter, FileEditorManagerListener, FileEditorManager}
import settings.ScalaProjectSettings
import scala.Some
import lang.psi.api.expr.{ScMethodCall, ScInfixExpr}
import com.intellij.ui.JBSplitter
import com.intellij.ui.components.JBScrollPane
import lang.psi.api.toplevel.imports.ScImportStmt
import lang.psi.api.statements.ScPatternDefinition

/**
 * @author Ksenia.Sautina
 * @since 10/15/12
 */
class WorksheetRunConfiguration(val project: Project, val configurationFactory: ConfigurationFactory, val name: String)
  extends ModuleBasedConfiguration[RunConfigurationModule](name, new RunConfigurationModule(project), configurationFactory) {
  val SCALA_HOME = "-Dscala.home="
  val CLASSPATH = "-Denv.classpath=\"%CLASSPATH%\""
  val EMACS = "-Denv.emacs=\"%EMACS%\""
  val MAIN_CLASS = "org.jetbrains.plugins.scala.worksheet.WorksheetRunner"
  val MAX_RESULTS_COUNT = 35
  val END_MESSAGE = "Output exceeds cutoff limit."

  val ContinueString = "     | "
  val PromptString   = "scala> "
  var worksheetViewer: Editor = null

  private var javaOptions = "-Djline.terminal=NONE"
  private var workingDirectory = Option(getProject.getBaseDir) map (_.getPath) getOrElse ""

  private var worksheetField = ""

  def getJavaOptions = javaOptions

  def setJavaOptions(s: String) {javaOptions = s}

  def getWorkingDirectory = workingDirectory

  def setWorkingDirectory(s: String) {workingDirectory = s}

  def getWorksheetField = worksheetField

  def setWorksheetField(s: String) {worksheetField = s}

  def apply(params: WorksheetRunConfigurationForm) {
    setJavaOptions(params.getJavaOptions)
    setWorkingDirectory(params.getWorkingDirectory)
    setWorksheetField(params.getWorksheetField)
    setModule(params.getModule)
  }

  def getState(executor: Executor, env: ExecutionEnvironment): RunProfileState = {
    val lineNumbers = new util.ArrayList[Int]()
    var currentIndex = -1
    var addedLinesCount = 0
    var isFirstLine = true

    def createWorksheetViewer(editor: Editor, virtualFile: VirtualFile): Editor = {
      val prop = if (editor.getComponent.getComponentCount > 0 && editor.getComponent.getComponent(0).isInstanceOf[JBSplitter])
        editor.getComponent.getComponent(0).asInstanceOf[JBSplitter].getProportion else 0.5f
      val dimension = editor.getComponent.getSize()
      val prefDim = new Dimension((dimension.getWidth / 2).toInt, dimension.getHeight.toInt)

      worksheetViewer = createBlankEditor(project)
      val model = editor.asInstanceOf[EditorImpl].getScrollPane.getVerticalScrollBar.getModel
      worksheetViewer.asInstanceOf[EditorImpl].getScrollPane.getVerticalScrollBar.setModel(model)
      worksheetViewer.getComponent.setPreferredSize(prefDim)

      val editorComponent = editor.getContentComponent
      editorComponent.setPreferredSize(prefDim)
      val pane = new JBSplitter(false, prop)
{'fraction_non_alphanumeric': 0.09170398805715504, 'fraction_numerical': 0.003838771593090211, 'mean_word_length': 5.581754385964913, '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': '1895645', 'n_tokens_mistral': 2893, 'n_tokens_neox': 2785, 'n_words': 536}