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:
parent
280af9684b
commit
dc66c8857f
@ -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()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user