Exemplo n.º 1
0
 private static void LoadAnalyzerSettings(XmlDocument document, Settings settings)
 {
     XmlNodeList list = document.DocumentElement.SelectNodes("Analyzers/Analyzer");
     if ((list != null) && (list.Count > 0))
     {
         foreach (XmlNode node in list)
         {
             XmlAttribute attribute = node.Attributes["AnalyzerId"];
             if ((attribute != null) && !string.IsNullOrEmpty(attribute.Value))
             {
                 string analyzerId = ConvertLegacyAddInName(attribute.Value);
                 SourceAnalyzer addIn = settings.Core.GetAnalyzer(analyzerId);
                 if (addIn != null)
                 {
                     AddInPropertyCollection addInSettings = settings.GetAddInSettings(addIn);
                     if (addInSettings == null)
                     {
                         addInSettings = new AddInPropertyCollection(addIn);
                         settings.SetAddInSettings(addInSettings);
                     }
                     XmlNode propertyCollectionNode = node["AnalyzerSettings"];
                     if (propertyCollectionNode != null)
                     {
                         LoadPropertyCollection(propertyCollectionNode, addInSettings, addIn.PropertyDescriptors, null);
                     }
                     LoadRulesSettings(node, addInSettings, addIn.PropertyDescriptors);
                 }
             }
         }
     }
 }
 public override PropertyCollection Clone()
 {
     AddInPropertyCollection propertys = new AddInPropertyCollection(this.addIn);
     foreach (PropertyValue value2 in base.Properties)
     {
         propertys.Add(value2.Clone());
     }
     return propertys;
 }
        /// <summary>
        /// Clones the contents of the collection.
        /// </summary>
        /// <returns>Returns the cloned collection.</returns>
        public override PropertyCollection Clone()
        {
            AddInPropertyCollection clone = new AddInPropertyCollection(this.addIn);
            foreach (PropertyValue item in this.Properties)
            {
                clone.Add(item.Clone());
            }

            return clone;
        }
