public static string GenerateDiagnosticResourceData(CheckData check)
        {
            var sb = new StringBuilder();

            sb.AppendFormat(_diagnosticResourceDataTemplate,
                            check.Name,
                            check.Title,
                            check.Description);
            if (check.Messages != null && check.Messages.Count > 1)
            {
                foreach (var pair in check.Messages)
                {
                    sb.AppendFormat(_diagnosticResourceDataMessageTemplate,
                                    check.Name,
                                    pair.Key,
                                    pair.Value);
                }
            }
            else
            {
                // use title as message
                sb.AppendFormat(_diagnosticResourceDataMessageTemplate,
                                check.Name,
                                "",
                                check.Title);
            }
            return(sb.ToString());
        }
        public static string GenerateAnalyzer(string analyzer, CheckData check)
        {
            var messageBuilder         = new StringBuilder();
            var descriptorBuilder      = new StringBuilder();
            var descriptorNamesBuilder = new StringBuilder();
            var replaceme = analyzer.Replace(".", String.Empty);

            if (check.Messages != null && check.Messages.Count > 1)
            {
                int i = 0;
                foreach (var pair in check.Messages)
                {
                    // 0: MessageName
                    // 1: REPLACEME
                    // 2: Name
                    messageBuilder.AppendFormat(_messageTemplate, pair.Key, replaceme, check.Name);
                    // 0: MessageName
                    // 1: Category
                    descriptorBuilder.AppendFormat(_descriptorTemplate, pair.Key, check.Category);
                    descriptorNamesBuilder.Append(pair.Key + "Rule" + (i < check.Messages.Count - 1 ? ", " : ""));
                    ++i;
                }
            }
            else
            {
                messageBuilder.AppendFormat(_messageTemplate, "", replaceme, check.Name);
                descriptorBuilder.AppendFormat(_descriptorTemplate, "", check.Category);
                descriptorNamesBuilder.Append("Rule");
            }
            // 0: REPLACE.ME
            // 1: REPLACEME
            // 2: Name
            // 3: ID
            // 4: Category
            // 5: list of message strings
            // 6: list of descriptors
            // 7: list of descritor names
            // 8: Title
            return(string.Format(_analyzerTemplate,
                                 analyzer,
                                 replaceme,
                                 check.Name,
                                 check.Id,
                                 check.Category,
                                 messageBuilder.ToString(),
                                 descriptorBuilder.ToString(),
                                 descriptorNamesBuilder.ToString(),
                                 check.Title));
        }
 public static string GenerateBasicAnalyzerFileName(CheckData check)
 {
     return("Basic" + check.Name + ".vb");
 }
 public static string GenerateCSharpAnalyzerFileName(CheckData check)
 {
     return("CSharp" + check.Name + ".cs");
 }
 public static string GenerateCSharpAnalyzer(string analyzer, CheckData check)
 {
     return(string.Format(_csharpAnalyzerTemplate, analyzer, check.Name, check.Id, check.Title));
 }
        public static string GenerateAnalyzer(string analyzer, CheckData check)
        {
            var messageBuilder  = new StringBuilder();
            var descriptorBuilder = new StringBuilder();
            var descriptorNamesBuilder = new StringBuilder();
            var replaceme = analyzer.Replace(".", String.Empty);

            if (check.Messages != null && check.Messages.Count > 1)
            {
                int i = 0;
                foreach (var pair in check.Messages)
                {
                    // 0: MessageName
                    // 1: REPLACEME
                    // 2: Name
                    messageBuilder.AppendFormat(_messageTemplate, pair.Key, replaceme, check.Name);
                    // 0: MessageName
                    // 1: Category
                    descriptorBuilder.AppendFormat(_descriptorTemplate, pair.Key, check.Category);
                    descriptorNamesBuilder.Append(pair.Key + "Rule" + (i < check.Messages.Count - 1 ? ", " : ""));
                    ++i;
                }
            }
            else
            {
                messageBuilder.AppendFormat(_messageTemplate, "", replaceme, check.Name);
                descriptorBuilder.AppendFormat(_descriptorTemplate, "", check.Category);
                descriptorNamesBuilder.Append("Rule");
            }
            // 0: REPLACE.ME
            // 1: REPLACEME
            // 2: Name
            // 3: ID
            // 4: Category
            // 5: list of message strings
            // 6: list of descriptors
            // 7: list of descritor names
            // 8: Title
            return string.Format(_analyzerTemplate, 
                                 analyzer,
                                 replaceme,
                                 check.Name,
                                 check.Id,
                                 check.Category,
                                 messageBuilder.ToString(),
                                 descriptorBuilder.ToString(),
                                 descriptorNamesBuilder.ToString(),
                                 check.Title);
        }
 public static string GenerateCodeFixTests(string analyzer, CheckData check)
 {
     return(string.Format(_codeFixTestTemplate, analyzer, check.Name));
 }
 public static string GenerateBasicCodeFix(string analyzer, CheckData check)
 {
     return(string.Format(_basicCodeFixTemplate, analyzer, check.Name, check.Id, check.Title));
 }
 public static string GenerateBasicCodeFixFileName(CheckData check)
 {
     return "Basic" + check.Name + ".Fixer.vb";
 }
 public static string GenerateBasicCodeFix(string analyzer, CheckData check)
 {
     return string.Format(_basicCodeFixTemplate, analyzer, check.Name, check.Id, check.Title);
 }
 public static string GenerateCSharpCodeFixFileName(CheckData check)
 {
     return "CSharp" + check.Name + ".Fixer.cs";
 }
 public static string GenerateAnalyzerTestsFileName(CheckData check)
 {
     return check.Name + "Tests.cs";
 }
 public static string GenerateBasicAnalyzerFileName(CheckData check)
 {
     return "Basic" + check.Name + ".vb";
 }
 public static string GenerateCSharpAnalyzerFileName(CheckData check)
 {
     return "CSharp" + check.Name + ".cs";
 }
 public static string GenerateCSharpAnalyzer(string analyzer, CheckData check)
 {
     return string.Format(_csharpAnalyzerTemplate, analyzer, check.Name, check.Id, check.Title);
 }
