Skip to content

Commit 77c9e75

Browse files
authored
Merge pull request #546 from adpi2/3.1.x-backport
Backports to 3.1.x
2 parents 5bd19c6 + bf96dfa commit 77c9e75

File tree

40 files changed

+656
-197
lines changed

40 files changed

+656
-197
lines changed

bin/scalafmt

42.5 MB
Binary file not shown.

build.sbt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ lazy val javaDebug = project
4949
autoScalaLibrary := false,
5050
compile / javacOptions ++= Seq("-source", "1.8", "-target", "1.8"),
5151
libraryDependencies ++= Seq(
52-
"org.apache.commons" % "commons-lang3" % "3.12.0",
52+
"org.apache.commons" % "commons-lang3" % "3.13.0",
5353
"com.google.code.gson" % "gson" % "2.10.1",
5454
"io.reactivex.rxjava2" % "rxjava" % "2.2.21",
5555
"org.reactivestreams" % "reactive-streams" % "1.0.4",
56-
"commons-io" % "commons-io" % "2.12.0",
56+
"commons-io" % "commons-io" % "2.13.0",
5757
"junit" % "junit" % "4.13.2" % Test,
5858
"org.easymock" % "easymock" % "5.1.0" % Test,
5959
"com.github.sbt" % "junit-interface" % "0.13.3" % Test
@@ -166,10 +166,10 @@ lazy val expressionCompiler = projectMatrix
166166
crossScalaVersions ++= CrossVersion
167167
.partialVersion(scalaVersion.value)
168168
.collect {
169-
case (2, 12) => Seq("2.12.17", "2.12.16", "2.12.15", "2.12.14", "2.12.13", "2.12.12", "2.12.11", "2.12.10")
170-
case (2, 13) => Seq("2.13.10", "2.13.9", "2.13.8", "2.13.7", "2.13.6", "2.13.5", "2.13.4", "2.13.3")
169+
case (2, 12) => Seq("2.12.18", "2.12.17", "2.12.16", "2.12.15", "2.12.14", "2.12.13", "2.12.12", "2.12.11")
170+
case (2, 13) => Seq("2.13.11", "2.13.10", "2.13.9", "2.13.8", "2.13.7", "2.13.6", "2.13.5", "2.13.4", "2.13.3")
171171
case (3, 0) => Seq("3.0.2", "3.0.1", "3.0.0")
172-
case (3, _) => Seq("3.2.2", "3.2.1", "3.2.0", "3.1.3", "3.1.2", "3.1.1", "3.1.0")
172+
case (3, _) => Seq("3.3.0", "3.2.2", "3.2.1", "3.2.0", "3.1.3", "3.1.2", "3.1.1", "3.1.0")
173173
}
174174
.toSeq
175175
.flatten,
@@ -202,7 +202,7 @@ lazy val scala3StepFilter: Project = project
202202
scalaVersion := Dependencies.scala31Plus,
203203
Compile / doc / sources := Seq.empty,
204204
libraryDependencies ++= Seq(
205-
"ch.epfl.scala" %% "tasty-query" % "0.7.9",
205+
"ch.epfl.scala" %% "tasty-query" % "0.8.4",
206206
"org.scala-lang" %% "tasty-core" % scalaVersion.value,
207207
Dependencies.munit % Test
208208
),

modules/core/src/main/scala/ch/epfl/scala/debugadapter/internal/ClassEntryLookUp.scala

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ private class ClassEntryLookUp(
162162

163163
private object ClassEntryLookUp {
164164
private[internal] def apply(entry: ClassEntry, logger: Logger): ClassEntryLookUp = {
165-
val sourceFiles = entry.sourceEntries.flatMap(SourceEntryLookUp.getAllSourceFiles(_, logger))
166-
ClassEntryLookUp(entry, sourceFiles, logger)
165+
val sourceLookUps = entry.sourceEntries.flatMap(SourceEntryLookUp(_, logger))
166+
ClassEntryLookUp(entry, sourceLookUps, logger)
167167
}
168168

169169
def apply(
170170
entry: ClassEntry,
171-
sourceFiles: Seq[SourceFile],
171+
sourceLookUps: Seq[SourceEntryLookUp],
172172
logger: Logger
173173
): ClassEntryLookUp = {
174174
val classFiles = entry.classSystems.flatMap { classSystem =>
@@ -181,8 +181,9 @@ private object ClassEntryLookUp {
181181
val classNameToClassFile =
182182
classFiles.map(c => (c.fullyQualifiedName, c)).toMap
183183

184-
val sourceUriToSourceFile = sourceFiles.map(f => (f.uri, f)).toMap
185-
val sourceNameToSourceFile = sourceFiles.groupBy(f => f.fileName)
184+
val sourceFileToRoot = sourceLookUps.flatMap(l => l.sourceFiles.map(f => (f -> l.root))).toMap
185+
val sourceUriToSourceFile = sourceLookUps.flatMap(_.sourceFiles).map(f => (f.uri, f)).toMap
186+
val sourceNameToSourceFile = sourceLookUps.flatMap(_.sourceFiles).groupBy(f => f.fileName)
186187

187188
val classNameToSourceFile = mutable.Map[String, SourceFile]()
188189
val sourceUriToClassFiles = mutable.Map[URI, Seq[ClassFile]]()
@@ -235,11 +236,11 @@ private object ClassEntryLookUp {
235236
// so we try to find the right package declaration in each file
236237
// it would be very unfortunate that 2 sources file with the same name
237238
// declare the same package.
238-
manySourceFiles.filter(s => findPackage(s, classFile.fullPackage, logger)) match {
239-
case sourceFile :: Nil =>
240-
recordSourceFile(sourceFile)
241-
case _ =>
242-
orphanClassFiles.append(classFile)
239+
manySourceFiles.filter { f =>
240+
findPackage(f, sourceFileToRoot(f), classFile.fullPackage, logger)
241+
} match {
242+
case sourceFile :: Nil => recordSourceFile(sourceFile)
243+
case _ => orphanClassFiles.append(classFile)
243244
}
244245
}
245246
}
@@ -249,6 +250,7 @@ private object ClassEntryLookUp {
249250
if (orphanClassFiles.size > 0)
250251
logger.debug(s"Found ${orphanClassFiles.size} orphan class files in ${entry.name}")
251252

253+
sourceLookUps.foreach(_.close())
252254
new ClassEntryLookUp(
253255
entry,
254256
classNameToClassFile,
@@ -320,17 +322,13 @@ private object ClassEntryLookUp {
320322
}
321323
}
322324

323-
private def findPackage(
324-
sourceFile: SourceFile,
325-
fullPackage: String,
326-
logger: Logger
327-
): Boolean = {
325+
private def findPackage(sourceFile: SourceFile, root: Path, fullPackage: String, logger: Logger): Boolean = {
328326
// for "a.b.c" it returns Seq("a.b.c", "b.c", "c")
329327
// so that we can match on "package a.b.c" or "package b.c" or "package c"
330328
val nestedPackages = fullPackage.split('.').foldLeft(Seq.empty[String]) { (nestedParts, newPart) =>
331329
nestedParts.map(outer => s"$outer.$newPart") :+ newPart
332330
}
333-
val sourceContent = readSourceContent(sourceFile, logger)
331+
val sourceContent = readSourceContent(sourceFile, root, logger)
334332
nestedPackages.exists { `package` =>
335333
val quotedPackage = Regex.quote(`package`)
336334
val matcher = s"package\\s+(object\\s+)?$quotedPackage(\\{|:|;|\\s+)".r
@@ -339,7 +337,13 @@ private object ClassEntryLookUp {
339337
}
340338

341339
private def readSourceContent(sourceFile: SourceFile, logger: Logger): Option[String] = {
342-
withinSourceEntry(sourceFile.entry) { root =>
340+
withinSourceEntry(sourceFile.entry)(readSourceContent(sourceFile, _, logger))
341+
.warnFailure(logger, s"Cannot read content of ${sourceFile.uri}")
342+
.flatten
343+
}
344+
345+
private def readSourceContent(sourceFile: SourceFile, root: Path, logger: Logger): Option[String] = {
346+
Try {
343347
val sourcePath = root.resolve(sourceFile.relativePath)
344348
new String(Files.readAllBytes(sourcePath))
345349
}

modules/core/src/main/scala/ch/epfl/scala/debugadapter/internal/IO.scala

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@ import scala.util.Failure
1111
import scala.util.Success
1212

1313
private[debugadapter] object IO {
14-
def withinJarFile[T](absolutePath: Path)(f: FileSystem => T): Try[T] = try {
14+
def withinJarFile[T](absolutePath: Path)(f: FileSystem => T): Try[T] =
15+
getJarFileSystem(absolutePath).map { fs =>
16+
try f(fs)
17+
finally fs.close()
18+
}
19+
20+
def getJarFileSystem(absolutePath: Path): Try[FileSystem] = try {
1521
val uri = URI.create(s"jar:${absolutePath.toUri}")
1622
val fileSystem = FileSystems.newFileSystem(uri, new util.HashMap[String, Any])
17-
try Success(f(fileSystem))
18-
finally fileSystem.close()
23+
Success(fileSystem)
1924
} catch {
2025
case NonFatal(exception) => Failure(exception)
2126
case zipError: util.zip.ZipError => Failure(zipError)

modules/core/src/main/scala/ch/epfl/scala/debugadapter/internal/SourceEntryLookUp.scala

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import scala.jdk.CollectionConverters.*
1212
import java.net.URI
1313
import ch.epfl.scala.debugadapter.Logger
1414
import ch.epfl.scala.debugadapter.internal.ScalaExtension.*
15+
import scala.util.control.NonFatal
1516

1617
private case class SourceFile(
1718
entry: SourceEntry,
@@ -22,20 +23,44 @@ private case class SourceFile(
2223
def folderPath: String = relativePath.stripSuffix(s"/$fileName")
2324
}
2425

26+
private case class SourceEntryLookUp(
27+
entry: SourceEntry,
28+
sourceFiles: Seq[SourceFile],
29+
fileSystem: FileSystem,
30+
root: Path
31+
) {
32+
def close(): Unit =
33+
try
34+
entry match {
35+
case SourceJar(jar) => fileSystem.close()
36+
case SourceDirectory(directory) => ()
37+
case StandaloneSourceFile(absolutePath, relativePath) => ()
38+
}
39+
catch {
40+
case NonFatal(_) => ()
41+
}
42+
}
43+
2544
private object SourceEntryLookUp {
26-
def getAllSourceFiles(entry: SourceEntry, logger: Logger): Seq[SourceFile] = {
45+
def apply(entry: SourceEntry, logger: Logger): Option[SourceEntryLookUp] = {
2746
entry match {
2847
case SourceJar(jar) =>
29-
IO
30-
.withinJarFile(jar) { fileSystem =>
31-
getAllSourceFiles(entry, fileSystem, fileSystem.getPath("/")).toVector
48+
IO.getJarFileSystem(jar)
49+
.map { fs =>
50+
val root = fs.getPath("/")
51+
val sourceFiles = getAllSourceFiles(entry, fs, root).toVector
52+
SourceEntryLookUp(entry, sourceFiles, fs, root)
3253
}
3354
.warnFailure(logger, s"Cannot list the source files in ${entry.name}")
34-
.getOrElse(Vector.empty)
3555
case SourceDirectory(directory) =>
36-
getAllSourceFiles(entry, FileSystems.getDefault, directory).toSeq
56+
val fs = FileSystems.getDefault
57+
val sourceFiles = getAllSourceFiles(entry, fs, directory).toVector
58+
Some(SourceEntryLookUp(entry, sourceFiles, fs, directory))
3759
case StandaloneSourceFile(absolutePath, relativePath) =>
38-
Seq(SourceFile(entry, relativePath, absolutePath.toUri))
60+
val fs = FileSystems.getDefault
61+
val sourceFile = SourceFile(entry, relativePath, absolutePath.toUri)
62+
val root = fs.getPath(sourceFile.folderPath)
63+
Some(SourceEntryLookUp(entry, Seq(sourceFile), FileSystems.getDefault, root))
3964
}
4065
}
4166

modules/core/src/main/scala/ch/epfl/scala/debugadapter/internal/SourceLookUpProvider.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,14 @@ private[debugadapter] object SourceLookUpProvider {
8383

8484
def apply(entries: Seq[ClassEntry], logger: Logger): SourceLookUpProvider = {
8585
val parrallelEntries = ParVector(entries*)
86-
val sourceFilesByEntry = parrallelEntries
87-
.flatMap(_.sourceEntries)
88-
.distinct
89-
.map(entry => entry -> SourceEntryLookUp.getAllSourceFiles(entry, logger))
90-
.toMap
86+
val sourceLookUps =
87+
parrallelEntries
88+
.flatMap(_.sourceEntries)
89+
.distinct
90+
.map(entry => entry -> SourceEntryLookUp(entry, logger))
91+
.toMap
9192
val allLookUps = parrallelEntries
92-
.map(entry => ClassEntryLookUp(entry, entry.sourceEntries.flatMap(sourceFilesByEntry.apply), logger))
93+
.map(entry => ClassEntryLookUp(entry, entry.sourceEntries.flatMap(sourceLookUps.apply), logger))
9394
.seq
9495
val sourceUriToClassPathEntry = allLookUps
9596
.flatMap(lookup => lookup.sources.map(uri => (uri, lookup)))

modules/core/src/main/scala/ch/epfl/scala/debugadapter/internal/stepfilter/Scala2StepFilter.scala

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package ch.epfl.scala.debugadapter.internal.stepfilter
22

3-
import com.sun.jdi
4-
import ch.epfl.scala.debugadapter.internal.scalasig._
5-
import ch.epfl.scala.debugadapter.internal.SourceLookUpProvider
6-
import ch.epfl.scala.debugadapter.internal.scalasig.ScalaSigPrinter
73
import ch.epfl.scala.debugadapter.Logger
84
import ch.epfl.scala.debugadapter.ScalaVersion
5+
import ch.epfl.scala.debugadapter.internal.SourceLookUpProvider
6+
import ch.epfl.scala.debugadapter.internal.scalasig.ScalaSigPrinter
7+
import ch.epfl.scala.debugadapter.internal.scalasig._
8+
import com.sun.jdi
9+
910
import scala.jdk.CollectionConverters.*
11+
import scala.util.matching.Regex
1012

1113
class Scala2StepFilter(
1214
sourceLookUp: SourceLookUpProvider,
@@ -122,12 +124,11 @@ class Scala2StepFilter(
122124
// TODO try use tryEncode
123125
getOwners(scalaClass)
124126
.foldRight(Option(javaClass.name)) { (sym, acc) =>
125-
for (javaName <- acc if javaName.contains(sym.name)) yield {
126-
javaName
127-
.split(sym.name)
127+
for (javaName <- acc if javaName.contains(sym.name))
128+
yield javaName
129+
.split(Regex.quote(sym.name))
128130
.drop(1)
129131
.mkString(sym.name)
130-
}
131132
}
132133
.exists { remainder =>
133134
remainder.forall(c => c.isDigit || c == '$')

modules/expression-compiler/src/main/scala-3/dotty/tools/dotc/evaluation/EvaluationStrategy.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import dotty.tools.dotc.util.Property.*
1212
enum EvaluationStrategy:
1313
case This(cls: ClassSymbol)
1414
case Outer(outerCls: ClassSymbol)
15+
case LocalOuter(outerCls: ClassSymbol) // the $outer param in a constructor
1516
case LocalValue(variable: TermSymbol, isByName: Boolean)
1617
case LocalValueAssign(variable: TermSymbol)
1718
case MethodCapture(variable: TermSymbol, method: TermSymbol, isByName: Boolean)

0 commit comments

Comments
 (0)