protected override Action <JetBrains.TextControl.ITextControl> ExecutePsiTransaction(JetBrains.ProjectModel.ISolution solution, JetBrains.Application.Progress.IProgressIndicator progress)
        {
            if (!Highlighting.IsValid())
            {
                return(null);
            }

            var node             = Highlighting.Node;
            var badWordTextRange = Highlighting.Range.TextRange;

            var newText = StringUtil.ReplaceSection(
                node.GetText(),
                Suggestion,
                badWordTextRange.StartOffset - node.GetDocumentRange().TextRange.StartOffset,
                badWordTextRange.Length
                );

            if (node is TreeElement)
            {
                var elementFactory = HtmlElementFactory.GetInstance(node.Language);
                var newElements    = elementFactory.CompileText(newText, node).ToList();
                if (newElements.Count > 0)
                {
                    var recentNode = ModificationUtil.ReplaceChild(node, newElements[0]);
                    for (int i = 1; i < newElements.Count; i++)
                    {
                        recentNode = ModificationUtil.AddChildAfter(recentNode.Parent, recentNode, newElements[i]);
                    }
                }
                return(null);
            }
            return(null);
        }
Esempio n. 2
0
        protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
        {
            if (!Highlighting.IsValid())
            {
                return(null);
            }

            var node             = Highlighting.Node;
            var badWordTextRange = Highlighting.Range.TextRange;

            var newText = StringUtil.ReplaceSection(
                node.GetText(),
                Suggestion,
                badWordTextRange.StartOffset - node.GetDocumentRange().TextRange.StartOffset,
                badWordTextRange.Length
                );

            if (node is XmlValueToken)
            {
                var newElm = new XmlValueToken(
                    (node as XmlValueToken).GetTokenType(),
                    new StringBuffer(newText),
                    new TreeOffset(0),
                    new TreeOffset(newText.Length)
                    );
                ModificationUtil.ReplaceChild(node, newElm);
                return(null);
            }
            if (node is XmlFloatingTextToken)
            {
                var newElm = new XmlFloatingTextToken(
                    (node as XmlFloatingTextToken).GetTokenType(),
                    newText
                    );
                ModificationUtil.ReplaceChild(node, newElm);
                return(null);
            }
            if (node is XmlToken)
            {
                var newElm = new XmlToken(
                    (node as XmlToken).GetTokenType(),
                    new StringBuffer(newText),
                    new TreeOffset(0),
                    new TreeOffset(newText.Length)
                    );
                ModificationUtil.ReplaceChild(node, newElm);
                return(null);
            }
            return(null);
        }
        protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
        {
            if (!Highlighting.IsValid())
            {
                return(null);
            }

            var node             = Highlighting.Node;
            var badWordTextRange = Highlighting.Range.TextRange;

            var newText = StringUtil.ReplaceSection(
                node.GetText(),
                Suggestion,
                badWordTextRange.StartOffset - node.GetDocumentRange().TextRange.StartOffset,
                badWordTextRange.Length
                );

            if (node is IIdentifier)
            {
                return(textControl => {
                    var declaredIdentifier = TextControlToPsi.GetDeclaredElements(solution, textControl)
                                             .FirstOrDefault();
                    solution.GetComponent <RenameRefactoringExecutor>().Execute(declaredIdentifier, textControl, newText);
                });
            }
            if (node is IComment)
            {
                var newElement = CreateNode(node, newText);
                ModificationUtil.ReplaceChild(node, newElement);
                return(null);
            }
            if (JavaScriptUtil.IsStringLiteral(node))
            {
                var newElement = CreateNode(node, newText);
                ModificationUtil.ReplaceChild(node, newElement);
                return(null);
            }
            return(null);
        }