I have some very simple code that uses the toolbox to execute some
code provided as string:
object Test extends App {
import java.io.File
import java.net.URLClassLoader
import scala.reflect.runtime.universe.runtimeMirror
import scala.tools.reflect.ToolBox
val path = Seq(
"/home/antoras/dev/scala/ToolboxTest/bin" // this path
contains my project
)
val cl = new URLClassLoader(
path.map(p => new File(p).toURI().toURL()).toArray,
getClass.getClassLoader())
val tb = runtimeMirror(cl).mkToolBox()
import tb._, u._
val tree = typecheck(parse("object M {import simple._; class X
extends Interface}"))
new Traverser {
override def traverse(t: Tree) {
t match {
case ClassDef(_, _, _, Template(parents, _, _)) =>
parents foreach {
case tt: TypeTree =>
Option(tt.original) foreach { o =>
val sit = typeOf[simple.Interface]
val sym = o.symbol
println(sit.typeSymbol == sym)
println(sym.asType.toType <:< sit)
}
case _ =>
}
case _ =>
}
super.traverse(t)
}
}.traverse(tree)
}
// and in another file
package simple
class Obj
trait Interface {
val obj: Obj
}
This code works as expected, it prints two times `true`. The problem
is that I tried to use this code inside of the IDE and therefore in
an OSGi environment but there it prints two times `false`. Looking
inside with the debugger shows that the symbols look identical but
they aren't.
All types come from the ToolBox, whose classpath can access OSGi
packages, therefore I'm not sure if this may be a problem about
different classpaths. Any ideas how different classpaths could
happen or what else makes my live hard here?