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 static IEnumerable <FollowedPath> FollowPath(PSMElement element, FollowedPath followedPath) { List <FollowedPath> result = new List <FollowedPath>(); PSMTreeIterator it = new PSMTreeIterator(element); followedPath.Add(element); while (it.CanGoToParent()) { it.GoToParent(); PSMClass psmClass = it.CurrentNode as PSMClass; if (psmClass != null && psmClass.IsReferencedFromStructuralRepresentative()) { foreach (PSMClass representative in psmClass.Diagram.DiagramElements.Keys.OfType <PSMClass>().Where(rClass => rClass.RepresentedPSMClass == psmClass)) { result.AddRange(FollowPath(representative, followedPath.Copy())); } } followedPath.Add(it.CurrentNode); } if (followedPath.Last() is PSMClass && ((PSMClass)followedPath.Last()).HasElementLabel) { result.Add(followedPath); } return(result); }
/// <summary> /// returns the path to the closest ancestor of <see cref="addedNode"/> /// that existed in the previous version. /// </summary> /// <param name="addedNode">The added node.</param> /// <param name="oldVersion">The old version.</param> /// <returns>xpath expression</returns> private static XPathExpr GetXPathForAddedNode(PSMElement addedNode, Version oldVersion) { PSMTreeIterator it = new PSMTreeIterator(addedNode); PSMElement ancestorOldVersion = null; while (ancestorOldVersion == null) { if (it.CanGoToParent()) { it.GoToParent(); } else { return(null); } it.CurrentNode = it.GetSignificantAncestorOrSelf(); if (it.CurrentNode != null) { ancestorOldVersion = (PSMElement)it.CurrentNode.GetInVersion(oldVersion); } else { break; } } return(ancestorOldVersion != null?ancestorOldVersion.XPathE() : null); }
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"); }