public void printTreeAsHTML(StringBuilder sb) { if (scope != null) { sb.append("<li><b>") .append(scope.getClass().getSimpleName()) .append("</b> <i>") .append(scope.getFullName()) .append("</i>"); } if (!assignments.isEmpty()) { sb.append("<ul>"); for (Assignment a : assignments) { sb.append("<li><font color='blue'>") .append(a.getClass().getSimpleName()) .append(" : <u>") .append(a.getIdentifier()) .append("</u></font></li>"); } sb.append("</ul>"); } if (!children.isEmpty()) { sb.append("<ul>"); for (ScopeTreeNode stn : children) { stn.printTreeAsHTML(sb); } sb.append("</ul>"); } }
@Override public int visit(IVisitableNode node) { if (node instanceof Scope) { Scope scope = (Scope) node; scopeTree.add(scope, null); } else if (node instanceof Assignment) { Assignment ass = (Assignment) node; scopeTree.add(ass.getMyScope(), ass); } return V_CONTINUE; }
public String getScopeTreeAsHTMLPage() { StringBuilder sb = new StringBuilder(); sb.append("<HTML><HEAD><TITLE>Scope Tree</TITLE></HEAD><BODY><ul>"); scopeTree.printTreeAsHTML(sb); sb.append("</ul></BODY></HTML>"); return sb.toString(); }
void addPath(List<Scope> scopePath, Assignment a) { if (scopePath.isEmpty()) { if (a != null) { assignments.add(a); } return; } Scope lastParent = scopePath.remove(scopePath.size() - 1); for (ScopeTreeNode stn : children) { if (stn.scope == lastParent) { stn.addPath(scopePath, a); lastParent = null; break; } } if (lastParent != null) { ScopeTreeNode newChild = new ScopeTreeNode(lastParent); children.add(newChild); newChild.addPath(scopePath, a); } }