Exemplo n.º 1
0
        public static void Run(DTE environment, VsError selectedError)
        {
            if (selectedError == null)
            {
                throw new ArgumentNullException("selectedError", @"Selected error is null");
            }

            selectedError.Navigate();

            // Replace all items that have spaces before the ending brackets
            // "A closing parenthesis should never be preceded by whitespace."
            ErrorUtilities.RegExUpdateWholeDocument(@"\s+\)", ")", selectedError, environment);

            // "If the closing parenthesis is followed by whitespace, the next non-whitespace character must not be an opening or closing parenthesis or square bracket,
            //  or a semicolon or comma."
            ErrorUtilities.RegExUpdateWholeDocument(@"\)\s+;", @");", selectedError, environment);
            ErrorUtilities.RegExUpdateWholeDocument(@"\)\s+,", @"),", selectedError, environment);
            ErrorUtilities.RegExUpdateWholeDocument(@"\)\s+\(", @")(", selectedError, environment);
            ErrorUtilities.RegExUpdateWholeDocument(@"\)\s+\)", @"))", selectedError, environment);
            ErrorUtilities.RegExUpdateWholeDocument(@"\)\s+\[", @")\[", selectedError, environment);
            ErrorUtilities.RegExUpdateWholeDocument(@"\)\s+\]", @")\]", selectedError, environment);

            // replace all items that have a cariage return between each line
            ErrorUtilities.RegExUpdateWholeDocument(@"(\s+[a-zA-Z]+\))\s*\r\n(\).*)", "$1$2", selectedError, environment);

            // In most cases, a closing parenthesis should be followed by a single space, unless the closing parenthesis comes at the end of a cast,
            // or the closing parenthesis is followed by certain types of operator symbols, such as positive signs, negative signs, and colons.
        }
Exemplo n.º 2
0
        public static void Run(DTE dte, VsError selectedError)
        {
            var logger = new ConsoleLogger {
                Trace = true
            };

            Console.WriteLine();
            Console.WriteLine(new string('_', 60));

            selectedError.Navigate();
            string formatString = Properties.StyleRepair.Default.NArrangeUseRegions
                                      ? @"{0}\NArrangeConfigWithRegions.xml"
                                      : @"{0}\NArrangeConfig.xml";

            var fileArranger = new FileArranger(
                string.Format(formatString, Path.GetDirectoryName(Assembly.GetCallingAssembly().Location)),
                Logger.Instance);

            bool success = fileArranger.Arrange(dte.ActiveDocument.FullName, dte.ActiveDocument.FullName, true);

            if (!success)
            {
                logger.LogMessage(LogLevel.Error, "Unable to NArrange {0}.", dte.ActiveDocument.FullName);
            }
        }
Exemplo n.º 3
0
        public static void Run(DTE dte, VsError selectedError)
        {
            selectedError.Navigate();
            var ep = ErrorUtilities.GetEditPoint(dte);

            ep.LineDown();
            ep.Delete(1);
        }
Exemplo n.º 4
0
        public static void Run(DTE dte, VsError selectedError)
        {
            selectedError.Navigate();
            EditPoint2 ep = ErrorUtilities.GetEditPoint(dte);

            ep.LineDown();
            ep.StartOfLine();
            ep.InsertNewLine();
        }
Exemplo n.º 5
0
        public static void Run(DTE dte, VsError selectedError)
        {
            selectedError.Navigate();

            /*
             * A violation of this rule occurs when the preprocessor-type keyword in a preprocessor directive is preceded by space
             */
            ErrorUtilities.RegExUpdateWholeDocument(@"#[^\S\n]+(\w)", "#$1", selectedError, dte);
        }
