Improved pretty printing (toString()).

This commit is contained in:
Achim D. Brucker 2016-09-10 23:20:34 +01:00
parent f2a31d9b1d
commit 6beabb2d23
1 changed files with 21 additions and 6 deletions

View File

@ -15,19 +15,34 @@ import com.ibm.wala.ipa.callgraph.CGNode;
class CallTree(value: CGNode, children: List[CallTree]) {
def this(value: CGNode) = this(value, null)
private val indent = 5
def contains(v: CGNode): Boolean = {
if (value == v) {
true
} else {
(children.map { c => c.contains(v) }).fold(false) { (a, b) => a || b }
if (null == children) {
false
} else {
(children.map { c => c.contains(v) }).fold(false) { (a, b) => a || b }
}
}
}
def toString(prefix: String): String = {
def childrenToString(c: List[CallTree]): String = c match {
case null => ""
case Nil => ""
case c :: Nil => "\n" + prefix + "└─ " + c.toString(prefix + " ")
case c :: tail => "\n" + prefix + "├─ " + c.toString(prefix + "│ ") + childrenToString(tail)
}
if (null == value) {
"null:CallTree"
} else {
value.toString() + childrenToString(children)
}
}
override def toString(): String = {
value.getMethod().getName().toString() + "\n" + ((children.map { c => "├── " + c.toString() + "\n" })
.fold("") { (a, b) => a + b })
toString("")
}
}