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

import com.intellij.debugger.impl.DebuggerUtilsEx
import com.intellij.debugger.engine.{JVMName, DebugProcessImpl}
import com.intellij.debugger.engine.evaluation.{EvaluationContextImpl, EvaluateExceptionUtil}
import com.intellij.debugger.engine.evaluation.expression.{DisableGC, Modifier, Evaluator}
import collection.mutable.ArrayBuffer
import com.sun.jdi._
import java.lang.String
import com.intellij.debugger.{SourcePosition, DebuggerBundle}
import com.intellij.openapi.application.ApplicationManager
import org.jetbrains.plugins.scala.debugger.evaluation.util.DebuggerUtil

/**
 * User: Alefas
 * Date: 12.10.11
 */
case class ScalaMethodEvaluator(objectEvaluator: Evaluator, _methodName: String, signature: JVMName,
                           argumentEvaluators: Seq[Evaluator], traitImplementation: Option[JVMName] = None,
                           methodPosition: Set[SourcePosition] = Set.empty, localMethodIndex: Int = -1) extends Evaluator {
  def getModifier: Modifier = null

  val methodName = DebuggerUtil.withoutBackticks(_methodName)
  private val localMethod = localMethodIndex > 0
  private val localMethodName = methodName + "$" + localMethodIndex

  def evaluate(context: EvaluationContextImpl): AnyRef = {
    if (!context.getDebugProcess.isAttached) return null
    val debugProcess: DebugProcessImpl = context.getDebugProcess
    val requiresSuperObject: Boolean = objectEvaluator.isInstanceOf[ScSuperEvaluator] ||
      (objectEvaluator.isInstanceOf[DisableGC] &&
        objectEvaluator.asInstanceOf[DisableGC].getDelegate.isInstanceOf[ScSuperEvaluator])
    val obj : AnyRef = DebuggerUtil.unwrapScalaRuntimeObjectRef {
      objectEvaluator.evaluate(context)
    }
    if (obj == null) {
      throw EvaluateExceptionUtil.createEvaluateException(new NullPointerException)
    }
    if (!(obj.isInstanceOf[ObjectReference] || obj.isInstanceOf[ClassType])) {
      throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.evaluating.method", methodName))
    }
    val args = argumentEvaluators.map(arg => arg.evaluate(context))
    try {
      val referenceType: ReferenceType =
      obj match {
        case o: ObjectReference =>
          val qualifierType = o.referenceType()
          debugProcess.findClass(context, qualifierType.name, qualifierType.classLoader)
        case obj: ClassType =>
          debugProcess.findClass(context, obj.name, context.getClassLoader)
        case _ =>
          null
      }
      val sign: String = if (signature != null) signature.getName(debugProcess) else null
      var mName: String = DebuggerUtilsEx.methodName(referenceType.name, methodName, sign)
      def findMethod(referenceType: ReferenceType): Method = {
        import scala.collection.JavaConversions._
        def sortedMethodCandidates: List[Method] = {
          val allMethods = referenceType.allMethods()
          allMethods.toList.collect {
            case method if !localMethod && method.name() == methodName => (method, 1)
            case method if localMethod && method.name() == localMethodName => (method, 1)
            case method if localMethod && method.name.startsWith(methodName + "$") => (method, 2)
          }.sortBy(_._2).map(_._1)
        }
        var jdiMethod: Method = null
        if (signature != null) {
          if (!localMethod) {
            jdiMethod = referenceType.asInstanceOf[ClassType].concreteMethodByName(methodName,
              signature.getName(debugProcess))
          }
          if (jdiMethod == null && localMethod) {<commit_msg>More variants for names of compiled local methods checked<commit_after>package org.jetbrains.plugins.scala.debugger.evaluation.evaluator

import com.intellij.debugger.impl.DebuggerUtilsEx
import com.intellij.debugger.engine.{JVMName, DebugProcessImpl}
import com.intellij.debugger.engine.evaluation.{EvaluationContextImpl, EvaluateExceptionUtil}
import com.intellij.debugger.engine.evaluation.expression.{DisableGC, Modifier, Evaluator}
import collection.mutable.ArrayBuffer
import com.sun.jdi._
import java.lang.String
import com.intellij.debugger.{SourcePosition, DebuggerBundle}
import com.intellij.openapi.application.ApplicationManager
import org.jetbrains.plugins.scala.debugger.evaluation.util.DebuggerUtil

/**
 * User: Alefas
 * Date: 12.10.11
 */
case class ScalaMethodEvaluator(objectEvaluator: Evaluator, _methodName: String, signature: JVMName,
                           argumentEvaluators: Seq[Evaluator], traitImplementation: Option[JVMName] = None,
                           methodPosition: Set[SourcePosition] = Set.empty, localMethodIndex: Int = -1) extends Evaluator {
  def getModifier: Modifier = null

  val methodName = DebuggerUtil.withoutBackticks(_methodName)
  private val localMethod = localMethodIndex > 0
  private val localMethodName = methodName + "$" + localMethodIndex

  def evaluate(context: EvaluationContextImpl): AnyRef = {
    if (!context.getDebugProcess.isAttached) return null
    val debugProcess: DebugProcessImpl = context.getDebugProcess
    val requiresSuperObject: Boolean = objectEvaluator.isInstanceOf[ScSuperEvaluator] ||
      (objectEvaluator.isInstanceOf[DisableGC] &&
        objectEvaluator.asInstanceOf[DisableGC].getDelegate.isInstanceOf[ScSuperEvaluator])
    val obj : AnyRef = DebuggerUtil.unwrapScalaRuntimeObjectRef {
      objectEvaluator.evaluate(context)
    }
    if (obj == null) {
      throw EvaluateExceptionUtil.createEvaluateException(new NullPointerException)
    }
    if (!(obj.isInstanceOf[ObjectReference] || obj.isInstanceOf[ClassType])) {
      throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.evaluating.method", methodName))
    }
    val args = argumentEvaluators.map(arg => arg.evaluate(context))
    try {
      val referenceType: ReferenceType =
      obj match {
        case o: ObjectReference =>
          val qualifierType = o.referenceType()
          debugProcess.findClass(context, qualifierType.name, qualifierType.classLoader)
        case obj: ClassType =>
          debugProcess.findClass(context, obj.name, context.getClassLoader)
        case _ =>
          null
      }
      val sign: String = if (signature != null) signature.getName(debugProcess) else null
      var mName: String = DebuggerUtilsEx.methodName(referenceType.name, methodName, sign)
      def findMethod(referenceType: ReferenceType): Method = {
        import scala.collection.JavaConversions._
        def sortedMethodCandidates: List[Method] = {
          val allMethods = referenceType.allMethods()
          allMethods.toList.collect {
            case method if !localMethod && method.name() == methodName => (method, 1)
            case method if localMethod && method.name() == localMethodName => (method, 1)
            case method if localMethod && method.name.startsWith(methodName + "$") => (method, 2)
            case method if localMethod && method.name.contains(methodName + "$") => (method, 3)
          }.sortBy(_._2).map(_._1)
        }
        var jdiMethod: Method = null
        if (signature != null) {
          if (!localMethod) {
            jdiMethod = referenceType.asInstanceOf[ClassType].concreteMethodByName(methodName,
              signature.getName(debugProcess))
          }
          if (jdiMethod == null && localMethod) {
{'fraction_non_alphanumeric': 0.09678725701943844, 'fraction_numerical': 0.003644708423326134, 'mean_word_length': 3.653894472361809, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, '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': '2897514', 'n_tokens_mistral': 2064, 'n_tokens_neox': 2039, 'n_words': 413}