Exemplo n.º 6
0
        public static void Run(DTE dte, VsError selectedError)
        {
            selectedError.Navigate();
            var ep = ErrorUtilities.GetEditPoint(dte);

            ep.LineUp();
            while (ep.LineLength == 0)
            {
                ep.Delete(1);
                ep.LineUp();
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Fix error SA1600
        /// </summary>
        /// <param name="dte">Current design environment</param>
        /// <param name="selectedError">Error selected by the user to fix.</param>
        public static void Run(DTE dte, VsError selectedError)
        {
            EditPoint2 ep = ErrorUtilities.GetEditPoint(dte);

            selectedError.Navigate();
            var selection       = (TextSelection)dte.ActiveDocument.Selection;
            var propertyElement = (CodeProperty)selection.ActivePoint.CodeElement[vsCMElement.vsCMElementProperty];

            if (propertyElement != null)
            {
                ProcessPropertyUpdate(propertyElement, ep);
            }
        }
Exemplo n.º 8
0
        public static void Run(DTE dte, VsError error)
        {
            error.Navigate();
            EditPoint2 ep = ErrorUtilities.GetEditPoint(dte);

            ep.StartOfLine();
            string variableName  = error.Description.Split(" ".ToCharArray())[7];
            string replaceString = ep.GetLines(ep.Line, ep.Line + 1);

            replaceString = Regex.Replace(replaceString, string.Format(@"(\s|\(|\!)({0})(\W)", variableName), "$1this.$2$3",
                                          RegexOptions.None);
            ep.ReplaceText(ep.LineLength, replaceString, (int )vsEPReplaceTextOptions.vsEPReplaceTextAutoformat);
        }
Exemplo n.º 9
0
        public static void Run(DTE dte, VsError selectedError)
        {
            selectedError.Navigate();

            /*
             * A violation of this rule occurs when the opening parenthesis within a statement is not spaced correctly.
             * An opening parenthesis should not be preceded by any whitespace, unless it is the first character on the line, or it is preceded
             * by certain C# keywords such as if, while, or for. In addition, an opening parenthesis is allowed to be preceded by whitespace when
             * it follows an operator symbol within an expression.
             *
             * An opening parenthesis should not be followed by whitespace, unless it is the last character on the line.
             */
            ErrorUtilities.RegExUpdateWholeDocument(@"\([^\S\n]+", "(", selectedError, dte);
        }
Exemplo n.º 10
0
        public static void RegExUpdate(string findPattern, string replacePattern, VsError selectedError, DTE dte)
        {
            selectedError.Navigate();
            EditPoint2 ep = GetEditPoint(dte);

            ep.StartOfLine();
            string textToUpdate = ep.GetLines(ep.Line, ep.Line + 1);

            textToUpdate = Regex.Replace(textToUpdate, findPattern, replacePattern);

            // Using the Autoformat option is cheating a little but saves on a lot of work.  It basically formats
            // the text as if you were typing it in the IDE
            ep.ReplaceText(ep.LineLength, textToUpdate, (int)vsEPReplaceTextOptions.vsEPReplaceTextAutoformat);
        }
Exemplo n.º 11
0
        public static void RegExUpdateWholeDocument(string findPattern, string replacePattern, VsError selectedError, DTE dte)
        {
            selectedError.Navigate();
            Document curDoc  = dte.ActiveDocument;
            var      textDoc = (TextDocument)curDoc.Object();

            textDoc.Selection.SelectAll();

            string allTheText    = textDoc.Selection.Text;
            string formattedText = Regex.Replace(allTheText, findPattern, replacePattern, RegexOptions.Multiline);

            textDoc.Selection.Cut();
            textDoc.Selection.Insert(formattedText);
        }
Exemplo n.º 12
0
        public static void Run(DTE dte, VsError selectedError)
        {
            selectedError.Navigate();
            EditPoint2 ep = ErrorUtilities.GetEditPoint(dte);

            ep.StartOfLine();
            string testString = ep.GetLines(ep.Line, ep.Line + 1);

            if (Regex.Match(testString, @"\t").Success)
            {
                testString = Regex.Replace(testString, @"\t", @"    ");
                ep.ReplaceText(ep.LineLength, testString, (int)vsEPReplaceTextOptions.vsEPReplaceTextAutoformat);
            }
        }
Exemplo n.º 13
0
        public static void Run(DTE dte, VsError selectedError)
        {
            selectedError.Navigate();

            Document      curDoc    = dte.ActiveDocument;
            var           textDoc   = (TextDocument)curDoc.Object();
            TextSelection selection = textDoc.Selection;

            // Use top point here to take care of collapsed definitions
            var ep = (EditPoint2)selection.TopPoint.CreateEditPoint();

            ep.StartOfLine();
            ep.LineUp();
            while (ep.GetText(ep.LineLength).Replace(" ", string.Empty).StartsWith("//") ||
                   ep.GetText(ep.LineLength).Replace(" ", string.Empty).StartsWith("["))
            {
                ep.LineUp();
            }

            ep.EndOfLine();
            ep.InsertNewLine();
        }
Exemplo n.º 14
0
        public static void Run(DTE dte, VsError selectedError)
        {
            selectedError.Navigate();
            EditPoint2 editPoint = ErrorUtilities.GetEditPoint(dte);

            editPoint.StartOfDocument();
            string fileName = selectedError.FileName.Substring(
                selectedError.FileName.LastIndexOf(@"\") + 1,
                selectedError.FileName.Length - (selectedError.FileName.LastIndexOf(@"\") + 1));

            editPoint.InsertNewLine();
            editPoint.StartOfDocument();
            editPoint.Insert(
                string.Format(
                    @"//-----------------------------------------------------------------------
// <copyright file=""{0}"" company=""{1}"">
//     {2}
// </copyright>
//-----------------------------------------------------------------------",
                    fileName,
                    StyleRepair.Properties.StyleRepair.Default.CompanyName,
                    StyleRepair.Properties.StyleRepair.Default.CopyrightMessage));
        }
Exemplo n.º 15
0
        public static void Run(DTE dte, VsError selectedError)
        {
            selectedError.Navigate();
            EditPoint2 ep = ErrorUtilities.GetEditPoint(dte);

            ep.StartOfLine();
            string editLine = ep.GetLines(ep.Line, ep.Line + 1);

            editLine = editLine.Replace(";", "");
            string varName = string.Empty;

            if (editLine.IndexOf("=") > -1)
            {
                varName = editLine.Split("=".ToCharArray()).First().Split(" ".ToCharArray()).Where(item => item.Length > 0).Last();
            }
            else
            {
                varName = editLine.Split(" ".ToCharArray()).Last();
            }
            ep.Parent.Selection.CharRight(Count: editLine.IndexOf(varName));
            dte.ExecuteCommand("Refactor.Rename");
            //// todo
        }
Exemplo n.º 16
0
 public static void Run(DTE environment, VsError selectedError)
 {
     selectedError.Navigate();
     ErrorUtilities.RegExUpdateWholeDocument(@"\/\/([^\/\s])", "// $1", selectedError, environment);
 }
Exemplo n.º 17
0
 public static void Run(DTE environment, VsError selectedError)
 {
     selectedError.Navigate();
     // TODO: verify this works
     ErrorUtilities.RegExUpdate(@"(?<=\})\s*;", string.Empty, selectedError, environment);
 }
Exemplo n.º 18
0
 public static void Run(DTE dte, VsError selectedError)
 {
     selectedError.Navigate();
     dte.ExecuteCommand("Edit.SortUsings");
 }
Exemplo n.º 19
0
 public static void Run(DTE dte, VsError selectedItem)
 {
     selectedItem.Navigate();
     ErrorUtilities.RegExUpdateWholeDocument(@"^(\s*\t*\r\n\s*\t*){1,}$", string.Empty, selectedItem, dte);
 }