Esempio n. 1
0
        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());
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
 public static string GenerateBasicAnalyzerFileName(CheckData check)
 {
     return("Basic" + check.Name + ".vb");
 }
Esempio n. 4
0
 public static string GenerateCSharpAnalyzerFileName(CheckData check)
 {
     return("CSharp" + check.Name + ".cs");
 }
Esempio n. 5
0
 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);
        }
Esempio n. 7
0
 public static string GenerateCodeFixTests(string analyzer, CheckData check)
 {
     return(string.Format(_codeFixTestTemplate, analyzer, check.Name));
 }
Esempio n. 8
0
 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";
 }
Esempio n. 10
0
 public static string GenerateBasicCodeFix(string analyzer, CheckData check)
 {
     return string.Format(_basicCodeFixTemplate, analyzer, check.Name, check.Id, check.Title);
 }
Esempio n. 11
0
 public static string GenerateCSharpCodeFixFileName(CheckData check)
 {
     return "CSharp" + check.Name + ".Fixer.cs";
 }
Esempio n. 12
0
 public static string GenerateAnalyzerTestsFileName(CheckData check)
 {
     return check.Name + "Tests.cs";
 }
Esempio n. 13
0
 public static string GenerateBasicAnalyzerFileName(CheckData check)
 {
     return "Basic" + check.Name + ".vb";
 }
Esempio n. 14
0
 public static string GenerateCSharpAnalyzerFileName(CheckData check)
 {
     return "CSharp" + check.Name + ".cs";
 }
Esempio n. 15
0
 public static string GenerateCSharpAnalyzer(string analyzer, CheckData check)
 {
     return string.Format(_csharpAnalyzerTemplate, analyzer, check.Name, check.Id, check.Title);
 }
Esempio n. 16
0
 public static string GenerateAnalyzerTestsFileName(CheckData check)
 {
     return(check.Name + "Tests.cs");
 }
Esempio n. 17
0
 public static string GenerateCSharpCodeFixFileName(CheckData check)
 {
     return("CSharp" + check.Name + ".Fixer.cs");
 }
Esempio n. 18
0
 public static string GenerateCodeFixTests(string analyzer, CheckData check)
 {
     return string.Format(_codeFixTestTemplate, analyzer, check.Name);
 }
Esempio n. 19
0
 public static string GenerateBasicCodeFixFileName(CheckData check)
 {
     return("Basic" + check.Name + ".Fixer.vb");
 }
Esempio n. 20
0
 public static string GenerateCodeFixTestsFileName(CheckData check)
 {
     return check.Name + "Tests.Fixer.cs";
 }
Esempio n. 21
0
 public static string GenerateCodeFixTestsFileName(CheckData check)
 {
     return(check.Name + "Tests.Fixer.cs");
 }
Esempio n. 22
0
 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;
        }
Esempio n. 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;
        }