1
0

diplomacy: be more robust using Java introspection

If an error occures, some objects might only be partially initialized.
We want to still be able to get nice names for error messages.
This commit is contained in:
Wesley W. Terpstra 2017-01-30 14:25:12 -08:00
parent 280af9684b
commit dc66c8857f

View File

@ -27,10 +27,15 @@ abstract class LazyModule()(implicit val p: Parameters)
m.getName != "children" m.getName != "children"
}.flatMap { m => }.flatMap { m =>
if (classOf[LazyModule].isAssignableFrom(m.getReturnType)) { if (classOf[LazyModule].isAssignableFrom(m.getReturnType)) {
Seq((m.getName, m.invoke(this))) val obj = m.invoke(this)
if (obj eq null) Seq() else Seq((m.getName, obj))
} else if (classOf[Seq[LazyModule]].isAssignableFrom(m.getReturnType)) { } else if (classOf[Seq[LazyModule]].isAssignableFrom(m.getReturnType)) {
m.invoke(this).asInstanceOf[Seq[Object]].zipWithIndex.map { case (l, i) => val obj = m.invoke(this)
(m.getName + "_" + i, l) if (obj eq null) Seq() else {
val seq = try { obj.asInstanceOf[Seq[Object]] } catch { case _ => null }
if (seq eq null) Seq() else {
seq.zipWithIndex.map { case (l, i) => (m.getName + "_" + i, l) }
}
} }
} else Seq() } else Seq()
} }