Skip to content

Commit 40ed8d4

Browse files
committed
Share common implementation of repl.AbstractFileClassLoader with io.AbstractFileClassLoader
1 parent d5fec8f commit 40ed8d4

File tree

1 file changed

+3
-20
lines changed

1 file changed

+3
-20
lines changed

repl/src/dotty/tools/repl/AbstractFileClassLoader.scala

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,8 @@ import io.AbstractFile
2020
import java.net.{URL, URLConnection, URLStreamHandler}
2121
import java.util.Collections
2222

23-
class AbstractFileClassLoader(val root: AbstractFile, parent: ClassLoader, interruptInstrumentation: String) extends ClassLoader(parent):
24-
private def findAbstractFile(name: String) = root.lookupPath(name.split('/').toIndexedSeq, directory = false)
25-
26-
// on JDK 20 the URL constructor we're using is deprecated,
27-
// but the recommended replacement, URL.of, doesn't exist on JDK 8
28-
@annotation.nowarn("cat=deprecation")
29-
override protected def findResource(name: String): URL | Null =
30-
findAbstractFile(name) match
31-
case null => null
32-
case file => new URL(null, s"memory:${file.path}", new URLStreamHandler {
33-
override def openConnection(url: URL): URLConnection = new URLConnection(url) {
34-
override def connect() = ()
35-
override def getInputStream = file.input
36-
}
37-
})
38-
override protected def findResources(name: String): java.util.Enumeration[URL] =
39-
findResource(name) match
40-
case null => Collections.enumeration(Collections.emptyList[URL]) //Collections.emptyEnumeration[URL]
41-
case url => Collections.enumeration(Collections.singleton(url))
23+
class AbstractFileClassLoader(root: AbstractFile, parent: ClassLoader, interruptInstrumentation: String)
24+
extends io.AbstractFileClassLoader(root, parent):
4225

4326
override def findClass(name: String): Class[?] = {
4427
var file: AbstractFile | Null = root
@@ -68,7 +51,7 @@ class AbstractFileClassLoader(val root: AbstractFile, parent: ClassLoader, inter
6851
val loaded = findLoadedClass(name) // Check if already loaded
6952
if loaded != null then return loaded
7053

71-
name match {
54+
name match {
7255
// Don't instrument JDK classes or StopRepl. These are often restricted to load from a single classloader
7356
// due to the JDK module system, and so instrumenting them and loading the modified copy of the class
7457
// results in runtime exceptions

0 commit comments

Comments
 (0)