|
1 | 1 | package dotty.tools.repl
|
2 | 2 |
|
3 | 3 | import scala.language.unsafeNulls
|
4 |
| - |
5 |
| -import java.io.{File => JFile, PrintStream} |
| 4 | +import java.io.{PrintStream, File as JFile} |
6 | 5 | import java.nio.charset.StandardCharsets
|
7 |
| - |
8 | 6 | import dotty.tools.dotc.ast.Trees.*
|
9 | 7 | import dotty.tools.dotc.ast.{tpd, untpd}
|
| 8 | +import dotty.tools.dotc.classpath.{AggregateClassPath, ClassPathFactory, ZipAndJarClassPathFactory} |
10 | 9 | import dotty.tools.dotc.config.CommandLineParser.tokenize
|
11 | 10 | import dotty.tools.dotc.config.Properties.{javaVersion, javaVmName, simpleVersionString}
|
12 | 11 | import dotty.tools.dotc.core.Contexts.*
|
13 | 12 | import dotty.tools.dotc.core.Decorators.*
|
14 |
| -import dotty.tools.dotc.core.Phases.{unfusedPhases, typerPhase} |
| 13 | +import dotty.tools.dotc.core.Phases.{typerPhase, unfusedPhases} |
15 | 14 | import dotty.tools.dotc.core.Denotations.Denotation
|
16 | 15 | import dotty.tools.dotc.core.Flags.*
|
17 | 16 | import dotty.tools.dotc.core.Mode
|
@@ -529,24 +528,36 @@ class ReplDriver(settings: Array[String],
|
529 | 528 | }
|
530 | 529 | }
|
531 | 530 |
|
532 |
| - // TODO: no idea how to access and reload the class paths |
533 |
| - val newClassPath = state.context.platform.classPath(using state.context).asURLs :+ f.toURI.toURL |
534 |
| - println(s"new class path=${newClassPath.mkString(", ")}") |
535 |
| - val clsl = rendering.classLoader()(using state.context) |
536 |
| - val newClsl = fromURLsParallelCapable(newClassPath, clsl) |
537 |
| - println(s"newClsl getResource=${newClsl.getURLs.toList}") |
538 |
| - newClsl.asContext(state.context) |
539 |
| - |
540 |
| -// Scala 2: |
541 |
| -// def alreadyDefined(clsName: String) = classLoader.tryToLoadClass(clsName).isDefined |
542 |
| -// val existingClass = entries.filter(_.ext.isClass).map(classNameOf).find(alreadyDefined) |
543 |
| - |
544 |
| -// if (existingClass.nonEmpty) out.println(s"The path '$f' cannot be loaded, it contains a classfile that already exists on the classpath: ${existingClass.get}") |
545 |
| -// else { |
546 |
| -// intp.addUrlsToClassPath(f.toURI.toURL) |
| 531 | + def alreadyDefined(clsName: String) = state.context.platform.classPath(using state.context).findClassFile(clsName).isDefined |
| 532 | + val existingClass = entries.filter(_.ext.isClass).map(classNameOf).find(alreadyDefined) |
| 533 | + if (existingClass.nonEmpty) |
| 534 | + out.println(s"The path '$f' cannot be loaded, it contains a classfile that already exists on the classpath: ${existingClass.get}") |
| 535 | + else |
| 536 | +// val cp = state.context.platform.classPath(using state.context).asClassPathString |
| 537 | +// println(s"CURRENT CP STRING: $cp") |
| 538 | +// val newCP = s"$cp${JFile.pathSeparator}$path" |
| 539 | +// println(s"UPDATED CP: $newCP") |
| 540 | + |
| 541 | + // add to compiler class path |
| 542 | + println(s"INIT state classPath = ${state.context.platform.classPath(using state.context).asClassPathString}") |
| 543 | + val cpCP = ClassPathFactory.newClassPath(jarFile)(using state.context) |
| 544 | + state.context.platform.addToClassPath(cpCP) |
| 545 | + println(s"classPath after add = ${state.context.platform.classPath(using state.context).asClassPathString}") |
| 546 | + |
| 547 | + // create initial context |
| 548 | + rootCtx = setupRootCtx(Array(), rootCtx) |
| 549 | + state.copy(context = rootCtx) |
| 550 | + |
| 551 | + |
| 552 | + // new class loader |
| 553 | +// val newClassPath = state.context.platform.classPath(using state.context).asURLs :+ f.toURI.toURL |
| 554 | +// val oldCL = rendering.classLoader()(using state.context) |
| 555 | +// val newCL = fromURLsParallelCapable(newClassPath, oldCL) |
| 556 | +// println(s"new CL class path = ${newCL.getURLs.toList}") |
| 557 | +// println(s"\nclass name = ${cpCP.className}") |
| 558 | +// rendering.myClassLoader = new AbstractFileClassLoader(state.context.settings.outputDir.default, newCL) |
547 | 559 | // out.println(s"Added '$path' to classpath.")
|
548 |
| -// out.println("Added '%s'. Your new classpath is:\n\"%s\"".format(f.path, intp.classPathString)) |
549 |
| -// } |
| 560 | + println(s"after setupRootCtx classPath = ${state.context.platform.classPath(using state.context).asClassPathString}") |
550 | 561 | state
|
551 | 562 |
|
552 | 563 | case TypeOf(expr) =>
|
|
0 commit comments