Esempio 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.
        }
Esempio 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);
            }
        }
Esempio n. 3
0
        public static void Run(DTE dte, VsError selectedError)
        {
            selectedError.Navigate();
            var ep = ErrorUtilities.GetEditPoint(dte);

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

            ep.LineDown();
            ep.StartOfLine();
            ep.InsertNewLine();
        }
Esempio 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);
        }
Esempio 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();
            }
        }
Esempio n. 7
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);
        }
Esempio n. 8
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);
            }
        }
Esempio 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);
        }
Esempio 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);
        }
Esempio n. 11
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);
            }
        }
Esempio n. 12
0
 /// <summary>
 /// Attempt to fix the error via regular expression updates
 /// </summary>
 /// <param name="dte">Design time environment the update is taking place in</param>
 /// <param name="selectedError">The error that we are trying to fix</param>
 public static void Run(DTE dte, VsError selectedError)
 {
     ErrorUtilities.RegExUpdateWholeDocument(@"(\s+)[System\.]*Array(\s+)", "$1array$2", selectedError, dte);
     ErrorUtilities.RegExUpdateWholeDocument(@"(\s+)[System\.]*Boolean(\s+)", "$1bool$2", selectedError, dte);
     ErrorUtilities.RegExUpdateWholeDocument(@"(\s+)[System\.]*Byte(\s+)", "$1byte$2", selectedError, dte);
     ErrorUtilities.RegExUpdateWholeDocument(@"(\s+)[System\.]*Char(\s+)", "$1char$2", selectedError, dte);
     ErrorUtilities.RegExUpdateWholeDocument(@"(\s+)[System\.]*Decimal(\s+)", "$1decimal$2", selectedError, dte);
     ErrorUtilities.RegExUpdateWholeDocument(@"(\s+)[System\.]*Double(\s+)", "$1double$2", selectedError, dte);
     ErrorUtilities.RegExUpdateWholeDocument(@"(\s+)[System\.]*Int16(\s+)", "$1short$2", selectedError, dte);
     ErrorUtilities.RegExUpdateWholeDocument(@"(\s+)[System\.]*Int32(\s+)", "$1int$2", selectedError, dte);
     ErrorUtilities.RegExUpdateWholeDocument(@"(\s+)[System\.]*Int64(\s+)", "$1long$2", selectedError, dte);
     ErrorUtilities.RegExUpdateWholeDocument(@"(\s+)[System\.]*Object(\s+)", "$1object$2", selectedError, dte);
     ErrorUtilities.RegExUpdateWholeDocument(@"(\s+)[System\.]*SByte(\s+)", "$1sbyte$2", selectedError, dte);
     ErrorUtilities.RegExUpdateWholeDocument(@"(\s+)[System\.]*Single(\s+)", "$1single$2", selectedError, dte);
     ErrorUtilities.RegExUpdateWholeDocument(@"(\s+)[System\.]*UInt16(\s+)", "$1ushort$2", selectedError, dte);
     ErrorUtilities.RegExUpdateWholeDocument(@"(\s+)[System\.]*UInt32(\s+)", "$1uint$2", selectedError, dte);
     ErrorUtilities.RegExUpdateWholeDocument(@"(\s+)[System\.]*UInt64(\s+)", "$1ulong$2", selectedError, dte);
     ErrorUtilities.RegExUpdateWholeDocument(@"(\s+)[System\.]*String(\s+)", "$1string$2", selectedError, dte);
 }
Esempio n. 13
0
        public static void Run(DTE dte, VsError selectedError)
        {
            // SA1000: The spacing around the keyword 'fixed' is invalid.
            string keyword = selectedError.Description.Split(' ')[9].Replace("'", string.Empty);

            if (SpaceKeywords.Contains(keyword))
            {
                ErrorUtilities.RegExUpdate(@"(" + keyword + @")([^\w\s])", @"$1 $2", selectedError, dte);
            }
            else if (NonSpaceKeywords.Contains(keyword))
            {
                ErrorUtilities.RegExUpdate(@"(" + keyword + @")\s+([^\w\s])", @"$1$2", selectedError, dte);
            }
            else if (keyword == "new")
            {
                ErrorUtilities.RegExUpdate(@"(" + keyword + @")([^\w\s\[])", @"$1 $2", selectedError, dte);
                ErrorUtilities.RegExUpdate(@"(" + keyword + @")\s+(\[)", @"$1$2", selectedError, dte);
            }
        }
Esempio n. 14
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();
        }
Esempio 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
        }
Esempio n. 16
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));
        }
Esempio n. 17
0
 public static void Run(DTE dte, VsError selectedError)
 {
     ErrorUtilities.RegExUpdate(@"(?<=\w)=(?=\w)", " = ", selectedError, dte);
 }
Esempio n. 18
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);
        }
Esempio n. 19
0
 public static void Run(DTE dte, VsError selectedError)
 {
     ErrorUtilities.RegExUpdate(@"\{(?=\S)", @"{ ", selectedError, dte);
 }
Esempio n. 20
0
 public static void Run(DTE dte, VsError selectedItem)
 {
     selectedItem.Navigate();
     ErrorUtilities.RegExUpdateWholeDocument(@"^(\s*\t*\r\n\s*\t*){1,}$", string.Empty, selectedItem, dte);
 }
Esempio n. 21
0
 public static void Run(DTE environment, VsError selectedError)
 {
     selectedError.Navigate();
     // TODO: verify this works
     ErrorUtilities.RegExUpdate(@"(?<=\})\s*;", string.Empty, selectedError, environment);
 }
Esempio n. 22
0
 public static void Run(DTE dte, VsError selectedError)
 {
     selectedError.Navigate();
     dte.ExecuteCommand("Edit.SortUsings");
 }
Esempio n. 23
0
 /// <summary>
 /// Attempt to fix the error via regular expression updates
 /// </summary>
 /// <param name="dte">Design time environment the update is taking place in</param>
 /// <param name="selectedError">The error that we are trying to fix</param>
 public static void Run(DTE dte, VsError selectedError)
 {
     ErrorUtilities.RegExUpdateWholeDocument(@"""", "string.Empty", selectedError, dte);
 }
Esempio n. 24
0
 public static void Run(DTE dte, VsError selectedError)
 {
     ErrorUtilities.RegExUpdate(@"\s{2,}", @" ", selectedError, dte);
 }
Esempio n. 25
0
 public static void Run(DTE dte, VsError selectedError)
 {
     ErrorUtilities.RegExUpdate(@"(?<=\S)\}", @" }", selectedError, dte);
 }
Esempio n. 26
0
 public static void Run(DTE environment, VsError selectedError)
 {
     selectedError.Navigate();
     ErrorUtilities.RegExUpdateWholeDocument(@"\/\/([^\/\s])", "// $1", selectedError, environment);
 }