|
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
|
@@ -534,24 +533,36 @@ class ReplDriver(settings: Array[String],
|
534 | 533 | }
|
535 | 534 | }
|
536 | 535 |
|
537 |
| - // TODO: no idea how to access and reload the class paths |
538 |
| - val newClassPath = state.context.platform.classPath(using state.context).asURLs :+ f.toURI.toURL |
539 |
| - println(s"new class path=${newClassPath.mkString(", ")}") |
540 |
| - val clsl = rendering.classLoader()(using state.context) |
541 |
| - val newClsl = fromURLsParallelCapable(newClassPath, clsl) |
542 |
| - println(s"newClsl getResource=${newClsl.getURLs.toList}") |
543 |
| - newClsl.asContext(state.context) |
544 |
| - |
545 |
| -// Scala 2: |
546 |
| -// def alreadyDefined(clsName: String) = classLoader.tryToLoadClass(clsName).isDefined |
547 |
| -// val existingClass = entries.filter(_.ext.isClass).map(classNameOf).find(alreadyDefined) |
548 |
| - |
549 |
| -// if (existingClass.nonEmpty) out.println(s"The path '$f' cannot be loaded, it contains a classfile that already exists on the classpath: ${existingClass.get}") |
550 |
| -// else { |
551 |
| -// intp.addUrlsToClassPath(f.toURI.toURL) |
| 536 | + def alreadyDefined(clsName: String) = state.context.platform.classPath(using state.context).findClassFile(clsName).isDefined |
| 537 | + val existingClass = entries.filter(_.ext.isClass).map(classNameOf).find(alreadyDefined) |
| 538 | + if (existingClass.nonEmpty) |
| 539 | + out.println(s"The path '$f' cannot be loaded, it contains a classfile that already exists on the classpath: ${existingClass.get}") |
| 540 | + else |
| 541 | +// val cp = state.context.platform.classPath(using state.context).asClassPathString |
| 542 | +// println(s"CURRENT CP STRING: $cp") |
| 543 | +// val newCP = s"$cp${JFile.pathSeparator}$path" |
| 544 | +// println(s"UPDATED CP: $newCP") |
| 545 | + |
| 546 | + // add to compiler class path |
| 547 | + println(s"INIT state classPath = ${state.context.platform.classPath(using state.context).asClassPathString}") |
| 548 | + val cpCP = ClassPathFactory.newClassPath(jarFile)(using state.context) |
| 549 | + state.context.platform.addToClassPath(cpCP) |
| 550 | + println(s"classPath after add = ${state.context.platform.classPath(using state.context).asClassPathString}") |
| 551 | + |
| 552 | + // create initial context |
| 553 | + rootCtx = setupRootCtx(Array(), rootCtx) |
| 554 | + state.copy(context = rootCtx) |
| 555 | + |
| 556 | + |
| 557 | + // new class loader |
| 558 | +// val newClassPath = state.context.platform.classPath(using state.context).asURLs :+ f.toURI.toURL |
| 559 | +// val oldCL = rendering.classLoader()(using state.context) |
| 560 | +// val newCL = fromURLsParallelCapable(newClassPath, oldCL) |
| 561 | +// println(s"new CL class path = ${newCL.getURLs.toList}") |
| 562 | +// println(s"\nclass name = ${cpCP.className}") |
| 563 | +// rendering.myClassLoader = new AbstractFileClassLoader(state.context.settings.outputDir.default, newCL) |
552 | 564 | // out.println(s"Added '$path' to classpath.")
|
553 |
| -// out.println("Added '%s'. Your new classpath is:\n\"%s\"".format(f.path, intp.classPathString)) |
554 |
| -// } |
| 565 | + println(s"after setupRootCtx classPath = ${state.context.platform.classPath(using state.context).asClassPathString}") |
555 | 566 | state
|
556 | 567 |
|
557 | 568 | case KindOf(expr) =>
|
|
0 commit comments