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 = MapAnalyzerId(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, attribute.Value); } } } } } }
public SettingsMerger(Settings localSettings, StyleCopEnvironment environment) { Param.RequireNotNull(localSettings, "localSettings"); Param.RequireNotNull(environment, "environment"); this.localSettings = localSettings; this.environment = environment; }
/// <summary> /// Checks the methods within the given document. /// </summary> /// <param name="document">The document to check.</param> public override void AnalyzeDocument(CodeDocument document) { Param.RequireNotNull(document, "document"); CsDocument csdocument = (CsDocument)document; Settings settings = new Settings(); settings.DoNotUseRegions = this.IsRuleEnabled(document, Rules.DoNotUseRegions.ToString()); settings.DoNotPlaceRegionsWithinElements = this.IsRuleEnabled(document, Rules.DoNotPlaceRegionsWithinElements.ToString()); if (csdocument.RootElement != null && !csdocument.RootElement.Generated) { // Checks various formatting rules. csdocument.WalkDocument( new CodeWalkerElementVisitor<object>(this.ProcessElement), null, new CodeWalkerExpressionVisitor<object>(this.ProcessExpression), settings); // Check statement formatting rules. this.CheckStatementFormattingRulesForElement(csdocument.RootElement); // Check the class member rules. this.CheckClassMemberRulesForElements(csdocument.RootElement, null, null); // Looks for empty comments. this.CheckForEmptyComments(csdocument.RootElement); // Checks the usage of the built-in types and empty strings. this.IterateTokenList(csdocument, settings); } }
/// <summary> /// Loads the settings from the document. /// </summary> /// <param name="document">The settings document.</param> /// <param name="settings">Stores the settings.</param> public static void Load(XmlDocument document, Settings settings) { Param.AssertNotNull(document, "document"); Param.AssertNotNull(settings, "settings"); // If the PublicAndProtectedOnly property exists on the Documentation analyzer, rename it to IgnorePrivates. V41Settings.ChangeAnalyzerSettingName( document, "Microsoft.StyleCop.CSharp.Documentation", "PublicAndProtectedOnly", "IgnorePrivates"); // Add the global settings if there are any. XmlNode globalSettingsNode = document.DocumentElement["GlobalSettings"]; if (globalSettingsNode != null) { LoadPropertyCollection( globalSettingsNode, settings.GlobalSettings, settings.Core.PropertyDescriptors, null); } // Load the parser settings. LoadParserSettings(document, settings); // Load the analyzers under this parser. LoadAnalyzerSettings(document, settings); }
/// <summary> /// Initializes a new instance of the SettingsComparer class. /// </summary> /// <param name="localSettings">The local settings.</param> /// <param name="parentSettings">The parent setting to merge with the local settings, or null.</param> public SettingsComparer(Settings localSettings, Settings parentSettings) { Param.RequireNotNull(localSettings, "localSettings"); Param.Ignore(parentSettings); this.localSettings = localSettings; this.parentSettings = parentSettings; }
public static void Load(XmlDocument document, Settings settings) { XmlNode propertyCollectionNode = document.DocumentElement["GlobalSettings"]; if (propertyCollectionNode != null) { LoadPropertyCollection(propertyCollectionNode, settings.GlobalSettings, settings.Core.PropertyDescriptors, null); } LoadParserSettings(document, settings); LoadAnalyzerSettings(document, settings); }
public static void Load(XmlDocument document, Settings settings) { ChangeAnalyzerSettingName(document, "Microsoft.StyleCop.CSharp.Documentation", "PublicAndProtectedOnly", "IgnorePrivates"); XmlNode propertyCollectionNode = document.DocumentElement["GlobalSettings"]; if (propertyCollectionNode != null) { LoadPropertyCollection(propertyCollectionNode, settings.GlobalSettings, settings.Core.PropertyDescriptors, null); } LoadParserSettings(document, settings); LoadAnalyzerSettings(document, settings); }
/// <summary> /// Initializes a new instance of the StyleCopObjectConsole class. /// </summary> /// <param name="environment">The environment.</param> /// <param name="defaultSettings">The default settings to use, or null to allow each project to specify its own settings.</param> /// <param name="addInPaths">The list of paths to search under for parser and analyzer addins. /// Can be null if no addin paths are provided.</param> /// <param name="loadFromDefaultPath">Indicates whether to load addins /// from the default application path.</param> public StyleCopObjectConsole( ObjectBasedEnvironment environment, Settings defaultSettings, ICollection<string> addInPaths, bool loadFromDefaultPath) : this(environment, defaultSettings, addInPaths, loadFromDefaultPath, null) { Param.Ignore(environment); Param.Ignore(defaultSettings); Param.Ignore(addInPaths); Param.Ignore(loadFromDefaultPath); }
/// <summary> /// Loads the settings from the document. /// </summary> /// <param name="document">The settings document.</param> /// <param name="settings">Stores the settings.</param> public static void Load(XmlDocument document, Settings settings) { Param.AssertNotNull(document, "document"); Param.AssertNotNull(settings, "settings"); // Add the global settings if there are any. XmlNode globalSettingsNode = document.DocumentElement["GlobalSettings"]; if (globalSettingsNode != null) { LoadPropertyCollection( globalSettingsNode, settings.GlobalSettings, settings.Core.PropertyDescriptors, null); } // Load the parser settings. LoadParserSettings(document, settings); // Load the analyzers under this parser. LoadAnalyzerSettings(document, settings); }
/// <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 analyzerName = ConvertLegacyAddInName(analyzerId.Value); // Get the analyzer instance. SourceAnalyzer analyzerInstance = settings.Core.GetAnalyzer(analyzerName); 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, null); } // Load any rule settings for the analyzer. LoadRulesSettings(analyzerNode, settingsForAnalyzer, analyzerInstance.PropertyDescriptors); } } } } }
/// <summary> /// Initializes a new instance of the StyleCopObjectConsole class. /// </summary> /// <param name="environment">The environment.</param> /// <param name="defaultSettings">The default settings to use, or null to allow each project to specify its own settings.</param> /// <param name="addInPaths">The list of paths to search under for parser and analyzer addins. /// Can be null if no addin paths are provided.</param> /// <param name="loadFromDefaultPath">Indicates whether to load addins /// from the default application path.</param> /// <param name="hostTag">An optional tag which can be set by the host.</param> public StyleCopObjectConsole( ObjectBasedEnvironment environment, Settings defaultSettings, ICollection<string> addInPaths, bool loadFromDefaultPath, object hostTag) { Param.RequireNotNull(environment, "environment"); Param.Ignore(defaultSettings); Param.Ignore(addInPaths); Param.Ignore(loadFromDefaultPath); Param.Ignore(hostTag); this.Core = new StyleCopCore(environment, hostTag); this.Core.Initialize(addInPaths, loadFromDefaultPath); this.Core.WriteResultsCache = false; this.InitCore(); this.defaultSettings = defaultSettings; }
/// <summary> /// Loads the settings from the document. /// </summary> /// <param name="document">The settings document.</param> /// <param name="settings">Stores the settings.</param> public static void Load(XmlDocument document, Settings settings) { Param.AssertNotNull(document, "document"); Param.AssertNotNull(settings, "settings"); // Move the StatementMustNotUseUnnecessaryParenthesis rule from the ReadabilityRules analyzer to the MaintainabilityRules analyzer // if it exists. MoveRuleToNewAnalyzer( document, "Microsoft.SourceAnalysis.CSharp.ReadabilityRules", "Microsoft.SourceAnalysis.CSharp.MaintainabilityRules", "StatementMustNotUseUnnecessaryParenthesis"); // If the PublicAndProtectedOnly property exists on the DocumentationRules analyzer, rename it to IgnorePrivates. V41Settings.ChangeAnalyzerSettingName( document, "Microsoft.SourceAnalysis.CSharp.DocumentationRules", "PublicAndProtectedOnly", "IgnorePrivates"); // Forward this call to the V4.3 rule class for parsing. V43Settings.Load(document, settings); }
/// <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; } }
/// <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); } } } } }
/// <summary> /// Gets the settings given the path to the local settings. /// </summary> /// <param name="settingsPath">The path to the settings to load.</param> /// <param name="merge">Indicates whether to merge the settings with parent settings before returning them.</param> /// <param name="exception">Returns an exception if one occured while loading the settings.</param> /// <returns>Returns the settings.</returns> public override Settings GetSettings(string settingsPath, bool merge, out Exception exception) { Param.RequireValidString(settingsPath, "settingsPath"); Param.Ignore(merge); Param.Ignore(merge); // Load the settings file. Settings settings = this.LoadSettingsDocument(settingsPath, true, out exception); if (merge) { // If there are no local settings, create an empty settings file pointing // at the location where we expected the local settings to be. This // will allow us to do a parent merge from this location. if (settings == null) { settings = new Settings(this.Core, settingsPath, Path.GetDirectoryName(settingsPath)); } // Merge the file and return it. SettingsMerger merger = new SettingsMerger(settings, this); settings = merger.MergedSettings; } return settings; }
/// <summary> /// The control must be initialized by calling this method during the host's OnLoad event. /// </summary> /// <param name="hostInstance">Interface implemented by the host object.</param> /// <param name="propertyPages">The array of pages to display on the tab control.</param> /// <param name="settings">The settings to read from and write to.</param> /// <param name="coreInstance">The StyleCop core instance.</param> /// <param name="contextItem">The context for the property control.</param> internal void Initialize( IPropertyControlHost hostInstance, IList<IPropertyControlPage> propertyPages, WritableSettings settings, StyleCopCore coreInstance, params object[] contextItem) { Param.AssertNotNull(hostInstance, "hostInstance"); Param.Assert(propertyPages != null && propertyPages.Count > 0, "propertyPages", "Cannot be null or empty"); Param.AssertNotNull(settings, "settings"); Param.AssertNotNull(coreInstance, "coreInstance"); Param.Ignore(contextItem); // Make sure we haven't already been intialized. if (this.host != null) { throw new StyleCopException(Strings.PropertyControlAlreadyInitialized); } this.host = hostInstance; this.pageInterfaces = propertyPages; this.localSettings = settings; this.core = coreInstance; this.context = contextItem; // Set the contents of the parent settings file. SettingsMerger merger = new SettingsMerger(this.localSettings, this.core.Environment); this.parentSettings = merger.ParentMergedSettings; this.mergedSettings = merger.MergedSettings; // Set up the settings comparer. this.settingsComparer = new SettingsComparer(this.localSettings, this.parentSettings); // Make sure the context is non-null. if (this.context == null) { this.context = new object[] { }; } this.tabPages = new TabPage[propertyPages.Count]; this.pages = new UserControl[propertyPages.Count]; // Add each of the property pages. int pageCount = 0; // Initialize the settings pages. for (int i = 0; i < propertyPages.Count; ++i) { this.pages[pageCount] = (UserControl)this.pageInterfaces[i]; TabPage tabPage = new TabPage(this.pageInterfaces[i].TabName); this.tabPages[pageCount] = tabPage; tabPage.Controls.Add(this.pages[i]); this.Controls.Add(tabPage); this.pages[i].Dock = DockStyle.Fill; this.SizePage(i); // The first page has already been initialized. this.pageInterfaces[i].Initialize(this); ++pageCount; } // Activate the first page. if (this.TabPages[0] != null) { this.SelectedTab = this.tabPages[0]; this.pageInterfaces[0].Activate(true); } this.SizeChanged += new System.EventHandler(this.OnSizeChanged); }
/// <summary> /// Checks the built-in types and empty strings within a document. /// </summary> /// <param name="document">The document containing the tokens.</param> /// <param name="settings">The current settings.</param> private void IterateTokenList(CsDocument document, Settings settings) { Param.AssertNotNull(document, "document"); Param.Ignore(settings); for (Node<CsToken> tokenNode = document.Tokens.First; tokenNode != null; tokenNode = tokenNode.Next) { CsToken token = tokenNode.Value; if (token.CsTokenClass == CsTokenClass.Type || token.CsTokenClass == CsTokenClass.GenericType) { // Check that the type is using the built-in types, if applicable. this.CheckBuiltInType(tokenNode, document); } else if (token.CsTokenType == CsTokenType.String) { // Check that the string is not using the empty string "" syntax. this.CheckEmptyString(tokenNode); } else if (token.CsTokenClass == CsTokenClass.RegionDirective && settings.DoNotUseRegions) { Region region = (Region)token; if (region.Beginning && !region.Generated && !region.IsGeneratedCodeRegion) { // There should not be any regions in the code. this.AddViolation(token.FindParentElement(), token.LineNumber, Rules.DoNotUseRegions); } } } }
/// <summary> /// Processes the given element. /// </summary> /// <param name="element">The element being visited.</param> /// <param name="settings">The settings.</param> private void CheckForRegionsInElement(CsElement element, Settings settings) { Param.AssertNotNull(element, "element"); Param.AssertNotNull(settings, "settings"); // If the DoNotUseRegions setting is enabled, then skip this check as the region // will be discovered during the overall regions rule check. if (settings.DoNotPlaceRegionsWithinElements && !settings.DoNotUseRegions && !element.Generated) { if (element.ElementType == ElementType.Method || element.ElementType == ElementType.Accessor || element.ElementType == ElementType.Constructor || element.ElementType == ElementType.Destructor || element.ElementType == ElementType.Field) { for (Node<CsToken> tokenNode = element.Tokens.First; tokenNode != element.Tokens.Last.Next; tokenNode = tokenNode.Next) { // If this token is an opening region directive, this is a violation. if (tokenNode.Value.CsTokenClass == CsTokenClass.RegionDirective) { Region region = (Region)tokenNode.Value; if (region.Beginning && !region.Generated && !region.IsGeneratedCodeRegion) { this.AddViolation(element, tokenNode.Value.LineNumber, Rules.DoNotPlaceRegionsWithinElements); } } } } } }
/// <summary> /// Gets the list of valid prefixes for the given project. /// </summary> /// <param name="settings">The settings for the document being parsed.</param> /// <returns>Returns the list of prefixes.</returns> private Dictionary<string, string> GetPrefixes(Settings settings) { Param.Ignore(settings); Dictionary<string, string> validPrefixes = new Dictionary<string, string>(); if (settings != null) { // Get the allowed hungarian prefixes from the local settings file. CollectionProperty list = this.GetSetting(settings, NamingRules.AllowedPrefixesProperty) as CollectionProperty; if (list != null && list.Count > 0) { foreach (string value in list) { if (!string.IsNullOrEmpty(value) && !validPrefixes.ContainsKey(value)) { validPrefixes.Add(value, value); } } } } return validPrefixes; }
/// <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); } } } } } }
/// <summary> /// Called when the parent settings have changed. /// </summary> public void RefreshMergedSettings() { // Set the contents of the parent settings file. SettingsMerger merger = new SettingsMerger(this.localSettings, this.core.Environment); this.parentSettings = merger.ParentMergedSettings; this.mergedSettings = merger.MergedSettings; // Set up the settings comparer. this.settingsComparer = new SettingsComparer(this.localSettings, this.parentSettings); for (int i = 0; i < this.pageInterfaces.Count; ++i) { if (this.pageInterfaces[i] != null) { this.pageInterfaces[i].RefreshSettingsOverrideState(); } } }
/// <summary> /// Sets the AnalyzeDesignerFiles property on the C# parser. /// </summary> /// <param name="settings">The settings collection.</param> /// <param name="nodeText">The text of the setting from the settings file.</param> private static void LoadAnalyzeDesignerFilesSetting(Settings settings, string nodeText) { Param.AssertNotNull(settings, "settings"); Param.AssertValidString(nodeText, "nodeText"); SourceParser parser = settings.Core.GetParser("Microsoft.StyleCop.CSharp.CsParser"); if (parser != null) { PropertyDescriptor<bool> propertyDescriptor = parser.PropertyDescriptors["AnalyzeDesignerFiles"] as PropertyDescriptor<bool>; if (propertyDescriptor != null) { settings.SetAddInSettingInternal(parser, new BooleanProperty(propertyDescriptor, nodeText != "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; }
/// <summary> /// Sets the given property on the given parser. /// </summary> /// <param name="settings">The settings collection.</param> /// <param name="analyzerId">The ID of the analyzer.</param> /// <param name="propertyName">The name of the property to set.</param> /// <param name="nodeText">The text of the setting from the settings file.</param> private static void LoadAnalyzerSetting(Settings settings, string analyzerId, string propertyName, string nodeText) { Param.AssertNotNull(settings, "settings"); Param.AssertValidString(analyzerId, "analyzerId"); Param.AssertValidString(propertyName, "propertyName"); Param.AssertValidString(nodeText, "nodeText"); SourceAnalyzer analyzer = settings.Core.GetAnalyzer(analyzerId); if (analyzer != null) { PropertyDescriptor<bool> propertyDescriptor = analyzer.PropertyDescriptors[propertyName] as PropertyDescriptor<bool>; if (propertyDescriptor != null) { settings.SetAddInSettingInternal(analyzer, new BooleanProperty(propertyDescriptor, nodeText != "0")); } } }
private Settings FindMergedSettingsThroughLinkedSettings(Settings originalSettings, bool mergeOriginal) { StringProperty property = originalSettings.GlobalSettings.GetProperty("LinkedSettingsFile") as StringProperty; if ((property == null) || string.IsNullOrEmpty(property.Value)) { return originalSettings; } string relativePath = Environment.ExpandEnvironmentVariables(property.Value); if (relativePath.StartsWith(".", StringComparison.Ordinal) || !relativePath.Contains(@"\")) { relativePath = StyleCopCore.MakeAbsolutePath(originalSettings.Location, relativePath); } if (!File.Exists(relativePath)) { return originalSettings; } Settings settings = this.environment.GetSettings(relativePath, true); if (settings == null) { return originalSettings; } if (mergeOriginal) { return MergeSettings(settings, originalSettings); } return settings; }
/// <summary> /// Loads the valid prefixes from the given node.. /// </summary> /// <param name="validPrefixesNode">The node containing the prefixes.</param> /// <param name="settings">The settings collection.</param> private static void LoadValidPrefixes(XmlNode validPrefixesNode, Settings settings) { Param.AssertNotNull(validPrefixesNode, "validPrefixesNode"); Param.AssertNotNull(settings, "settings"); string[] prefixes = validPrefixesNode.InnerText.Split(','); // Get the analyzer. SourceAnalyzer analyzer = settings.Core.GetAnalyzer("Microsoft.StyleCop.CSharp.NamingRules"); if (analyzer != null) { // Get the property descriptor. CollectionPropertyDescriptor propertyDescriptor = analyzer.PropertyDescriptors["Hungarian"] as CollectionPropertyDescriptor; if (propertyDescriptor != null) { settings.SetAddInSettingInternal(analyzer, new CollectionProperty(propertyDescriptor, prefixes)); } } }
private Settings FindMergedSettingsThroughParentPaths(Settings originalSettings, bool mergeOriginal) { if (!originalSettings.DefaultSettings) { bool flag = false; string parentSettingsPath = this.environment.GetParentSettingsPath(originalSettings.Location); if (string.IsNullOrEmpty(parentSettingsPath) && !originalSettings.DefaultSettings) { flag = true; parentSettingsPath = this.environment.GetDefaultSettingsPath(); } if (!string.IsNullOrEmpty(parentSettingsPath)) { Settings settings = this.environment.GetSettings(parentSettingsPath, !flag); settings.DefaultSettings = flag; if (settings != null) { if (mergeOriginal) { Settings settings2 = MergeSettings(settings, originalSettings); settings2.DefaultSettings = flag; return settings2; } return settings; } } } if (!mergeOriginal) { return null; } return originalSettings; }
/// <summary> /// Loads a pre-version 4.1 settings document. /// </summary> /// <param name="document">The settings to load.</param> /// <param name="settings">The object where the settings will be stored.</param> internal static void Load(XmlDocument document, Settings settings) { Param.AssertNotNull(document, "document"); Param.AssertNotNull(settings, "settings"); foreach (XmlNode child in document.DocumentElement.ChildNodes) { switch (child.Name) { case "StyleCopDisabledAnalyzers": EnableDisableAnalyzerRules(child, settings, false); break; case "StyleCopExplicitlyEnabledAnalyzers": EnableDisableAnalyzerRules(child, settings, true); break; case "AnalyzeDesignerFiles": LoadAnalyzeDesignerFilesSetting(settings, child.InnerText); break; case "PublicAndProtectedOnly": LoadAnalyzerSetting( settings, "Microsoft.StyleCop.CSharp.DocumentationRules", "IgnorePrivates", child.InnerText); LoadAnalyzerSetting( settings, "Microsoft.StyleCop.CSharp.DocumentationRules", "IgnoreInternals", child.InnerText); break; case "IncludeFields": LoadAnalyzerSetting( settings, "Microsoft.StyleCop.CSharp.DocumentationRules", "IncludeFields", child.InnerText); break; case "GeneratedCodeElementOrder": LoadAnalyzerSetting( settings, "Microsoft.StyleCop.CSharp.OrderingRules", "GeneratedCodeElementOrder", child.InnerText); break; case "RequireValueTags": LoadLegacyAnalyzerSetting( settings, "Microsoft.StyleCop.CSharp.DocumentationRules", "RequireValueTags", child.InnerText); break; case "GlobalSettingsFilePath": PropertyDescriptor<string> propertyDescriptor = settings.Core.PropertyDescriptors[SettingsMerger.MergeSettingsFilesProperty] as PropertyDescriptor<string>; if (propertyDescriptor != null) { settings.GlobalSettings.Add(new StringProperty(propertyDescriptor, SettingsMerger.MergeStyleLinked)); } propertyDescriptor = settings.Core.PropertyDescriptors[SettingsMerger.LinkedSettingsProperty] as PropertyDescriptor<string>; if (propertyDescriptor != null) { settings.GlobalSettings.Add(new StringProperty(propertyDescriptor, child.InnerText)); } break; case "StyleCopHungarian": LoadValidPrefixes(child, settings); break; } } }
/// <summary> /// Gets a setting for the add-in. /// </summary> /// <param name="settings">The settings.</param> /// <param name="propertyName">The name of the setting property.</param> /// <returns>Returns the setting or null if it does not exist.</returns> public PropertyValue GetSetting(Settings settings, string propertyName) { Param.Ignore(settings); Param.RequireValidString(propertyName, "propertyName"); if (settings == null) { return null; } return settings.GetAddInSetting(this, propertyName); }
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); } } } } }