@@ -19,16 +19,39 @@ import java.util.Collections
1919
2020class AbstractFileClassLoader (val root : AbstractFile , parent : ClassLoader )
2121 extends ClassLoader (parent):
22- private def findAbstractFile (name : String ) =
23- root.lookupPath(name.split('/' ).toIndexedSeq, directory = false )
22+
23+ /** Splits the given path using the given separator char, and finds the corresponding file through
24+ * subdirectories. Optionally adds the given suffix to the last component. This is intended to
25+ * make it easy to find files in formats such as "java/lang/Object" or "java.lang.Object".
26+ */
27+ final def lookupPath (
28+ path : String ,
29+ separator : Char ,
30+ lastSuffix : String = " " ,
31+ directory : Boolean = false
32+ ): Option [AbstractFile ] =
33+ var file : AbstractFile = root
34+ var idx = 0
35+ var nextStepIdx = - 1
36+ while
37+ nextStepIdx = path.indexOf(separator, idx)
38+ nextStepIdx != - 1
39+ do
40+ file.lookupName(path.substring(idx, nextStepIdx), directory = true ) match
41+ case null => return None
42+ case f =>
43+ file = f
44+ idx = nextStepIdx + 1
45+ Option (file.lookupName(path.substring(idx) + lastSuffix, directory = directory))
46+ end lookupPath
2447
2548 // on JDK 20 the URL constructor we're using is deprecated,
2649 // but the recommended replacement, URL.of, doesn't exist on JDK 8
2750 @ annotation.nowarn(" cat=deprecation" )
2851 override protected def findResource (name : String ): URL | Null =
29- findAbstractFile (name) match
30- case null => null
31- case file => new URL (
52+ lookupPath (name, '/' ) match
53+ case None => null
54+ case Some ( file) => new URL (
3255 null ,
3356 s " memory: ${file.path}" ,
3457 new URLStreamHandler {
0 commit comments