@@ -266,25 +266,36 @@ object Contexts {
266266 base.sources.getOrElseUpdate(file, new SourceFile (file, codec))
267267 }
268268
269- /** Sourcefile with given path name, memoized */
270- def getSource (path : TermName ): SourceFile = base.sourceNamed.get(path) match {
269+ /** SourceFile with given path name, memoized */
270+ def getSource (path : TermName ): SourceFile = base.sourceNamed.get(path) match
271271 case Some (source) =>
272272 source
273- case None => try {
274- val f = new PlainFile (Path (path.toString))
275- val src = getSource(f)
276- base.sourceNamed(path) = src
277- src
278- } catch {
279- case ex : InvalidPathException =>
280- report.error(s " invalid file path: ${ex.getMessage}" )
281- NoSource
282- }
283- }
273+ case None =>
274+ getFile(path) match
275+ case NoAbstractFile => NoSource
276+ case file => getSource(file)
284277
285- /** Sourcefile with given path, memoized */
278+ /** SourceFile with given path, memoized */
286279 def getSource (path : String ): SourceFile = getSource(path.toTermName)
287280
281+ /** AbstraFile with given path name, memoized */
282+ def getFile (path : TermName ): AbstractFile = base.files.get(path) match
283+ case Some (file) =>
284+ file
285+ case None =>
286+ try
287+ val file = new PlainFile (Path (path.toString))
288+ base.files(path) = file
289+ file
290+ catch
291+ case ex : InvalidPathException =>
292+ report.error(s " invalid file path: ${ex.getMessage}" )
293+ NoAbstractFile
294+
295+ /** AbstractFile with given path, memoized */
296+ def getFile (path : String ): AbstractFile = getFile(path.toTermName)
297+
298+
288299 private var related : SimpleIdentityMap [Phase | SourceFile , Context ] = null
289300
290301 private def lookup (key : Phase | SourceFile ): Context =
@@ -842,9 +853,10 @@ object Contexts {
842853 private var _nextSymId : Int = 0
843854 def nextSymId : Int = { _nextSymId += 1 ; _nextSymId }
844855
845- /** Sources that were loaded */
856+ /** Sources and Files that were loaded */
846857 val sources : util.HashMap [AbstractFile , SourceFile ] = util.HashMap [AbstractFile , SourceFile ]()
847858 val sourceNamed : util.HashMap [TermName , SourceFile ] = util.HashMap [TermName , SourceFile ]()
859+ val files : util.HashMap [TermName , AbstractFile ] = util.HashMap ()
848860
849861 // Types state
850862 /** A table for hash consing unique types */
@@ -929,6 +941,7 @@ object Contexts {
929941 errorTypeMsg.clear()
930942 sources.clear()
931943 sourceNamed.clear()
944+ files.clear()
932945 comparers.clear() // forces re-evaluation of top and bottom classes in TypeComparer
933946
934947 // Test that access is single threaded
0 commit comments