Skip to content

Commit

Permalink
Evaluation with frames of local variables check source file name
Browse files Browse the repository at this point in the history
#SCL-7103 fixed
  • Loading branch information
niktrop committed Jun 4, 2014
1 parent 1110d96 commit 3fc4d97
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
Expand Up @@ -1302,10 +1302,11 @@ object ScalaEvaluatorBuilder extends EvaluatorBuilder {
resolve: PsiElement,
ref: ScReferenceExpression, replaceWithImplicit: String => ScExpression) {
val isLocalValue = isLocalV(resolve)
val fileName = resolve.getContainingFile.name

def evaluateFromParameter(fun: PsiElement, resolve: PsiElement): Evaluator = {
val name = NameTransformer.encode(resolve.asInstanceOf[PsiNamedElement].name)
val evaluator = new ScalaLocalVariableEvaluator(name)
val evaluator = new ScalaLocalVariableEvaluator(name, fileName)
fun match {
case funDef: ScFunctionDefinition =>
def paramIndex(fun: ScFunctionDefinition, context: PsiElement, elem: PsiElement): Int = {
Expand All @@ -1322,7 +1323,6 @@ object ScalaEvaluatorBuilder extends EvaluatorBuilder {
evaluator.setMethodName("apply")
case _ => throw EvaluateExceptionUtil.createEvaluateException("Evaluation from parameter not from function definition or function expression")
}
evaluator.setSourceName(fun.getContainingFile.getName)
myResult = evaluator
myResult
}
Expand Down Expand Up @@ -1357,18 +1357,17 @@ object ScalaEvaluatorBuilder extends EvaluatorBuilder {
if (expr.isEmpty) throw EvaluateExceptionUtil.createEvaluateException("Cannot find expression of match statement")
expr.get.accept(this)
evaluateSubpatternFromPattern(myResult, pattern.get, namedElement.asInstanceOf[ScPattern])
myResult = new ScalaDuplexEvaluator(new ScalaLocalVariableEvaluator(name), myResult)
myResult = new ScalaDuplexEvaluator(new ScalaLocalVariableEvaluator(name, fileName), myResult)
case block: ScBlockExpr => //it is anonymous function
val argEvaluator = new ScalaLocalVariableEvaluator("")
val argEvaluator = new ScalaLocalVariableEvaluator("", fileName)
argEvaluator.setMethodName("apply")
argEvaluator.setSourceName(block.getContainingFile.getName)
argEvaluator.setParameterIndex(0)
val fromPatternEvaluator = evaluateSubpatternFromPattern(argEvaluator, pattern.get, namedElement.asInstanceOf[ScPattern])
myResult = new ScalaDuplexEvaluator(new ScalaLocalVariableEvaluator(name), fromPatternEvaluator)
case _ => myResult = new ScalaLocalVariableEvaluator(name)
myResult = new ScalaDuplexEvaluator(new ScalaLocalVariableEvaluator(name, fileName), fromPatternEvaluator)
case _ => myResult = new ScalaLocalVariableEvaluator(name, fileName)
}
} else throw EvaluateExceptionUtil.createEvaluateException("Invalid case clause")
case _ => myResult = new ScalaLocalVariableEvaluator(name)
case _ => myResult = new ScalaLocalVariableEvaluator(name, fileName)
}
if (isObject) {
myResult = new ScalaFieldEvaluator(myResult, ref => true, "elem") //get from VolatileObjectReference
Expand Down Expand Up @@ -1562,7 +1561,7 @@ object ScalaEvaluatorBuilder extends EvaluatorBuilder {
}
myResult = new ScalaFieldEvaluator(myResult, ref => true, name)
case None =>
myResult = new ScalaLocalVariableEvaluator(name)
myResult = new ScalaLocalVariableEvaluator(name, fileName)
}
}
}
Expand Down
Expand Up @@ -15,13 +15,14 @@ import org.jetbrains.plugins.scala.debugger.evaluation.util.DebuggerUtil
* Date: 12.10.11
*/

