@@ -16,15 +16,30 @@ object Toolbox {
16
16
implicit def make (implicit settings : Settings ): Toolbox = Toolbox .make
17
17
}
18
18
19
- @ forceInline def make4 (implicit settings : Settings ): Toolbox = {
19
+ /** Create a new instance of the toolbox.
20
+ *
21
+ * This instance of the toolbox tries to recover the classloader of the application based on
22
+ * the classloader of the class that call make. This may not always be the correct classloader.
23
+ *
24
+ * @param settings TODO
25
+ * @return
26
+ */
27
+ @ forceInline def make (implicit settings : Settings ): Toolbox = {
20
28
// TODO find the name of the class that needs to be loaded. Maybe from a stack trace.
21
29
22
30
// We force inline to make forName use the classloader of the class at callsite
23
- val cl = Class .forName(" hello.Main" ).getClassLoader
24
- make2(cl)
31
+ val clazz = Class .forName(" hello.Main" )
32
+ val cl = clazz.getClassLoader
33
+ make(cl)
25
34
}
26
35
27
- def make2 (cl : ClassLoader )(implicit settings : Settings ): Toolbox = {
36
+ /** Create a new instance of the toolbox
37
+ *
38
+ * @param cl TODO
39
+ * @param settings TODO
40
+ * @return A new instance of the toolbox
41
+ */
42
+ def make (cl : ClassLoader )(implicit settings : Settings ): Toolbox = {
28
43
try {
29
44
val toolboxImplCls = cl.loadClass(" dotty.tools.dotc.quoted.ToolboxImpl" )
30
45
val makeMeth = toolboxImplCls.getMethod(" make2" , classOf [Settings ], classOf [ClassLoader ])
@@ -39,30 +54,6 @@ object Toolbox {
39
54
}
40
55
}
41
56
42
- @ inline
43
- def make3 (implicit settings : Settings ): Toolbox = {
44
- val cls = Class .forName(" hello.Main" )
45
- val cl = cls.getClassLoader()
46
- make2(cl)
47
- }
48
-
49
- def make (implicit settings : Settings ): Toolbox = {
50
- val cl = getClass.getClassLoader
51
-
52
- try {
53
- val toolboxImplCls = cl.loadClass(" dotty.tools.dotc.quoted.ToolboxImpl" )
54
- val makeMeth = toolboxImplCls.getMethod(" make" , classOf [Settings ])
55
- makeMeth.invoke(null , settings).asInstanceOf [Toolbox ]
56
- }
57
- catch {
58
- case ex : ClassNotFoundException =>
59
- throw new ToolboxNotFoundException (
60
- s """ Could not load the Toolbox class ` ${ex.getMessage}` from the JVM classpath. Make sure that the compiler is on the JVM classpath. """ ,
61
- ex
62
- )
63
- }
64
- }
65
-
66
57
/** Setting of the Toolbox instance. */
67
58
case class Settings private (outDir : Option [String ], showRawTree : Boolean , compilerArgs : List [String ], color : Boolean )
68
59
0 commit comments