Пример #1
0
        /// <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);
        }
Пример #2
0
 /// <summary>
 /// Marks nodes blue or red if there is a change in the represented
 /// class/subtree.
 /// </summary>
 private void FixStructuralRepresentatives()
 {
     PSMTreeIterator.NodeMarker additionalNodeMarker = IsContentGroupNode;
     foreach (PSMClass sr in Diagram.DiagramElements.Keys.OfType <PSMClass>().Where(c => c.IsStructuralRepresentative))
     {
         foreach (PSMTreeIterator.NodeMarker nodeMarker in new[] { null, additionalNodeMarker })
         {
             PSMElement representedClassSignificantAncestor         = PSMTreeIterator.GetSignificantAncestorOrSelf(sr.RepresentedPSMClass, nodeMarker);
             PSMElement structuralRepresentativeSignificantAncestor = PSMTreeIterator.GetSignificantAncestorOrSelf(sr, nodeMarker);
             if (redNodes.Contains(representedClassSignificantAncestor))
             {
                 redNodes.AddIfNotContained(structuralRepresentativeSignificantAncestor);
                 blueNodes.Remove(structuralRepresentativeSignificantAncestor);
                 greenNodes.Remove(structuralRepresentativeSignificantAncestor);
                 MakeAncestorsBlue(structuralRepresentativeSignificantAncestor, nodeMarker);
             }
             else if (blueNodes.Contains(representedClassSignificantAncestor) && !redNodes.Contains(structuralRepresentativeSignificantAncestor))
             {
                 blueNodes.AddIfNotContained(structuralRepresentativeSignificantAncestor);
                 greenNodes.Remove(structuralRepresentativeSignificantAncestor);
                 MakeAncestorsBlue(structuralRepresentativeSignificantAncestor, nodeMarker);
             }
         }
     }
 }
Пример #3
0
        private PSMElement groupingFuncBySignificantNode(EvolutionChange change)
        {
            PSMElement target = (change is ISubelementChange) ? ((ISubelementChange)change).ChangedSubelement : change.Element;

            if (target.ModelsElement())
            {
                return(target);
            }
            else
            {
                return(PSMTreeIterator.GetSignificantAncestorOrSelf(target, IsContentGroupNode));
            }
        }
Пример #4
0
        private Dictionary <PSMElement, List <EvolutionChange> > GroupByTargetSignificantNode()
        {
            Dictionary <PSMElement, List <EvolutionChange> > groupChanges = GroupChanges(groupingFuncBySignificantNode);

            foreach (EvolutionChange change in this)
            {
                List <PSMElement> secondaryTargets = new List <PSMElement>();
                if (change is IDoubleTargetChange)
                {
                    secondaryTargets.Add(((IDoubleTargetChange)change).SecondaryTarget);
                }
                else if (change is ISubelementChange)
                {
                    secondaryTargets.Add(change.Element);
                }


                foreach (PSMElement secondaryTarget in secondaryTargets)
                {
                    if (secondaryTarget == null)
                    {
                        continue;
                    }

                    PSMElement secondaryTargetNV = (PSMElement)secondaryTarget.GetInVersion(change.NewVersion);

                    if (secondaryTargetNV != null)
                    {
                        if (secondaryTargetNV.ModelsElement())
                        {
                            //secondaryTarget = secondaryTarget;
                        }
                        else
                        {
                            secondaryTargetNV = PSMTreeIterator.GetSignificantAncestorOrSelf(secondaryTargetNV, IsContentGroupNode);
                        }

                        if (secondaryTargetNV != null)
                        {
                            if (!groupChanges.ContainsKey(secondaryTargetNV))
                            {
                                groupChanges[secondaryTargetNV] = new List <EvolutionChange>();
                            }
                            if (!groupChanges[secondaryTargetNV].Contains(change))
                            {
                                groupChanges[secondaryTargetNV].Add(change);
                            }
                        }
                    }
                }
            }

            foreach (KeyValuePair <PSMElement, List <EvolutionChange> > kvp in groupChanges.ToDictionary(pair => pair.Key, pair => pair.Value))
            {
                PSMElement             target     = kvp.Key;
                List <EvolutionChange> changeList = kvp.Value;

                if (IsContentGroupNode(target))
                {
                    PSMElement groupParent = PSMTreeIterator.GetSignificantAncestorOrSelf(target);
                    if (groupParent == null)
                    {
                        groupParent = target;
                    }
                    if (!groupChanges.ContainsKey(groupParent))
                    {
                        groupChanges[groupParent] = new List <EvolutionChange>();
                    }
                    foreach (EvolutionChange change in changeList)
                    {
                        if (!groupChanges[groupParent].Contains(change))
                        {
                            groupChanges[groupParent].Add(change);
                        }
                    }
                }
            }

            return(groupChanges);
        }
