/*package*/ Collection<TraceNodeUI> getResult() { closeStepNode(); ArrayList<TraceNodeUI> rv = new ArrayList<TraceNodeUI>(myResult.size()); if (myExcludeEmptySteps) { for (TraceNodeUI n : myResult) { if (n.hasChildren()) { rv.add(n); } } return rv; } else { return myResult; } }
private Iterable<TraceNodeUI> compactTemplates(Iterable<TraceNodeUI> templateNodes) { if (!myCompactTemplates) { return templateNodes; } // compactByNavigateTarget(); ArrayList<TraceNodeUI> rv = new ArrayList<TraceNodeUI>(); LinkedHashMap<SNode, TraceNodeUI> mostSpecificTemplates = new LinkedHashMap<SNode, TraceNodeUI>(); L1: for (TraceNodeUI n : templateNodes) { SNodeReference t = n.getNavigateTarget(); SNode templateNode = t == null ? null : t.resolve(MPSModuleRepository.getInstance()); if (templateNode == null) { rv.add(n); continue; } for (SNode tn : new ArrayList<SNode>(mostSpecificTemplates.keySet())) { if (tn.getContainingRoot() == templateNode.getContainingRoot()) { // within same hierarchy if (SNodeOperations.isAncestor(tn, templateNode)) { // templateNode is more specific template than the one we already got in // mostSpecificTemplates mostSpecificTemplates.remove(tn); mostSpecificTemplates.put(templateNode, n); continue L1; } else if (SNodeOperations.isAncestor(templateNode, tn)) { // templateNode is enclosing template, forget it continue L1; } // else unrelated, two independent descendants, continue looking through most specific // templates found. } } // no related templates found, record present one mostSpecificTemplates.put(templateNode, n); } rv.addAll(mostSpecificTemplates.values()); return rv; }
private void closeStepNode() { if (myStepNode == null) { return; } for (Pair<SNodeReference, SNodeReference> p : myGroupedChanges.keySet()) { TraceNodeUI in = new TraceNodeUI(Kind.INPUT, p.o1); TraceNodeUI out = new TraceNodeUI(Kind.OUTPUT, p.o2); for (TraceNodeUI templates : compactTemplates(myGroupedChanges.get(p))) { out.addChild(templates); } in.addChild(out); myStepNode.addChild(in); } if (myGroupByStep) { myResult.add(myStepNode); } else { for (TraceNodeUI n : myStepNode.getChildren()) { myResult.add(n); } } myStepNode = null; }