Exemplo n.º 4
0
 private static Settings MergeSettings(Settings originalSettings, Settings overridingSettings)
 {
     Settings settings = new Settings(originalSettings.Core);
     MergePropertyCollections(originalSettings.GlobalSettings, overridingSettings.GlobalSettings, settings.GlobalSettings);
     foreach (AddInPropertyCollection propertys in originalSettings.ParserSettings)
     {
         AddInPropertyCollection addInSettings = overridingSettings.GetAddInSettings(propertys.AddIn);
         AddInPropertyCollection properties = new AddInPropertyCollection(propertys.AddIn);
         settings.SetAddInSettings(properties);
         MergePropertyCollections(propertys, addInSettings, properties);
     }
     foreach (AddInPropertyCollection propertys4 in overridingSettings.ParserSettings)
     {
         if (settings.GetAddInSettings(propertys4.AddIn) == null)
         {
             settings.SetAddInSettings((AddInPropertyCollection) propertys4.Clone());
         }
     }
     foreach (AddInPropertyCollection propertys6 in originalSettings.AnalyzerSettings)
     {
         AddInPropertyCollection overridingPropertyCollection = overridingSettings.GetAddInSettings(propertys6.AddIn);
         AddInPropertyCollection propertys8 = new AddInPropertyCollection(propertys6.AddIn);
         settings.SetAddInSettings(propertys8);
         MergePropertyCollections(propertys6, overridingPropertyCollection, propertys8);
     }
     foreach (AddInPropertyCollection propertys9 in overridingSettings.AnalyzerSettings)
     {
         if (settings.GetAddInSettings(propertys9.AddIn) == null)
         {
             settings.SetAddInSettings((AddInPropertyCollection) propertys9.Clone());
         }
     }
     if (originalSettings.WriteTime.CompareTo(overridingSettings.WriteTime) > 0)
     {
         settings.WriteTime = originalSettings.WriteTime;
         return settings;
     }
     settings.WriteTime = overridingSettings.WriteTime;
     return settings;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Loads parser settings from the document.
        /// </summary>
        /// <param name="document">The settings document.</param>
        /// <param name="settings">Stores the settings.</param>
        private static void LoadParserSettings(XmlDocument document, Settings settings)
        {
            Param.AssertNotNull(document, "document");
            Param.AssertNotNull(settings, "settings");

            XmlNodeList parsersNodes = document.DocumentElement.SelectNodes("Parsers/Parser");
            if (parsersNodes != null && parsersNodes.Count > 0)
            {
                foreach (XmlNode parserNode in parsersNodes)
                {
                    XmlAttribute parserId = parserNode.Attributes["ParserId"];
                    if (parserId != null && !string.IsNullOrEmpty(parserId.Value))
                    {
                        string parserName = parserId.Value;
                        if (parserName.Equals("Microsoft.SourceAnalysis.CSharp.CsParser", StringComparison.Ordinal))
                        {
                            parserName = "Microsoft.StyleCop.CSharp.CsParser";
                        }

                        // Get the parser instance.
                        SourceParser parserInstance = settings.Core.GetParser(parserName);
                        if (parserInstance != null)
                        {
                            // Get the parser settings object for this parser or create a new one.
                            AddInPropertyCollection settingsForParser = settings.GetAddInSettings(parserInstance);

                            if (settingsForParser == null)
                            {
                                settingsForParser = new AddInPropertyCollection(parserInstance);
                                settings.SetAddInSettings(settingsForParser);
                            }

                            // Load the settings for this parser.
                            XmlNode parserSettingsNode = parserNode["ParserSettings"];
                            if (parserSettingsNode != null)
                            {
                                LoadPropertyCollection(parserSettingsNode, settingsForParser, parserInstance.PropertyDescriptors, null);
                            }

                            // Load any rule settings for the parser.
                            LoadRulesSettings(parserNode, settingsForParser, parserInstance.PropertyDescriptors);
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Loads analyzer settings from the document.
        /// </summary>
        /// <param name="document">The settings document.</param>
        /// <param name="settings">Stores the settings.</param>
        private static void LoadAnalyzerSettings(XmlDocument document, Settings settings)
        {
            Param.AssertNotNull(document, "document");
            Param.AssertNotNull(settings, "settings");

            XmlNodeList analyzerNodes = document.DocumentElement.SelectNodes("Analyzers/Analyzer");
            if (analyzerNodes != null && analyzerNodes.Count > 0)
            {
                foreach (XmlNode analyzerNode in analyzerNodes)
                {
                    XmlAttribute analyzerId = analyzerNode.Attributes["AnalyzerId"];
                    if (analyzerId != null && !string.IsNullOrEmpty(analyzerId.Value))
                    {
                        string analyzerId43 = MapAnalyzerId(analyzerId.Value);

                        // Get the analyzer instance for this mapped analyzer ID.
                        SourceAnalyzer analyzerInstance = settings.Core.GetAnalyzer(analyzerId43);
                        if (analyzerInstance != null)
                        {
                            // Get the analyzer settings object for this analyzer or create a new one.
                            AddInPropertyCollection settingsForAnalyzer = settings.GetAddInSettings(analyzerInstance);

                            if (settingsForAnalyzer == null)
                            {
                                settingsForAnalyzer = new AddInPropertyCollection(analyzerInstance);
                                settings.SetAddInSettings(settingsForAnalyzer);
                            }

                            // Load the settings for this analyzer.
                            XmlNode analyzerSettingsNode = analyzerNode["AnalyzerSettings"];
                            if (analyzerSettingsNode != null)
                            {
                                LoadPropertyCollection(analyzerSettingsNode, settingsForAnalyzer, analyzerInstance.PropertyDescriptors, analyzerId.Value);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
 private static void LoadParserSettings(XmlDocument document, Settings settings)
 {
     XmlNodeList list = document.DocumentElement.SelectNodes("Parsers/Parser");
     if ((list != null) && (list.Count > 0))
     {
         foreach (XmlNode node in list)
         {
             XmlAttribute attribute = node.Attributes["ParserId"];
             if ((attribute != null) && !string.IsNullOrEmpty(attribute.Value))
             {
                 string parserId = attribute.Value;
                 if (parserId.Equals("Microsoft.SourceAnalysis.CSharp.CsParser", StringComparison.Ordinal))
                 {
                     parserId = "Microsoft.StyleCop.CSharp.CsParser";
                 }
                 SourceParser addIn = settings.Core.GetParser(parserId);
                 if (addIn != null)
                 {
                     AddInPropertyCollection addInSettings = settings.GetAddInSettings(addIn);
                     if (addInSettings == null)
                     {
                         addInSettings = new AddInPropertyCollection(addIn);
                         settings.SetAddInSettings(addInSettings);
                     }
                     XmlNode propertyCollectionNode = node["ParserSettings"];
                     if (propertyCollectionNode != null)
                     {
                         LoadPropertyCollection(propertyCollectionNode, addInSettings, addIn.PropertyDescriptors, null);
                     }
                     LoadRulesSettings(node, addInSettings, addIn.PropertyDescriptors);
                 }
             }
         }
     }
 }
Exemplo n.º 8
0
 internal void SetAddInSettings(AddInPropertyCollection properties)
 {
     Dictionary<string, AddInPropertyCollection> propertyCollectionDictionary = this.GetPropertyCollectionDictionary(properties.AddIn);
     if (propertyCollectionDictionary.ContainsKey(properties.AddIn.Id))
     {
         propertyCollectionDictionary[properties.AddIn.Id] = properties;
     }
     else
     {
         propertyCollectionDictionary.Add(properties.AddIn.Id, properties);
     }
 }
Exemplo n.º 9
0
 internal void SetAddInSettingInternal(StyleCopAddIn addIn, PropertyValue property)
 {
     AddInPropertyCollection addInSettings = this.GetAddInSettings(addIn);
     if (addInSettings == null)
     {
         addInSettings = new AddInPropertyCollection(addIn);
         this.SetAddInSettings(addInSettings);
     }
     addInSettings.Add(property);
 }
Exemplo n.º 10
0
        /// <summary>
        /// Loads a property which no longer exists, and translates it into an enabled or
        /// disabled rule.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="analyzerId">The ID of the analyzer owning the property.</param>
        /// <param name="propertyName">The name of legacy property.</param>
        /// <param name="nodeText">The property value.</param>
        private static void LoadLegacyAnalyzerSetting(
            Settings settings, 
            string analyzerId, 
            string propertyName, 
            string nodeText)
        {
            Param.AssertNotNull(settings, "settings");
            Param.AssertValidString(analyzerId, "analyzerId");
            Param.AssertValidString(propertyName, "propertyName");
            Param.AssertNotNull(nodeText, "nodeText");

            switch (analyzerId)
            {
                case "Microsoft.StyleCop.CSharp.DocumentationRules":
                    if (propertyName == "RequireValueTags")
                    {
                        SourceAnalyzer analyzer = settings.Core.GetAnalyzer(analyzerId);
                        if (analyzer != null)
                        {
                            AddInPropertyCollection settingsForAnalyzer = settings.GetAddInSettings(analyzer);

                            if (settingsForAnalyzer == null)
                            {
                                settingsForAnalyzer = new AddInPropertyCollection(analyzer);
                                settings.SetAddInSettings(settingsForAnalyzer);
                            }

                            bool enabled = nodeText != "0";

                            AddOrUpdateLegacyBooleanProperty(
                                "PropertyDocumentationMustHaveValue", enabled, settingsForAnalyzer, analyzer.PropertyDescriptors);

                            AddOrUpdateLegacyBooleanProperty(
                                "PropertyDocumentationMustHaveValueText", enabled, settingsForAnalyzer, analyzer.PropertyDescriptors);
                        }
                    }

                    break;
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Enables or disables all ruels for the given analyzers.
        /// </summary>
        /// <param name="disabledAnalyzersNode">The node representing the analyzer.</param>
        /// <param name="settings">The settings.</param>
        /// <param name="enabled">Indicates whether to enable or disable the rules.</param>
        private static void EnableDisableAnalyzerRules(XmlNode disabledAnalyzersNode, Settings settings, bool enabled)
        {
            Param.AssertNotNull(disabledAnalyzersNode, "disabledAnalyzersNode");
            Param.AssertNotNull(settings, "settings");
            Param.Ignore(enabled);

            string[] ids = disabledAnalyzersNode.InnerText.Split(',');

            foreach (string id in ids)
            {
                string analyzerId43 = MapAnalyzerId(id);

                if (analyzerId43 != null)
                {
                    SourceAnalyzer analyzer = settings.Core.GetAnalyzer(analyzerId43);
                    if (analyzer != null)
                    {
                        ICollection<string> rules = MapAnalyzerToRules(id);
                        if (rules != null)
                        {
                            AddInPropertyCollection settingsForAnalyzer = settings.GetAddInSettings(analyzer);

                            if (settingsForAnalyzer == null)
                            {
                                settingsForAnalyzer = new AddInPropertyCollection(analyzer);
                                settings.SetAddInSettings(settingsForAnalyzer);
                            }

                            foreach (string rule in rules)
                            {
                                AddBooleanProperty(rule + "#Enabled", enabled, settingsForAnalyzer, analyzer.PropertyDescriptors);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Sets the settings for the given add-in.
        /// </summary>
        /// <param name="properties">The properties to set.</param>
        /// <remarks>This overrides any existing settings for the add-in.</remarks>
        internal void SetAddInSettings(AddInPropertyCollection properties)
        {
            Param.AssertNotNull(properties, "properties");

            Dictionary<string, AddInPropertyCollection> collection = this.GetPropertyCollectionDictionary(properties.AddIn);

            if (collection.ContainsKey(properties.AddIn.Id))
            {
                collection[properties.AddIn.Id] = properties;
            }
            else
            {
                collection.Add(properties.AddIn.Id, properties);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Sets a setting for the given add-in.
        /// </summary>
        /// <param name="addIn">The add-in.</param>
        /// <param name="property">The setting property to set.</param>
        internal void SetAddInSettingInternal(StyleCopAddIn addIn, PropertyValue property)
        {
            Param.AssertNotNull(addIn, "addIn");
            Param.AssertNotNull(property, "property");

            AddInPropertyCollection properties = this.GetAddInSettings(addIn);
            if (properties == null)
            {
                properties = new AddInPropertyCollection(addIn);
                this.SetAddInSettings(properties);
            }

            properties.Add(property);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Merges two settings files together.
        /// </summary>
        /// <param name="originalSettings">The original settings.</param>
        /// <param name="overridingSettings">The settings which are overriding the original settings.</param>
        /// <returns>Returns the merged settings.</returns>
        private static Settings MergeSettings(Settings originalSettings, Settings overridingSettings)
        {
            Param.AssertNotNull(originalSettings, "originalSettings");
            Param.AssertNotNull(overridingSettings, "overridingSettings");
            Debug.Assert(originalSettings.Core == overridingSettings.Core, "The settings must come from the same core instance.");

            // Create a new merged settings object.
            Settings mergedSettings = new Settings(originalSettings.Core);

            // Merge the global settings together.
            MergePropertyCollections(originalSettings.GlobalSettings, overridingSettings.GlobalSettings, mergedSettings.GlobalSettings);

            // Merge the parser settings together. Loop through the settings for each parser in the original settings.
            foreach (AddInPropertyCollection originalParserSettings in originalSettings.ParserSettings)
            {
                // Try to find settings for this parser in the overriding settings.
                AddInPropertyCollection overridingParserSettings = overridingSettings.GetAddInSettings(originalParserSettings.AddIn);

                // Create a new merged parser settings object.
                AddInPropertyCollection mergedParserSettings = new AddInPropertyCollection(originalParserSettings.AddIn);
                mergedSettings.SetAddInSettings(mergedParserSettings);

                // Merge the parser settings together.
                MergePropertyCollections(originalParserSettings, overridingParserSettings, mergedParserSettings);
            }

            // Now loop through the settings for each parser in the overriding settings. If there are any parser
            // settings here that aren't in the merged settings, then copy the settings directly from the overriding settings.
            // This means that there were no settings for this parser in the original settings.
            foreach (AddInPropertyCollection overridingParserSettings in overridingSettings.ParserSettings)
            {
                AddInPropertyCollection mergedParserSettings = mergedSettings.GetAddInSettings(overridingParserSettings.AddIn);
                if (mergedParserSettings == null)
                {
                    mergedSettings.SetAddInSettings((AddInPropertyCollection)overridingParserSettings.Clone());
                }
            }

            // Merge the analyzer settings together. Loop through the settings for each analyzer in the original settings.
            foreach (AddInPropertyCollection originalAnalyzerSettings in originalSettings.AnalyzerSettings)
            {
                // Try to find settings for this analyzer in the overriding settings.
                AddInPropertyCollection overridingAnalyzerSettings = overridingSettings.GetAddInSettings(originalAnalyzerSettings.AddIn);

                // Create a new merged analyzer settings object.
                AddInPropertyCollection mergedAnalyzerSettings = new AddInPropertyCollection(originalAnalyzerSettings.AddIn);
                mergedSettings.SetAddInSettings(mergedAnalyzerSettings);

                // Merge the analyer settings together.
                MergePropertyCollections(originalAnalyzerSettings, overridingAnalyzerSettings, mergedAnalyzerSettings);
            }

            // Now loop through the settings for each analyzer in the overriding settings. If there are any analyzer
            // settings here that aren't in the merged settings, then copy the settings directly from the overriding settings.
            // This means that there were no settings for this analyzer in the original settings.
            foreach (AddInPropertyCollection overridingAnalyzerSettings in overridingSettings.AnalyzerSettings)
            {
                AddInPropertyCollection mergedAnalyzerSettings = mergedSettings.GetAddInSettings(overridingAnalyzerSettings.AddIn);
                if (mergedAnalyzerSettings == null)
                {
                    mergedSettings.SetAddInSettings((AddInPropertyCollection)overridingAnalyzerSettings.Clone());
                }
            }

            // Merge the write times together. Set the write time of the merged settings file to the most
            // recent write time of the two file which were merged.
            if (originalSettings.WriteTime.CompareTo(overridingSettings.WriteTime) > 0)
            {
                mergedSettings.WriteTime = originalSettings.WriteTime;
            }
            else
            {
                mergedSettings.WriteTime = overridingSettings.WriteTime;
            }

            return mergedSettings;
        }
Exemplo n.º 15
0
 private static void LoadLegacyAnalyzerSetting(Settings settings, string analyzerId, string propertyName, string nodeText)
 {
     string str;
     if ((((str = analyzerId) != null) && (str == "Microsoft.StyleCop.CSharp.DocumentationRules")) && (propertyName == "RequireValueTags"))
     {
         SourceAnalyzer addIn = settings.Core.GetAnalyzer(analyzerId);
         if (addIn != null)
         {
             AddInPropertyCollection addInSettings = settings.GetAddInSettings(addIn);
             if (addInSettings == null)
             {
                 addInSettings = new AddInPropertyCollection(addIn);
                 settings.SetAddInSettings(addInSettings);
             }
             bool flag = nodeText != "0";
             AddOrUpdateLegacyBooleanProperty("PropertyDocumentationMustHaveValue", flag, addInSettings, addIn.PropertyDescriptors);
             AddOrUpdateLegacyBooleanProperty("PropertyDocumentationMustHaveValueText", flag, addInSettings, addIn.PropertyDescriptors);
         }
     }
 }
Exemplo n.º 16
0
 private static void EnableDisableAnalyzerRules(XmlNode disabledAnalyzersNode, Settings settings, bool enabled)
 {
     foreach (string str in disabledAnalyzersNode.InnerText.Split(new char[] { ',' }))
     {
         string analyzerId = MapAnalyzerId(str);
         if (analyzerId != null)
         {
             SourceAnalyzer addIn = settings.Core.GetAnalyzer(analyzerId);
             if (addIn != null)
             {
                 ICollection<string> is2 = MapAnalyzerToRules(str);
                 if (is2 != null)
                 {
                     AddInPropertyCollection addInSettings = settings.GetAddInSettings(addIn);
                     if (addInSettings == null)
                     {
                         addInSettings = new AddInPropertyCollection(addIn);
                         settings.SetAddInSettings(addInSettings);
                     }
                     foreach (string str3 in is2)
                     {
                         AddBooleanProperty(str3 + "#Enabled", enabled, addInSettings, addIn.PropertyDescriptors);
                     }
                 }
             }
         }
     }
 }