예제 #1
0
        public static void Run(DTE dte, VsError selectedError)
        {
            selectedError.Navigate();
            EditPoint2 ep = ErrorUtilities.GetEditPoint(dte);

            ep.LineDown();
            ep.StartOfLine();
            ep.InsertNewLine();
        }
예제 #2
0
        public static void GeneratePropertyFromVariable(CodeVariable2 variable, bool generateGetter, bool generateSetter, bool generateComments)
        {
            CodeClass2    codeClass     = variable.Collection.Parent as CodeClass2;
            CodeGenerator codeGenerator = CreateCodeGenerator(codeClass.Language);

            string propertyName = ConvertVariableNameToPropertyName(variable.Name);

            if (!ContainsMember(codeClass, propertyName))
            {
                string getterName = String.Empty;
                string setterName = String.Empty;

                if (generateGetter)
                {
                    getterName = propertyName;
                }
                if (generateSetter)
                {
                    setterName = propertyName;
                }

                CodeProperty property = (CodeProperty)codeClass.AddProperty(getterName, setterName, variable.Type, -1, vsCMAccess.vsCMAccessPublic, null);
                if (generateComments)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("<doc>");
                    sb.AppendLine("<summary>");
                    sb.AppendLine();
                    sb.AppendLine("</summary>");
                    sb.Append("</doc>");

                    property.DocComment = sb.ToString();
                }

                if (generateGetter)
                {
                    EditPoint2 editPoint = (EditPoint2)property.Getter.GetStartPoint(vsCMPart.vsCMPartBody).CreateEditPoint();
                    editPoint.EndOfLine();
                    int position = editPoint.LineCharOffset;
                    editPoint.StartOfLine();
                    editPoint.Delete(position);
                    editPoint.Insert(codeGenerator.GenerateReturnStatement(variable.Name));
                    editPoint.SmartFormat(editPoint);
                }

                if (generateSetter)
                {
                    EditPoint2 editPoint = (EditPoint2)property.Setter.GetStartPoint(vsCMPart.vsCMPartBody).CreateEditPoint();
                    editPoint.Insert(codeGenerator.GenerateAssignStatement(variable.Name, "value"));
                    editPoint.SmartFormat(editPoint);
                }
            }
        }
예제 #3
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);
        }
예제 #4
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);
        }
예제 #5
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);
            }
        }
        protected bool makeSemicolon(TextSelection textSelection)
        {
            EditPoint2 epend   = textSelection.ActivePoint.CreateEditPoint() as EditPoint2;
            EditPoint2 epbegin = textSelection.ActivePoint.CreateEditPoint() as EditPoint2;

            epbegin.StartOfLine();

            String strOrgText = epbegin.GetText(epend);

            // Check for bracket pair
            int bOpen  = 0;
            int bClose = 0;

            foreach (char c in strOrgText.Trim())
            {
                if (c == '}')
                {
                    ++bClose;
                }
                if (c == '{')
                {
                    ++bOpen;
                }
            }

            if (bClose != bOpen)
            {
                m_logger.Log(String.Format("{0}: CodeBeautifier encounter error while parsing line ( bracket not equal ).", m_appOptions.name));
                return(false);
            }

            String strNewText = getLeadingWhiteSpace(strOrgText) + makeText(strOrgText, textSelection.Parent.Parent.FullName);

            if (String.IsNullOrEmpty(strOrgText) || String.IsNullOrEmpty(strNewText))
            {
                m_logger.Log(String.Format("{0}: CodeBeautifier encounter error while parsing document.", m_appOptions.name));
                return(false);
            }

            if (strNewText.Equals(strOrgText))
            {
                m_logger.Log(String.Format("{0}: No changes after document format.", m_appOptions.name), OptionsGeneral.LoggerPriority.Medium);
                return(true);
            }

            epbegin.ReplaceText(epend, strNewText, (int)(vsEPReplaceTextOptions.vsEPReplaceTextKeepMarkers | vsEPReplaceTextOptions.vsEPReplaceTextNormalizeNewlines));

            return(false);
        }
예제 #7
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
        }
예제 #8
0
        protected bool makeBracketClose(TextSelection textSelection)
        {
            EditPoint2 epend   = textSelection.ActivePoint.CreateEditPoint() as EditPoint2;
            EditPoint2 epbegin = textSelection.ActivePoint.CreateEditPoint() as EditPoint2;

            String bracketOpen;
            int    otherbracket = 0;

            do
            {
                EditPoint2 last = epbegin.CreateEditPoint() as EditPoint2;
                epbegin.CharLeft();
                bracketOpen = epbegin.GetText(last);

                if (bracketOpen.CompareTo("}") == 0)
                {
                    ++otherbracket;
                }
                if (bracketOpen.CompareTo("{") == 0)
                {
                    --otherbracket;
                }

                if (epbegin.AtStartOfDocument &&
                    (bracketOpen.CompareTo("{") != 0 || otherbracket != 0))
                {
                    return(false);
                }
            } while(bracketOpen.CompareTo("{") != 0 || otherbracket != 0);

            epbegin.StartOfLine();

            String strOrgText = epbegin.GetText(epend);
            String strNewText = makeText(strOrgText, textSelection.Parent.Parent.FullName);

            if (String.IsNullOrEmpty(strOrgText) || String.IsNullOrEmpty(strNewText))
            {
                m_logger.Log(String.Format("{0}: CodeBeautifier encounter error while parsing document.", m_appOptions.name));
                return(false);
            }

            // Insert leading white space to each line
            String strNewIdentText   = String.Empty;
            String leadingWhiteSpace = getLeadingWhiteSpace(strOrgText);

            using (StringReader reader = new StringReader(strNewText))
            {
                string line = reader.ReadLine();
                do
                {
                    strNewIdentText += leadingWhiteSpace + line;

                    line = reader.ReadLine();
                    if (line != null)
                    {
                        strNewIdentText += Environment.NewLine;
                    }
                } while(line != null);
            }

            if (strNewIdentText.Equals(strOrgText))
            {
                m_logger.Log(String.Format("{0}: No changes after document format.", m_appOptions.name), OptionsGeneral.LoggerPriority.Medium);
                return(true);
            }

            epbegin.ReplaceText(epend, strNewIdentText, (int)(vsEPReplaceTextOptions.vsEPReplaceTextKeepMarkers | vsEPReplaceTextOptions.vsEPReplaceTextNormalizeNewlines));

            return(true);
        }