示例#16
0
 public static string GenerateAnalyzerTestsFileName(CheckData check)
 {
     return(check.Name + "Tests.cs");
 }
示例#17
0
 public static string GenerateCSharpCodeFixFileName(CheckData check)
 {
     return("CSharp" + check.Name + ".Fixer.cs");
 }
 public static string GenerateCodeFixTests(string analyzer, CheckData check)
 {
     return string.Format(_codeFixTestTemplate, analyzer, check.Name);
 }
示例#19
0
 public static string GenerateBasicCodeFixFileName(CheckData check)
 {
     return("Basic" + check.Name + ".Fixer.vb");
 }
 public static string GenerateCodeFixTestsFileName(CheckData check)
 {
     return check.Name + "Tests.Fixer.cs";
 }
示例#21
0
 public static string GenerateCodeFixTestsFileName(CheckData check)
 {
     return(check.Name + "Tests.Fixer.cs");
 }
 public static string GenerateDiagnosticResourceData(CheckData check)
 {
     var sb = new StringBuilder();
     sb.AppendFormat(_diagnosticResourceDataTemplate,
                     check.Name,
                     check.Title,
                     check.Description);
     if (check.Messages != null && check.Messages.Count > 1)
     {   
         foreach (var pair in check.Messages)
         {
             sb.AppendFormat(_diagnosticResourceDataMessageTemplate,
                             check.Name,
                             pair.Key,
                             pair.Value);
         }
     }
     else
     {
         // use title as message
         sb.AppendFormat(_diagnosticResourceDataMessageTemplate,
                         check.Name,
                         "",
                         check.Title);
     }
     return sb.ToString();
 }
        private static void AddCompileItemsToProjectFile(string projFile, ProjectKind kind, CheckData check)
        {
            XDocument xmlFile = XDocument.Load(projFile);
            Debug.Assert(xmlFile.Root.Name.LocalName == "Project");

            var first = xmlFile.Root.Descendants().Where(c => c.Name.LocalName == "Compile").First();

            var parent = first.Parent;
            XElement elem = null;
            switch (kind)
            {
                case ProjectKind.Core:
                    elem = new XElement(first);
                    elem.SetAttributeValue("Include", CodeTemplates.GenerateAnalyzerFileName(check));
                    parent.Add(elem);
                    elem = new XElement(first);
                    elem.SetAttributeValue("Include", CodeTemplates.GenerateCodeFixFileName(check));
                    parent.Add(elem);
                    break;
                case ProjectKind.CSharp:
                    elem = new XElement(first);
                    elem.SetAttributeValue("Include", CodeTemplates.GenerateCSharpAnalyzerFileName(check));
                    parent.Add(elem);
                    elem = new XElement(first);
                    elem.SetAttributeValue("Include", CodeTemplates.GenerateCSharpCodeFixFileName(check));
                    parent.Add(elem);
                    break;
                case ProjectKind.VisualBasic:
                    elem = new XElement(first);
                    elem.SetAttributeValue("Include", CodeTemplates.GenerateBasicAnalyzerFileName(check));
                    parent.Add(elem);
                    elem = new XElement(first);
                    elem.SetAttributeValue("Include", CodeTemplates.GenerateBasicCodeFixFileName(check));
                    parent.Add(elem);
                    break;
                case ProjectKind.UnitTests:
                    elem = new XElement(first);
                    elem.SetAttributeValue("Include", CodeTemplates.GenerateAnalyzerTestsFileName(check));
                    parent.Add(elem);
                    elem = new XElement(first);
                    elem.SetAttributeValue("Include", CodeTemplates.GenerateCodeFixTestsFileName(check));
                    parent.Add(elem);
                    break;
                default:
                    throw new ArgumentException(kind.ToString());
            }
            xmlFile.Save(projFile);
            return;
        }
