Beispiel #1
0
        /// <summary>
        ///     Refactors a single element
        /// </summary>
        /// <param name="element"></param>
        /// <param name="originalName">The original element's name</param>
        /// <param name="newName">The new element's name</param>
        private void RefactorElement(ModelElement element, string originalName, string newName)
        {
            if (element != null)
            {
                NameSpace nameSpace = element as NameSpace;
                if (nameSpace != null)
                {
                    NameSpaceRefactorer refactorer = new NameSpaceRefactorer(nameSpace);
                    foreach (Dictionary dictionary in EfsSystem.Instance.Dictionaries)
                    {
                        refactorer.visit(dictionary);
                    }
                }
                else
                {
                    // the system keeps track where the element is used
                    List <Usage>      usageList = EfsSystem.Instance.FindReferences(element);
                    SortedSet <Usage> usages    = new SortedSet <Usage>(usageList, new CompareUsages());
                    foreach (Usage usage in usages)
                    {
                        RefactorIExpressionable(element, usage.User as IExpressionable);
                        RefactorTypedElement(element, usage.User as ITypedElement);
                    }

                    if (element is StructureElement)
                    {
                        Structure structure = element.Enclosing as Structure;
                        if (structure != null && structure.IsAbstract)
                        {
                            usages = new SortedSet <Usage>(EfsSystem.Instance.FindReferences(structure));
                            foreach (Usage usage in usages)
                            {
                                if (usage.Mode == Usage.ModeEnum.Interface)
                                {
                                    Structure redefiningStructure = usage.User as Structure;
                                    if (redefiningStructure != null)
                                    {
                                        ModelElement el = redefiningStructure.FindStructureElement(originalName);
                                        if (el != null)
                                        {
                                            el.Name = newName;
                                            RefactorElement(el, originalName, newName);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        ///     Refactors a single element
        /// </summary>
        /// <param name="element"></param>
        /// <param name="originalName">The original element's name</param>
        /// <param name="newName">The new element's name</param>
        private void RefactorElement(ModelElement element, string originalName, string newName)
        {
            if (element != null)
            {
                NameSpace nameSpace = element as NameSpace;
                if (nameSpace != null)
                {
                    NameSpaceRefactorer refactorer = new NameSpaceRefactorer(nameSpace);
                    foreach (Dictionary dictionary in EfsSystem.Instance.Dictionaries)
                    {
                        refactorer.visit(dictionary);
                    }
                }
                else
                {
                    // the system keeps track where the element is used
                    List<Usage> usages = EfsSystem.Instance.FindReferences(element);
                    foreach (Usage usage in usages)
                    {
                        RefactorIExpressionable(element, usage.User as IExpressionable);
                        RefactorTypedElement(element, usage.User as ITypedElement);
                    }

                    if (element is StructureElement)
                    {
                        Structure structure = element.Enclosing as Structure;
                        if (structure != null && structure.IsAbstract)
                        {
                            usages = EfsSystem.Instance.FindReferences(structure);
                            foreach (Usage usage in usages)
                            {
                                if (usage.Mode == Usage.ModeEnum.Interface)
                                {
                                    Structure redefiningStructure = usage.User as Structure;
                                    if (redefiningStructure != null)
                                    {
                                        ModelElement el = redefiningStructure.FindStructureElement(originalName);
                                        if (el != null)
                                        {
                                            el.Name = newName;
                                            RefactorElement(el, originalName, newName);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }