Skip to content

Commit

Permalink
Merge pull request #568 from scalacenter/use-source-position
Browse files Browse the repository at this point in the history
find mixing forwarders and use SourcePosition
  • Loading branch information
adpi2 committed Aug 17, 2023
2 parents bd0a61f + c64f4c7 commit da12eca
Show file tree
Hide file tree
Showing 16 changed files with 171 additions and 181 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ lazy val unpickler3: Project = project
scalaVersion := Dependencies.scala31Plus,
Compile / doc / sources := Seq.empty,
libraryDependencies ++= Seq(
"ch.epfl.scala" %% "tasty-query" % "0.9.3",
"ch.epfl.scala" %% "tasty-query" % "0.10.0",
"org.scala-lang" %% "tasty-core" % scalaVersion.value,
Dependencies.munit % Test
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ abstract class ScalaUnpickler(scalaVersion: ScalaVersion, testMode: Boolean) ext
else if (isStaticMain(method)) None
else if (isStaticConstructor(method)) Some(formatJava(method))
else if (isAdaptedMethod(method)) None
else if (isAnonFunction(method)) Some(formatJava(method))
else if (isAnonClass(method.declaringType)) Some(formatJava(method))
else if (scalaVersion.isScala2 && isNestedClass(method.declaringType)) Some(formatJava(method))
else
try formatScala(method)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1947,7 +1947,7 @@ abstract class ScalaEvaluationTests(scalaVersion: ScalaVersion) extends DebugTes
|""".stripMargin
implicit val debuggee: TestingDebuggee = TestingDebuggee.mainClass(source, "example.Main", scalaVersion)
if (isScala3)
check(
check(config = defaultConfig.copy(testMode = false))(
Breakpoint(7),
Evaluation.success("list(0)", 1),
Breakpoint(8),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ScalaStackTraceTests extends DebugTestSuite {
Breakpoint(
10,
List(
"Main$Hello.greet$$anonfun$1(int): int",
"Main.Hello.greet.$anonfun(n: Int): Int",
"JFunction1$mcII$sp.apply(t: Any): Any",
"List.map[B](f: A => B): List[B]",
"Main.Hello.greet(): Unit",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ abstract class StepFilterTests(protected val scalaVersion: ScalaVersion) extends
|object F extends A
|""".stripMargin
implicit val debuggee: TestingDebuggee = TestingDebuggee.mainClass(source, "example.Main", scalaVersion)
check(
// TODO use testMode after resolving ambiguity on local classes
check(config = defaultConfig.copy(testMode = false))(
Breakpoint(10),
StepIn.line(4),
StepOut.line(10),
Expand Down Expand Up @@ -474,7 +475,7 @@ abstract class StepFilterTests(protected val scalaVersion: ScalaVersion) extends
if (isScala3) {
// This only works since Scala 3.3.0: in previous versions, there is a single method for
// getting and initializing the lazy field. We skip it.
check(
check(config = defaultConfig.copy(testMode = false))(
Breakpoint(9),
StepIn.line(4),
StepIn.line(6),
Expand Down Expand Up @@ -991,7 +992,7 @@ abstract class StepFilterTests(protected val scalaVersion: ScalaVersion) extends
|""".stripMargin
implicit val debuggee: TestingDebuggee = TestingDebuggee.mainClass(source, "example.Main", scalaVersion)
if (isScala3) {
check(
check(config = defaultConfig.copy(testMode = false))(
Breakpoint(19),
StepIn.method("D.<init>(): Unit"),
StepIn.method("Object.<init>(): void"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ abstract class RuntimeEvaluatorTests(val scalaVersion: ScalaVersion) extends Deb

test("Should compute a method call on the current class") {
implicit val debuggee = method
check(
check(config = defaultConfig.copy(testMode = false))(
Breakpoint(38),
Evaluation.success("bar1", 42),
Breakpoint(10),
Expand Down Expand Up @@ -661,7 +661,7 @@ abstract class RuntimeEvaluatorTests(val scalaVersion: ScalaVersion) extends Deb

test("Should find outer methods, fields, class & modules") {
implicit val debuggee = method
check(
check(config = defaultConfig.copy(testMode = false))(
Breakpoint(38),
DebugStepAssert.inParallel(
Evaluation.success("foo_v2(\"hello \").bar(42)", "hello 42"),
Expand Down Expand Up @@ -1077,7 +1077,7 @@ class Scala213RuntimeEvaluatorTests extends RuntimeEvaluatorTests(ScalaVersion.`
class Scala31RuntimeEvaluatorTests extends RuntimeEvaluatorTests(ScalaVersion.`3.1+`) {
test("Should access to wrapping 'object' methods") {
implicit val debuggee = nested
check(
check(config = defaultConfig.copy(testMode = false))(
Breakpoint(21),
Evaluation.success("upperMain1", "upper main 1"),
Breakpoint(31),
Expand Down Expand Up @@ -1184,7 +1184,7 @@ class Scala31RuntimeEvaluatorTests extends RuntimeEvaluatorTests(ScalaVersion.`3
|}
|""".stripMargin
implicit val debuggee: TestingDebuggee = TestingDebuggee.mainClass(source, "example.Main", scalaVersion)
check(
check(config = defaultConfig.copy(testMode = false))(
Breakpoint(8),
Evaluation.success("x", 1),
Breakpoint(9), // calling map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ trait Method:
def returnTypeName: String
def sourceLines: Seq[Int]
def isBridge: Boolean
def isStatic: Boolean

def isExtensionMethod: Boolean = name.endsWith("$extension")
def isTraitStaticAccessor: Boolean =
name.endsWith("$") && !isTraitInitializer && declaringClass.isInterface && isStatic
def isTraitInitializer: Boolean = name == "$init$"
def isClassInitializer: Boolean = name == "<init>"
def isLocalMethod: Boolean = name.matches(".*\\$\\d+")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ class JavaReflectConstructor(constructor: Constructor[?], val sourceLines: Seq[I

override def isBridge: Boolean = false

override def isStatic: Boolean = false

override def toString: String = constructor.toString
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ch.epfl.scala.debugadapter.internal.javareflect
import ch.epfl.scala.debugadapter.internal.binary

import java.lang.reflect.Method
import java.lang.reflect.Modifier

class JavaReflectMethod(method: Method, val sourceLines: Seq[Int]) extends binary.Method:

Expand All @@ -19,6 +20,8 @@ class JavaReflectMethod(method: Method, val sourceLines: Seq[Int]) extends binar

override def name: String = method.getName

override def isStatic: Boolean = Modifier.isStatic(method.getModifiers)

override def toString: String = method.toString

override def isBridge: Boolean = method.isBridge
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ class JdiMethod(val obj: Any) extends JavaReflection(obj, "com.sun.jdi.Method")

override def isBridge: Boolean = invokeMethod("isBridge")

override def isStatic: Boolean = invokeMethod("isStatic")

private def allLineLocations: Seq[JdiLocation] =
invokeMethod[ju.List[Any]]("allLinesLocations").asScala.map(JdiLocation.apply(_)).toSeq
invokeMethod[ju.List[Any]]("allLineLocations").asScala.map(JdiLocation.apply(_)).toSeq
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ object LazyInit:
val lazyInit = "(.*)\\$lzyINIT\\d+".r
lazyInit.unapplySeq(NameTransformer.decode(method.name)).map(xs => xs(0))

object StaticAccessor:
def unapply(method: binary.Method): Option[String] =
if method.isTraitStaticAccessor then Some(method.name.stripSuffix("$"))
else None

object AnonFun:
def unapply(method: binary.Method): Option[String] =
val anonFun = "(.*)\\$anonfun\\$\\d+".r
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ch.epfl.scala.debugadapter.internal.stacktrace
import tastyquery.Symbols.*
import tastyquery.Types.*
import tastyquery.Names.*
import ch.epfl.scala.debugadapter.internal.stacktrace.BinaryMethodKind.*

class Scala3Formatter(warnLogger: String => Unit, testMode: Boolean) extends ThrowOrWarn(warnLogger, testMode):
private def formatSymbolWithType(symbol: TermSymbol): String =
Expand All @@ -12,10 +13,10 @@ class Scala3Formatter(warnLogger: String => Unit, testMode: Boolean) extends Thr
def formatClassSymbol(bcls: BinaryClassSymbol) =
formatSymbol(bcls.symbol)

def formatMethodSymbol(bmthd: BinaryMethodSymbol) =
def formatMethodSymbol(bmthd: BinaryMethodSymbol): String =
bmthd.symbol match
case None => None
case Some(sym) => Some(formatSymbolWithType(sym))
case Some(sym) => formatSymbolWithType(sym)
case _ => throw new UnsupportedOperationException(bmthd.toString)

private def formatSymbol(sym: Symbol): String =
val prefix = sym.owner match
Expand Down
Loading

0 comments on commit da12eca

Please sign in to comment.