Skip to content

Commit

Permalink
Rename MethodInvocationFailed to RuntimeException
Browse files Browse the repository at this point in the history
  • Loading branch information
adpi2 committed Feb 7, 2024
1 parent 35557c8 commit d20c4de
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private[internal] class EvaluationProvider(
.invoke(methodName, methodSignature, wrappedArgs)
.recover {
// if invocation throws an exception, we return that exception as the result
case MethodInvocationFailed(msg, Some(exception)) => exception
case RuntimeException(msg, Some(exception)) => exception
}
.map(_.value)
}
Expand Down Expand Up @@ -180,7 +180,7 @@ private[internal] class EvaluationProvider(
} yield compiledExpression
}
// if evaluation throws an exception, we return that exception as the result
result.recover { case MethodInvocationFailed(_, Some(exception)) => exception.value }
result.recover { case RuntimeException(_, Some(exception)) => exception.value }
}

private def completeFuture[T](result: Try[T], thread: ThreadReference): CompletableFuture[T] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ class JdiArray(arrayRef: ArrayReference, thread: ThreadReference) extends JdiObj

def getValues: Seq[JdiValue] = arrayRef.getValues.asScala.toSeq.map(JdiValue(_, thread))

def getValue(i: Int): JdiValue = JdiValue(arrayRef.getValue(i), thread)
def getValue(i: Int): Safe[JdiValue] =
Safe(JdiValue(arrayRef.getValue(i), thread)).recoverWith { case e: IndexOutOfBoundsException =>
Safe.failed(RuntimeException(e.getMessage, None))
}
}

object JdiArray {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private[internal] class JdiClass(
for {
_ <- prepareMethod(ctr)
instance <- Safe(cls.newInstance(thread, ctr, args.map(_.value).asJava, ObjectReference.INVOKE_SINGLE_THREADED))
.recoverWith(wrapInvocationException(thread))
.recoverWith(wrapInvocationException)
} yield JdiObject(instance, thread)

// Load the argument types of the method to avoid ClassNotLoadedException
Expand Down Expand Up @@ -64,7 +64,7 @@ private[internal] class JdiClass(
def invokeStatic(method: Method, args: Seq[JdiValue]): Safe[JdiValue] =
Safe(cls.invokeMethod(thread, method, args.map(_.value).asJava, ObjectReference.INVOKE_SINGLE_THREADED))
.map(JdiValue(_, thread))
.recoverWith(wrapInvocationException(thread))
.recoverWith(wrapInvocationException)
}

object JdiClass {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,17 @@ private[evaluator] class JdiObject(
def classObject: JdiClass = JdiClass(reference.referenceType, thread)
def classLoader: JdiClassLoader = JdiClassLoader(reference.referenceType.classLoader, thread)

def invoke(method: Method, args: Seq[JdiValue]): Safe[JdiValue] = {
def invoke(method: Method, args: Seq[JdiValue]): Safe[JdiValue] =
Safe(reference.invokeMethod(thread, method, args.map(_.value).asJava, ObjectReference.INVOKE_SINGLE_THREADED))
.map(JdiValue(_, thread))
.recoverWith(wrapInvocationException(thread))
}
.recoverWith(wrapInvocationException)

protected def wrapInvocationException(thread: ThreadReference): PartialFunction[Throwable, Safe[Nothing]] = {
protected val wrapInvocationException: PartialFunction[Throwable, Safe[Nothing]] = {
case invocationException: InvocationException =>
for {
exception <- Safe(invocationException.exception).map(JdiObject(_, thread))
message <- exception.invoke("toString", List()).map(_.asString.stringValue).recover { case _ => "" }
} yield throw new MethodInvocationFailed(message, Some(exception))
} yield throw new RuntimeException(message, Some(exception))
}

// we use a Seq instead of a Map because the ScalaEvaluator rely on the order of the fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ class RuntimeEvaluation(frame: JdiFrame, logger: Logger) {
for {
array <- eval(tree.array)
index <- eval(tree.index).flatMap(_.unboxIfPrimitive).flatMap(_.toInt)
} yield array.asArray.getValue(index)
value <- array.asArray.getValue(index)
} yield value

private def evaluateIf(tree: If): Safe[JdiValue] =
for {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ch.epfl.scala.debugadapter.internal.evaluator

private[internal] case class MethodInvocationFailed(
private[internal] case class RuntimeException(
message: String,
remoteException: Option[JdiObject]
) extends Exception(message) {
override def toString: String = s"MethodInvocationFailed: $message"
override def toString: String = s"RuntimeException: $message"
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ object RuntimePrimitiveOps {
case GreaterOrEqual => fractional.gteq(x, y)
}
.map(clsLoader.mirrorOfAnyVal)
.recoverWith { case e: ArithmeticException => Safe.failed(MethodInvocationFailed(e.getMessage, None)) }
.recoverWith { case e: ArithmeticException => Safe.failed(RuntimeException(e.getMessage, None)) }
}

private def computeIntegral[T <: AnyVal](x: T, y: T, clsLoader: JdiClassLoader)(implicit
Expand All @@ -169,7 +169,7 @@ object RuntimePrimitiveOps {
case GreaterOrEqual => integral.gteq(x, y)
}
.map(clsLoader.mirrorOfAnyVal)
.recoverWith { case e: ArithmeticException => Safe.failed(MethodInvocationFailed(e.getMessage, None)) }
.recoverWith { case e: ArithmeticException => Safe.failed(RuntimeException(e.getMessage, None)) }
}

def evaluate(lhs: JdiValue, rhs: JdiValue, loader: JdiClassLoader) = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class ExpressionCompilerBridge {
) ++ options :+ sourceFile.toString

val command = new CompilerCommand(args, errorConsumer.accept(_))
val reporter = new StoreReporter() // cannot fix because of Scala 2.10
val reporter = new StoreReporter() // cannot fix because of Scala 2.12
val global = new ExpressionGlobal(
command.settings,
reporter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class ExpressionContext(
val expressionTermName: TermName = termName(uniqueName.toLowerCase.toString)
val expressionClassName: TypeName = typeName(uniqueName)

var expressionSymbol: TermSymbol = _
var expressionSymbol: TermSymbol = null
// all classes and def in the chain of owners of the expression from local to global
// we store them to resolve the captured variables
var classOwners: Seq[ClassSymbol] = _
var classOwners: Seq[ClassSymbol] = null
var capturingMethod: Option[TermSymbol] = None

def store(exprSym: Symbol)(using Context): Unit =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import dotty.tools.dotc.transform.MacroTransform
import dotty.tools.dotc.core.Phases.*
import dotty.tools.dotc.report
import dotty.tools.dotc.util.SrcPos
import scala.annotation.nowarn

class ExtractExpression(using exprCtx: ExpressionContext) extends MacroTransform with DenotTransformer:
override def phaseName: String = ExtractExpression.name
Expand All @@ -39,7 +40,7 @@ class ExtractExpression(using exprCtx: ExpressionContext) extends MacroTransform

override protected def newTransformer(using Context): Transformer =
new Transformer:
var expressionTree: Tree = _
var expressionTree: Tree = null
override def transform(tree: Tree)(using Context): Tree =
tree match
case PackageDef(pid, stats) =>
Expand Down

0 comments on commit d20c4de

Please sign in to comment.