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

import com.intellij.codeInsight.PsiEquivalenceUtil
import com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator
import com.intellij.debugger.impl.{DebuggerManagerAdapter, DebuggerSession}
import com.intellij.debugger.{DebuggerManagerEx, SourcePosition}
import com.intellij.openapi.components.AbstractProjectComponent
import com.intellij.openapi.project.Project
import com.intellij.psi.{PsiElement, PsiFile}

import scala.collection.mutable

/**
 * Nikolay.Tropin
 * 2014-06-03
 */
class ScalaEvaluatorCache(project: Project) extends AbstractProjectComponent(project) {

  private val cachedEvaluators = mutable.HashMap[(PsiFile, Int), mutable.HashMap[PsiElement, ExpressionEvaluator]]()
  private val cachedStamp = mutable.HashMap[PsiFile, Long]()

  override def projectOpened() = {
    DebuggerManagerEx.getInstanceEx(project).addDebuggerManagerListener(
      new DebuggerManagerAdapter {
        override def sessionDetached(session: DebuggerSession) = clear()
      }
    )
  }

  def clear() {
    cachedEvaluators.values.foreach(_.clear())
    cachedEvaluators.clear()
  }

  def get(position: SourcePosition, element: PsiElement): Option[ExpressionEvaluator] = {
    val file = position.getFile
    val offset = position.getOffset
    if (!cachedStamp.get(file).contains(file.getModificationStamp)) {
      cachedStamp(file) = file.getModificationStamp
      cachedEvaluators.filterKeys(_._1 == file).foreach {
        case (pos, map) =>
          map.clear()
          cachedEvaluators.remove(pos)
      }
      None
    } else {
      cachedEvaluators.get((file, offset)) match {<commit_msg>don't store PsiFiles in ScalaEvaluatorCache after debugger session ends<commit_after>package org.jetbrains.plugins.scala
package debugger.evaluation

import com.intellij.codeInsight.PsiEquivalenceUtil
import com.intellij.debugger.engine.evaluation.expression.ExpressionEvaluator
import com.intellij.debugger.impl.{DebuggerManagerAdapter, DebuggerSession}
import com.intellij.debugger.{DebuggerManagerEx, SourcePosition}
import com.intellij.openapi.components.AbstractProjectComponent
import com.intellij.openapi.project.Project
import com.intellij.psi.{PsiElement, PsiFile}

import scala.collection.mutable

/**
 * Nikolay.Tropin
 * 2014-06-03
 */
class ScalaEvaluatorCache(project: Project) extends AbstractProjectComponent(project) {

  private val cachedEvaluators = mutable.HashMap[(PsiFile, Int), mutable.HashMap[PsiElement, ExpressionEvaluator]]()
  private val cachedStamp = mutable.HashMap[PsiFile, Long]()

  override def projectOpened() = {
    DebuggerManagerEx.getInstanceEx(project).addDebuggerManagerListener(
      new DebuggerManagerAdapter {
        override def sessionDetached(session: DebuggerSession) = clear()
      }
    )
  }

  def clear() {
    cachedEvaluators.values.foreach(_.clear())
    cachedEvaluators.clear()
    cachedStamp.clear()
  }

  def get(position: SourcePosition, element: PsiElement): Option[ExpressionEvaluator] = {
    val file = position.getFile
    val offset = position.getOffset
    if (!cachedStamp.get(file).contains(file.getModificationStamp)) {
      cachedStamp(file) = file.getModificationStamp
      cachedEvaluators.filterKeys(_._1 == file).foreach {
        case (pos, map) =>
          map.clear()
          cachedEvaluators.remove(pos)
      }
      None
    } else {
      cachedEvaluators.get((file, offset)) match {
{'fraction_non_alphanumeric': 0.10063254744105808, 'fraction_numerical': 0.005175388154111558, 'mean_word_length': 4.548644338118022, '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': '19811', 'n_tokens_mistral': 1051, 'n_tokens_neox': 1039, 'n_words': 179}