class ScalaLocalVariableEvaluator(_name: String) extends Evaluator {
class ScalaLocalVariableEvaluator(name: String, sourceName: String) extends Evaluator {
import ScalaLocalVariableEvaluator.LOG
private val myName: String = DebuggerUtil.withoutBackticks(name)
private val mySourceName: String = DebuggerUtil.withoutBackticks(sourceName)
private var myContext: EvaluationContextImpl = null
private var myEvaluatedVariable: LocalVariableProxyImpl = null
private var myParameterIndex: Int = -1
private var myMethodName: String = null
private var mySourceName: String = null

def setParameterIndex(parameterIndex: Int) {
myParameterIndex = parameterIndex
Expand All @@ -31,11 +32,7 @@ class ScalaLocalVariableEvaluator(_name: String) extends Evaluator {
myMethodName = name
}

def setSourceName(path: String) {
mySourceName = path
}

private val name: String = DebuggerUtil.withoutBackticks(_name)
private def sourceName(frameProxy: StackFrameProxyImpl) = frameProxy.location().sourceName()

def evaluate(context: EvaluationContextImpl): AnyRef = {
var frameProxy: StackFrameProxyImpl = context.getFrameProxy
Expand All @@ -52,16 +49,16 @@ class ScalaLocalVariableEvaluator(_name: String) extends Evaluator {
}
Some(value)
}
var local: LocalVariableProxyImpl = frameProxy.visibleVariableByName(name)
var local: LocalVariableProxyImpl = frameProxy.visibleVariableByName(myName)
if (local != null) return saveContextAndGetValue(frameProxy, local)
for (i <- 1 to 2) {
local = frameProxy.visibleVariableByName(name + "$" + i)
local = frameProxy.visibleVariableByName(myName + "$" + i)
if (local != null) return saveContextAndGetValue(frameProxy, local)
}
val locals = frameProxy.visibleVariables()
import scala.collection.JavaConversions._
for (local <- locals) {
if (local.name().startsWith(name + "$")) return saveContextAndGetValue(frameProxy, local)
if (local.name().startsWith(myName + "$")) return saveContextAndGetValue(frameProxy, local)
}
None
}
Expand All @@ -71,12 +68,12 @@ class ScalaLocalVariableEvaluator(_name: String) extends Evaluator {
while (frameIndex < lastIndex) {
frameProxy = threadProxy.frame(frameIndex)
evaluate match {
case Some(x) => return x
case None => frameIndex += 1
case Some(x) if sourceName(frameProxy) == mySourceName => return x
case _ => frameIndex += 1
}
}
throw EvaluateExceptionUtil.
createEvaluateException(DebuggerBundle.message("evaluation.error.local.variable.missing", name))
createEvaluateException(DebuggerBundle.message("evaluation.error.local.variable.missing", myName))
}

def parameterWithIndex(index: Int, frameProxy: StackFrameProxyImpl): Option[AnyRef] = {
Expand All @@ -89,7 +86,7 @@ class ScalaLocalVariableEvaluator(_name: String) extends Evaluator {
if (frameProxy == null || index < 0) None
else {
val frameMethodName = frameProxy.location().method().name()
val frameSourceName = frameProxy.location().sourceName()
val frameSourceName = sourceName(frameProxy)
if ((myMethodName == null && mySourceName == null) || (frameMethodName.startsWith(myMethodName) && mySourceName == frameSourceName)) {
try {
val values = frameProxy.getArgumentValues
Expand All @@ -106,7 +103,7 @@ class ScalaLocalVariableEvaluator(_name: String) extends Evaluator {

try {
evaluate.getOrElse(
throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.local.variable.missing", name)))
throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.local.variable.missing", myName)))
}
catch {
case e: EvaluateException =>
Expand Down

0 comments on commit 3fc4d97

Please sign in to comment.