<commit_before>package org.jetbrains.plugins.scala
package debugger.evaluation

import com.intellij.debugger.codeinsight.RuntimeTypeEvaluator
import com.intellij.debugger.engine.ContextUtil
import com.intellij.debugger.engine.evaluation.EvaluationContextImpl
import com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator
import com.intellij.debugger.impl.DebuggerContextImpl
import com.intellij.debugger.{DebuggerBundle, DebuggerInvocationUtil, EvaluatingComputable}
import com.intellij.openapi.application.{AccessToken, ReadAction}
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Key
import com.intellij.psi._
import com.intellij.psi.search.GlobalSearchScope
import com.sun.jdi.{ClassType, Type, Value}
import org.jetbrains.annotations.Nullable
import org.jetbrains.plugins.scala.debugger.evaluation.ScalaRuntimeTypeEvaluator._
import org.jetbrains.plugins.scala.debugger.evaluation.util.DebuggerUtil
import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScModifierListOwner
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScObject
import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiManager
import org.jetbrains.plugins.scala.lang.psi.types.ScType
import org.jetbrains.plugins.scala.lang.psi.types.ScType.ExtractClass

/**
 * Nikolay.Tropin
 * 8/8/13
 */
abstract class ScalaRuntimeTypeEvaluator(@Nullable editor: Editor, expression: PsiElement, context: DebuggerContextImpl, indicator: ProgressIndicator)
        extends RuntimeTypeEvaluator(editor, expression, context, indicator) {

  override def evaluate(evaluationContext: EvaluationContextImpl): PsiClass = {
    val project: Project = evaluationContext.getProject

    val evaluator: ExpressionEvaluator = DebuggerInvocationUtil.commitAndRunReadAction(project, new EvaluatingComputable[ExpressionEvaluator] {
      def compute: ExpressionEvaluator = {
        ScalaEvaluatorBuilder.build(myElement, ContextUtil.getSourcePosition(evaluationContext))
      }
    })
    val value: Value = evaluator.evaluate(evaluationContext)
    if (value != null) {
      getCastableRuntimeType(project, value)
    } else throw EvaluationException(DebuggerBundle.message("evaluation.error.surrounded.expression.null"))
  }
}

object ScalaRuntimeTypeEvaluator {

  val KEY: Key[ScExpression => ScType] = Key.create("SCALA_RUNTIME_TYPE_EVALUATOR")

  def getCastableRuntimeType(project: Project, value: Value): PsiClass = {
    val unwrapped = DebuggerUtil.unwrapScalaRuntimeObjectRef(value)
    val jdiType: Type = unwrapped.asInstanceOf[Value].`type`
    var psiClass: PsiClass = findPsiClass(project, jdiType)<commit_msg>build evaluator for ScalaCodeFragment, not plain PsiElement, in ScalaRuntimeTypeEvaluator<commit_after>package org.jetbrains.plugins.scala
package debugger.evaluation

import com.intellij.debugger.codeinsight.RuntimeTypeEvaluator
import com.intellij.debugger.engine.ContextUtil
import com.intellij.debugger.engine.evaluation.{CodeFragmentKind, TextWithImportsImpl, EvaluationContextImpl}
import com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator
import com.intellij.debugger.impl.DebuggerContextImpl
import com.intellij.debugger.{DebuggerBundle, DebuggerInvocationUtil, EvaluatingComputable}
import com.intellij.openapi.application.{AccessToken, ReadAction}
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Key
import com.intellij.psi._
import com.intellij.psi.search.GlobalSearchScope
import com.sun.jdi.{ClassType, Type, Value}
import org.jetbrains.annotations.Nullable
import org.jetbrains.plugins.scala.debugger.evaluation.ScalaRuntimeTypeEvaluator._
import org.jetbrains.plugins.scala.debugger.evaluation.util.DebuggerUtil
import org.jetbrains.plugins.scala.lang.psi.api.expr.ScExpression
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.ScModifierListOwner
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScObject
import org.jetbrains.plugins.scala.lang.psi.impl.ScalaPsiManager
import org.jetbrains.plugins.scala.lang.psi.types.ScType
import org.jetbrains.plugins.scala.lang.psi.types.ScType.ExtractClass

/**
 * Nikolay.Tropin
 * 8/8/13
 */
abstract class ScalaRuntimeTypeEvaluator(@Nullable editor: Editor, expression: PsiElement, context: DebuggerContextImpl, indicator: ProgressIndicator)
        extends RuntimeTypeEvaluator(editor, expression, context, indicator) {

  override def evaluate(evaluationContext: EvaluationContextImpl): PsiClass = {
    val project: Project = evaluationContext.getProject

    val evaluator: ExpressionEvaluator = DebuggerInvocationUtil.commitAndRunReadAction(project, new EvaluatingComputable[ExpressionEvaluator] {
      def compute: ExpressionEvaluator = {
        val textWithImports = new TextWithImportsImpl(CodeFragmentKind.CODE_BLOCK, expression.getText)
        val codeFragment = new ScalaCodeFragmentFactory().createCodeFragment(textWithImports, expression, project)
        ScalaEvaluatorBuilder.build(codeFragment, ContextUtil.getSourcePosition(evaluationContext))
      }
    })
    val value: Value = evaluator.evaluate(evaluationContext)
    if (value != null) {
      getCastableRuntimeType(project, value)
    } else throw EvaluationException(DebuggerBundle.message("evaluation.error.surrounded.expression.null"))
  }
}

object ScalaRuntimeTypeEvaluator {

  val KEY: Key[ScExpression => ScType] = Key.create("SCALA_RUNTIME_TYPE_EVALUATOR")

  def getCastableRuntimeType(project: Project, value: Value): PsiClass = {
    val unwrapped = DebuggerUtil.unwrapScalaRuntimeObjectRef(value)
    val jdiType: Type = unwrapped.asInstanceOf[Value].`type`
    var psiClass: PsiClass = findPsiClass(project, jdiType)
{'fraction_non_alphanumeric': 0.09029649595687332, 'fraction_numerical': 0.0013477088948787063, 'mean_word_length': 6.249084249084249, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4944073', 'n_tokens_mistral': 1814, 'n_tokens_neox': 1760, 'n_words': 280}