Пример #5
0
        /// <summary>
        /// Performs <see cref="GroupAwareProjectXPath"/> and substitutes steps in the result path according
        /// to structural representative information. (So the path is relative to the structural representative)
        /// </summary>
        /// <param name="context">The generator context.</param>
        /// <param name="element">The element.</param>
        /// <param name="structuralRepresentativeReplacement">The structural representative replacement.</param>
        /// <returns></returns>
        public static XPathExpr GroupAwareProjectXPathWithSRSubstitution(XsltGeneratorContext context, PSMElement element, IFromStructuralRepresentative structuralRepresentativeReplacement)
        {
            XPathExpr expr;

            if (structuralRepresentativeReplacement != null)
            {
                var cp = context.ProcessedPath;

                //if (PSMTreeIterator.AreInTheSamePSMTree(structuralRepresentativeReplacement.RepresentedPSMClass, structuralRepresentativeReplacement.StructuralRepresentative))


                PSMElement representedOldAnc = PSMTreeIterator.GetSignificantAncestorOrSelf((PSMClass)structuralRepresentativeReplacement.RepresentedPSMClass.GetInVersion(context.ChangeSet.OldVersion));
                PSMElement structuralRepresentativeOldAnc = PSMTreeIterator.GetSignificantAncestorOrSelf((PSMClass)structuralRepresentativeReplacement.StructuralRepresentative.GetInVersion(context.ChangeSet.OldVersion));

                if (representedOldAnc != null)
                {
                    context.ProcessedPath = GetXPathForNode(representedOldAnc, context.ChangeSet.OldVersion);
                }
                else
                {
                    context.ProcessedPath = new XPathExpr("<virt-root>");
                    if (context.InGroup)
                    {
                        context.ProcessedPath = context.ProcessedPath.Append("/$cg");
                    }
                }

                string from = representedOldAnc != null?XsltTemplateNameManager.GetElementNameForSignificantElement(representedOldAnc) : null;

                string to = structuralRepresentativeOldAnc != null?XsltTemplateNameManager.GetElementNameForSignificantElement(structuralRepresentativeOldAnc) : null;

                XPathExpr e = null;

                if (from != null && to != null &&
                    !(context.ProcessedPath.ToString().EndsWith(from) && cp.ToString().EndsWith(to)))
                {
                    e = ProjectXPath(cp, context.ProcessedPath, false);
                    if (!XPathExpr.IsNullOrEmpty(e) && !String.IsNullOrEmpty(to) && !String.IsNullOrEmpty(from))
                    {
                        if (e.ToString().Contains(from))
                        {
                            e = new XPathExpr(e.ToString().Replace(from, to));
                        }
                    }
                }
                expr = GroupAwareProjectXPath(context, element, context.ChangeSet.OldVersion);

                if (!XPathExpr.IsNullOrEmpty(e))
                {
                    // ReSharper disable PossibleNullReferenceException
                    expr = e.Append("/" + expr);
                }
                // ReSharper restore PossibleNullReferenceException

                context.ProcessedPath = cp;
            }
            else
            {
                expr = GroupAwareProjectXPath(context, element, context.ChangeSet.OldVersion);
            }

            return(expr);
        }