11package ch .epfl .scala .debugadapter .internal .stepfilter
22
3- import tastyquery . Contexts . Context
3+ import ch . epfl . scala . debugadapter . internal . jdi
44import tastyquery .Contexts
5- import tastyquery .jdk . ClasspathLoaders
6- import tastyquery .jdk . ClasspathLoaders . FileKind
5+ import tastyquery .Contexts . Context
6+ import tastyquery .Flags
77import tastyquery .Names .*
8+ import tastyquery .Signatures .*
89import tastyquery .Symbols .*
9- import java .util .function .Consumer
10+ import tastyquery .Types .*
11+ import tastyquery .jdk .ClasspathLoaders
12+ import tastyquery .jdk .ClasspathLoaders .FileKind
13+
1014import java .nio .file .Path
11- import ch . epfl . scala . debugadapter . internal . jdi
12- import tastyquery . Flags
13- import scala .util .matching . Regex
15+ import java . util . function . Consumer
16+ import scala . util . Failure
17+ import scala .util .Success
1418import scala .util .Try
15- import tastyquery .Types .*
16- import tastyquery .Signatures .*
19+ import scala .util .matching .Regex
1720
1821class ScalaStepFilterBridge (
1922 classpaths : Array [Path ],
@@ -25,36 +28,40 @@ class ScalaStepFilterBridge(
2528
2629 private def warn (msg : String ): Unit = warnLogger.accept(msg)
2730
28- private def throwOrWarn (msg : String ): Unit =
29- if (testMode) throw new Exception (msg)
30- else warn(msg)
31+ private def throwOrWarn (exception : Throwable ): Unit =
32+ if (testMode) throw exception
33+ else exception.getMessage
3134
3235 def skipMethod (obj : Any ): Boolean =
33- findSymbol(obj).forall(skip)
36+ findSymbolImpl(obj) match
37+ case Failure (exception) => throwOrWarn(exception); false
38+ case Success (Some (symbol)) => skip(symbol)
39+ case Success (None ) => true
3440
3541 private [stepfilter] def findSymbol (obj : Any ): Option [TermSymbol ] =
42+ findSymbolImpl(obj).get
43+
44+ private def findSymbolImpl (obj : Any ): Try [Option [TermSymbol ]] =
3645 val method = jdi.Method (obj)
37- val isExtensionMethod = method.name.endsWith(" $extension" )
3846 val fqcn = method.declaringType.name
39- findDeclaringType(fqcn, isExtensionMethod) match
47+ findDeclaringType(fqcn, method. isExtensionMethod) match
4048 case None =>
41- throwOrWarn(s " Cannot find Scala symbol of $fqcn" )
42- None
49+ Failure (Exception (s " Cannot find Scala symbol of $fqcn" ))
4350 case Some (declaringType) =>
4451 val matchingSymbols =
4552 declaringType.declarations
4653 .collect { case sym : TermSymbol if sym.isTerm => sym }
47- .filter(matchSymbol(method, _, isExtensionMethod ))
54+ .filter(matchSymbol(method, _))
4855
4956 if matchingSymbols.size > 1 then
5057 val builder = new java.lang.StringBuilder
5158 builder.append(
5259 s " Found ${matchingSymbols.size} matching symbols for $method: "
5360 )
5461 matchingSymbols.foreach(sym => builder.append(s " \n $sym" ))
55- throwOrWarn( builder.toString)
62+ Failure ( Exception ( builder.toString) )
5663
57- matchingSymbols.headOption
64+ Success ( matchingSymbols.headOption)
5865
5966 private [stepfilter] def extractScalaTerms (
6067 fqcn : String ,
@@ -94,34 +101,25 @@ class ScalaStepFilterBridge(
94101 case _ => None
95102 }
96103
97- private def matchSymbol (method : jdi.Method , symbol : TermSymbol , isExtensionMethod : Boolean ): Boolean =
98- matchTargetName(method, symbol, isExtensionMethod) &&
99- matchSignature(method, symbol, isExtensionMethod)
104+ private def matchSymbol (method : jdi.Method , symbol : TermSymbol ): Boolean =
105+ matchTargetName(method, symbol) && matchSignature(method, symbol)
100106
101- def matchTargetName (
102- method : jdi.Method ,
103- symbol : TermSymbol ,
104- isExtensionMethod : Boolean
105- ): Boolean =
107+ def matchTargetName (method : jdi.Method , symbol : TermSymbol ): Boolean =
106108 val javaPrefix = method.declaringType.name.replace('.' , '$' ) + " $$"
107109 // if an inner accesses a private method, the backend makes the method public
108110 // and prefixes its name with the full class name.
109111 // Example: method foo in class example.Inner becomes example$Inner$$foo
110112 val expectedName = method.name.stripPrefix(javaPrefix)
111113 val encodedScalaName = NameTransformer .encode(symbol.targetName.toString)
112- if isExtensionMethod then encodedScalaName == expectedName.stripSuffix(" $extension" )
114+ if method. isExtensionMethod then encodedScalaName == expectedName.stripSuffix(" $extension" )
113115 else encodedScalaName == expectedName
114116
115- def matchSignature (
116- method : jdi.Method ,
117- symbol : TermSymbol ,
118- isExtensionMethod : Boolean
119- ): Boolean =
117+ def matchSignature (method : jdi.Method , symbol : TermSymbol ): Boolean =
120118 try {
121119 symbol.signedName match
122120 case SignedName (_, sig, _) =>
123121 val javaArgs = method.arguments.headOption.map(_.name) match
124- case Some (" $this" ) if isExtensionMethod => method.arguments.tail
122+ case Some (" $this" ) if method. isExtensionMethod => method.arguments.tail
125123 case _ => method.arguments
126124 matchArguments(sig.paramsSig, javaArgs) &&
127125 method.returnType.forall(matchType(sig.resSig, _))
0 commit comments