public bool IsUnderContentGroup(PSMElement element, out PSMElement groupElement) { //Debug.Assert(PSMTreeIterator.ModelsElement(element)); groupElement = null; if (element.ModelsElement() /* && !(element is PSMAttribute) */) { return(false); } PSMTreeIterator it = new PSMTreeIterator(element); while (it.CanGoToParent()) { it.GoToParent(); if (IsContentGroupNode(it.CurrentNode)) { groupElement = it.CurrentNode; return(true); } if (it.CurrentNodeModelsElement()) { return(false); } } return(false); }
private void CategorizeSubtree(PSMTreeIterator iterator) { if (iterator.CurrentNodeModelsElement() || IsContentGroupNode(iterator.CurrentNode)) { significantNodes.Add(iterator.CurrentNode); bool isRed = false; if ((changesByTargetSignificantNode.ContainsKey(iterator.CurrentNode) && !changesByTargetSignificantNode[iterator.CurrentNode].All(c => c.Element == iterator.CurrentNode && c is ICanBeIgnoredOnTarget)) || GetState(iterator.CurrentNode) == EContentPlacementState.Added) { redNodes.Add(iterator.CurrentNode); isRed = true; } PSMElement cn = iterator.CurrentNode; foreach (PSMElement child in iterator.GetChildNodes()) { iterator.CurrentNode = child; CategorizeSubtree(iterator); } iterator.CurrentNode = cn; PSMElement firstFoundRedChild = iterator.GetChildNodes().FirstOrDefault(child => (child is PSMAssociation) && redNodes.Contains(((PSMAssociation)child).Child) && IsContentGroupNode(((PSMAssociation)child).Child)); if (!isRed && firstFoundRedChild != null) { isRed = true; int index = redNodes.IndexOf(((PSMAssociation)firstFoundRedChild).Child); redNodes.Insert(index, iterator.CurrentNode); } if (!isRed) { if (iterator.GetChildNodes().Any(child => redNodes.Contains(child) || blueNodes.Contains(child) || insignificantBlueNodes.Contains(child))) { blueNodes.Add(iterator.CurrentNode); } else { greenNodes.Add(iterator.CurrentNode); } } } else { PSMElement cn = iterator.CurrentNode; foreach (PSMElement child in iterator.GetChildNodes()) { iterator.CurrentNode = child; CategorizeSubtree(iterator); } iterator.CurrentNode = cn; if (iterator.GetChildNodes().Any(child => redNodes.Contains(child) || blueNodes.Contains(child) || insignificantBlueNodes.Contains(child))) { insignificantBlueNodes.Add(iterator.CurrentNode); } } }
public static string SuggestTemplateName(PSMElement node) { PSMTreeIterator t = new PSMTreeIterator(node); string name = string.Empty; while (t.CanGoToParent()) { string step = t.CurrentNodeModelsElement() ? GetElementNameForSignificantElement(t.CurrentNode) : t.CurrentNode.Name; name = !string.IsNullOrEmpty(step) ? step + "-" + name : name; t.GoToParent(); } if (t.CurrentNode != null) { string step = t.CurrentNodeModelsElement() ? GetElementNameForSignificantElement(t.CurrentNode) : t.CurrentNode.Name; name = step + "-" + name; } return(name.Trim('-') + "-iteration"); }