/// <summary>
        /// Performs the QuickFix, ensures the file is both writable and creates a transaction.
        /// </summary>
        /// <param name="solution">
        /// Current Solution.
        /// </param>
        /// <param name="progress">
        /// Progress Indicator for the fix.
        /// </param>
        /// <returns>
        /// The execute transaction.
        /// </returns>
        protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, JetBrains.Application.Progress.IProgressIndicator progress)
        {
            return(delegate(ITextControl textControl)
            {
                solution.GetComponent <DocumentManagerOperations>().SaveAllDocuments();

                using (solution.GetComponent <DocumentTransactionManager>().CreateTransactionCookie(JetBrains.Util.DefaultAction.Commit, "action name"))
                {
                    var services = solution.GetPsiServices();
                    services.Transactions.Execute(
                        "Code cleanup",
                        () => services.Locks.ExecuteWithWriteLock(() => { ExecuteTransactionInner(solution, textControl); }));
                }
            });
        }
        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);
        }
        /// <summary>
        /// Process clean-up on file.
        /// </summary>
        /// <param name="projectFile">
        /// The project file to process.
        /// </param>
        /// <param name="rangeMarker">
        /// The range marker to process.
        /// </param>
        /// <param name="profile">
        /// The code cleanup settings to use.
        /// </param>
        /// <param name="progressIndicator">
        /// The progress indicator.
        /// </param>
        public void Process(
            IPsiSourceFile projectFile, IRangeMarker rangeMarker, CodeCleanupProfile profile, JetBrains.Application.Progress.IProgressIndicator progressIndicator)
        {
            if (!this.IsAvailable(projectFile))
            {
                return;
            }

            ISolution solution = projectFile.GetSolution();

            ICSharpFile file = projectFile.GetDominantPsiFile <CSharpLanguage>() as ICSharpFile;

            if (file == null)
            {
                return;
            }

            StyleCopCodeCleanupOptions options = profile.GetSetting(Descriptor);

            if (!options.FixViolations)
            {
                return;
            }

            var services = solution.GetPsiServices();

            services.Transactions.Execute("Code cleanup", () => this.InternalProcess(projectFile.ToProjectFile(), file, options.CreateXmlDocStubs));

            StyleCopTrace.Out();
        }
Example #4
0
 public void Save(JetBrains.Application.Progress.IProgressIndicator progress, bool enablePersistence)
 {
 }
Example #5
0
 public object Load(JetBrains.Application.Progress.IProgressIndicator progress, bool enablePersistence)
 {
     return(true);
 }
        /// <summary>
        /// Process clean-up on file.
        /// </summary>
        /// <param name="projectFile">
        /// The project file to process.
        /// </param>
        /// <param name="rangeMarker">
        /// The range marker to process.
        /// </param>
        /// <param name="profile">
        /// The code cleanup settings to use.
        /// </param>
        /// <param name="progressIndicator">
        /// The progress indicator.
        /// </param>
        public void Process(
            IPsiSourceFile projectFile, IRangeMarker rangeMarker, CodeCleanupProfile profile, JetBrains.Application.Progress.IProgressIndicator progressIndicator)
        {
            if (!this.IsAvailable(projectFile))
            {
                return;
            }

            ISolution solution = projectFile.GetSolution();

            ICSharpFile file = projectFile.GetDominantPsiFile <CSharpLanguage>() as ICSharpFile;

            if (file == null)
            {
                return;
            }


            if (!profile.GetSetting(FIX_VIOLATIONS))
            {
                return;
            }

            var services = solution.GetPsiServices();

            services.Transactions.Execute("Code cleanup", () => this.InternalProcess(projectFile.ToProjectFile(), file, profile.GetSetting(CREATE_XML_DOC_STUB)));

            StyleCopTrace.Out();
        }