diplomacy: find names of LazyModules also in Seq() member values (#527)
This commit is contained in:
parent
3fc55298ef
commit
46cdfc2b45
@ -17,15 +17,28 @@ abstract class LazyModule()(implicit val p: Parameters)
|
|||||||
LazyModule.stack = this :: LazyModule.stack
|
LazyModule.stack = this :: LazyModule.stack
|
||||||
parent.foreach(p => p.children = this :: p.children)
|
parent.foreach(p => p.children = this :: p.children)
|
||||||
|
|
||||||
lazy val className = getClass.getName.split('.').last
|
private var suggestedName: Option[String] = None
|
||||||
lazy val valName = parent.flatMap { p =>
|
def suggestName(x: String) = suggestedName = Some(x)
|
||||||
p.getClass.getMethods.filter { m =>
|
|
||||||
|
private lazy val childNames =
|
||||||
|
getClass.getMethods.filter { m =>
|
||||||
m.getParameterTypes.isEmpty &&
|
m.getParameterTypes.isEmpty &&
|
||||||
!java.lang.reflect.Modifier.isStatic(m.getModifiers) &&
|
!java.lang.reflect.Modifier.isStatic(m.getModifiers) &&
|
||||||
classOf[LazyModule].isAssignableFrom(m.getReturnType) &&
|
m.getName != "children"
|
||||||
(m.invoke(p) eq this)
|
}.flatMap { m =>
|
||||||
}.headOption.map(_.getName)
|
if (classOf[LazyModule].isAssignableFrom(m.getReturnType)) {
|
||||||
}
|
Seq((m.getName, m.invoke(this)))
|
||||||
|
} else if (classOf[Seq[LazyModule]].isAssignableFrom(m.getReturnType)) {
|
||||||
|
m.invoke(this).asInstanceOf[Seq[Object]].zipWithIndex.map { case (l, i) =>
|
||||||
|
(m.getName + "_" + i, l)
|
||||||
|
}
|
||||||
|
} else Seq()
|
||||||
|
}
|
||||||
|
private def findValName =
|
||||||
|
parent.flatMap(_.childNames.find(_._2 eq this)).map(_._1)
|
||||||
|
|
||||||
|
lazy val className = getClass.getName.split('.').last
|
||||||
|
lazy val valName = suggestedName.orElse(findValName)
|
||||||
lazy val outerName = if (nodes.size != 1) None else nodes(0).gco.flatMap(_.lazyModule.valName)
|
lazy val outerName = if (nodes.size != 1) None else nodes(0).gco.flatMap(_.lazyModule.valName)
|
||||||
|
|
||||||
def moduleName = className + valName.orElse(outerName).map("_" + _).getOrElse("")
|
def moduleName = className + valName.orElse(outerName).map("_" + _).getOrElse("")
|
||||||
|
Loading…
Reference in New Issue
Block a user