示例#24
0
        private static void AddCompileItemsToProjectFile(string projFile, ProjectKind kind, CheckData check)
        {
            XDocument xmlFile = XDocument.Load(projFile);

            Debug.Assert(xmlFile.Root.Name.LocalName == "Project");

            var first = xmlFile.Root.Descendants().Where(c => c.Name.LocalName == "Compile").First();

            var      parent = first.Parent;
            XElement elem   = null;

            switch (kind)
            {
            case ProjectKind.Core:
                elem = new XElement(first);
                elem.SetAttributeValue("Include", CodeTemplates.GenerateAnalyzerFileName(check));
                parent.Add(elem);
                elem = new XElement(first);
                elem.SetAttributeValue("Include", CodeTemplates.GenerateCodeFixFileName(check));
                parent.Add(elem);
                break;

            case ProjectKind.CSharp:
                elem = new XElement(first);
                elem.SetAttributeValue("Include", CodeTemplates.GenerateCSharpAnalyzerFileName(check));
                parent.Add(elem);
                elem = new XElement(first);
                elem.SetAttributeValue("Include", CodeTemplates.GenerateCSharpCodeFixFileName(check));
                parent.Add(elem);
                break;

            case ProjectKind.VisualBasic:
                elem = new XElement(first);
                elem.SetAttributeValue("Include", CodeTemplates.GenerateBasicAnalyzerFileName(check));
                parent.Add(elem);
                elem = new XElement(first);
                elem.SetAttributeValue("Include", CodeTemplates.GenerateBasicCodeFixFileName(check));
                parent.Add(elem);
                break;

            case ProjectKind.UnitTests:
                elem = new XElement(first);
                elem.SetAttributeValue("Include", CodeTemplates.GenerateAnalyzerTestsFileName(check));
                parent.Add(elem);
                elem = new XElement(first);
                elem.SetAttributeValue("Include", CodeTemplates.GenerateCodeFixTestsFileName(check));
                parent.Add(elem);
                break;

            default:
                throw new ArgumentException(kind.ToString());
            }
            xmlFile.Save(projFile);
            return;
        }