Ejemplo n.º 1
0
        private void CalculateCode(ParentingStatement parentingStatement)
        {
            _NewCode = null;
            if (parentingStatement == null)
                return;

            LanguageElement parentToReplace = null;
            ParentToSingleStatement grandparent = parentingStatement.Parent as ParentToSingleStatement;
            if (grandparent != null)
            {
                if (!grandparent.HasBlock)
                {
                    ElementCloneOptions cloneOptions = new ElementCloneOptions() { CloneNodes = false };
                    parentToReplace = grandparent.Clone(cloneOptions) as LanguageElement;
                }
            }
            LanguageElement endNode;
            LanguageElement startNode;
            parentingStatement.GetFullBlockNodes(out startNode, out endNode);
            LanguageElement elementToCheck = startNode;
            ElementBuilder elementBuilder = new ElementBuilder();
            if (parentToReplace != null)
                elementBuilder.AddNode(null, parentToReplace);

            while (elementToCheck != null)
            {
                ParentingStatement parent = elementToCheck as ParentingStatement;
                if (parent != null && parent.ElementType != LanguageElementType.Catch)
                {
                    foreach (IElement element in parent.Nodes)
                    {
                        LanguageElement child = element.Clone() as LanguageElement;
                        if (child != null)
                            elementBuilder.AddNode(parentToReplace, child);
                    }
                }
                if (elementToCheck == endNode)
                    break;

                elementToCheck = elementToCheck.NextCodeSibling;
            }

            if (parentToReplace != null)
                _DeleteRange = parentToReplace.Range;
            else
                _DeleteRange = new SourceRange(startNode.Range.Top, endNode.Range.Bottom);

            _NewCode = elementBuilder.GenerateCode();

            if (_NewCode.EndsWith(Environment.NewLine))
                _NewCode = _NewCode.Remove(_NewCode.Length - Environment.NewLine.Length);
        }
        private void cpRemoveOuterBlock_CheckAvailability(object sender, CheckContentAvailabilityEventArgs ea)
        {
            ParentingStatement parentingStatement = ea.Element as ParentingStatement;

            if (parentingStatement == null)
            {
                return;
            }
            if (parentingStatement.ElementType == LanguageElementType.Switch)
            {
                return;
            }
            ea.Available = true;
        }
        private void CalculateCode(ParentingStatement parentingStatement)
        {
            _NewCode = null;
            if (parentingStatement == null)
            {
                return;
            }

            LanguageElement         parentToReplace = null;
            ParentToSingleStatement grandparent     = parentingStatement.Parent as ParentToSingleStatement;

            if (grandparent != null)
            {
                if (!grandparent.HasBlock)
                {
                    ElementCloneOptions cloneOptions = new ElementCloneOptions()
                    {
                        CloneNodes = false
                    };
                    parentToReplace = grandparent.Clone(cloneOptions) as LanguageElement;
                }
            }
            LanguageElement endNode;
            LanguageElement startNode;

            parentingStatement.GetFullBlockNodes(out startNode, out endNode);
            LanguageElement elementToCheck = startNode;
            ElementBuilder  elementBuilder = new ElementBuilder();

            if (parentToReplace != null)
            {
                elementBuilder.AddNode(null, parentToReplace);
            }

            while (elementToCheck != null)
            {
                ParentingStatement parent = elementToCheck as ParentingStatement;
                if (parent != null && parent.ElementType != LanguageElementType.Catch)
                {
                    foreach (IElement element in parent.Nodes)
                    {
                        LanguageElement child = element.Clone() as LanguageElement;
                        if (child != null)
                        {
                            elementBuilder.AddNode(parentToReplace, child);
                        }
                    }
                }
                if (elementToCheck == endNode)
                {
                    break;
                }

                elementToCheck = elementToCheck.NextCodeSibling;
            }

            if (parentToReplace != null)
            {
                _DeleteRange = parentToReplace.Range;
            }
            else
            {
                _DeleteRange = new SourceRange(startNode.Range.Top, endNode.Range.Bottom);
            }

            _NewCode = elementBuilder.GenerateCode();

            if (_NewCode.EndsWith(Environment.NewLine))
            {
                _NewCode = _NewCode.Remove(_NewCode.Length - Environment.NewLine.Length);
            }
        }