public bool IsAddInSettingOverwritten(StyleCopAddIn addIn, string propertyName, PropertyValue localProperty) { Param.RequireNotNull(addIn, "addIn"); Param.RequireValidString(propertyName, "propertyName"); Param.Ignore(localProperty); if (this.parentSettings == null) { return(false); } // Try to find this property in the parent settings file. PropertyValue parentProperty = null; PropertyCollection parentParserProperties = this.parentSettings.GetAddInSettings(addIn); if (parentParserProperties != null) { parentProperty = parentParserProperties[propertyName]; } if (parentProperty == null) { // If there is no parent setting, then the parent is set to the default. If the local setting // is not set to the default, then we consider that the local setting is overriding the parent setting. return(!localProperty.HasDefaultValue || !localProperty.IsDefault); } // Compare the local and parent properties. return(IsSettingOverwritten(localProperty, parentProperty)); }
public void SetAddInSetting(StyleCopAddIn addIn, PropertyValue property) { Param.RequireNotNull(addIn, "addIn"); Param.RequireNotNull(property, "property"); this.SetAddInSettingInternal(addIn, property); }
public void ClearAddInSetting(StyleCopAddIn addIn, string propertyName) { Param.RequireNotNull(addIn, "addIn"); Param.RequireValidString(propertyName, "propertyName"); this.ClearAddInSettingInternal(addIn, propertyName); }
/// <summary> /// Determines whether a local add-in setting overrides the parent setting. /// </summary> /// <param name="addIn">The add-in.</param> /// <param name="propertyName">The name of the property.</param> /// <returns>Returns true if the local add-in setting overrides the parent setting.</returns> public bool IsParserSettingOverwritten(StyleCopAddIn addIn, string propertyName) { Param.RequireNotNull(addIn, "addIn"); Param.RequireValidString(propertyName, "propertyName"); if (this.localSettings == null) { return(false); } PropertyCollection localAddInSettings = this.localSettings.GetAddInSettings(addIn); if (localAddInSettings == null) { return(false); } PropertyValue localProperty = localAddInSettings[propertyName]; if (localProperty == null) { return(false); } return(this.IsAddInSettingOverwritten(addIn, propertyName, localProperty)); }
public PropertyValue GetAddInSetting(StyleCopAddIn addIn, string propertyName) { Param.RequireNotNull(addIn, "addIn"); Param.RequireValidString(propertyName, "propertyName"); PropertyCollection properties = this.GetAddInSettings(addIn); if (properties != null) { return(properties[propertyName]); } return(null); }
/// <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); }
/// <summary> /// Gets the settings for the given add-in. /// </summary> /// <param name="addIn"> /// The add-in. /// </param> /// <returns> /// Returns the add-in settings or null if there are no settings for the add-in. /// </returns> public AddInPropertyCollection GetAddInSettings(StyleCopAddIn addIn) { Param.RequireNotNull(addIn, "addIn"); Dictionary <string, AddInPropertyCollection> collection = this.GetPropertyCollectionDictionary(addIn); AddInPropertyCollection settingsForAddIn; if (collection.TryGetValue(addIn.Id, out settingsForAddIn)) { return(settingsForAddIn); } return(null); }
/// <summary> /// Clears a setting for the given add-in. /// </summary> /// <param name="addIn"> /// The add-in. /// </param> /// <param name="propertyName"> /// The name of the property to clear. /// </param> internal void ClearAddInSettingInternal(StyleCopAddIn addIn, string propertyName) { Param.AssertNotNull(addIn, "addIn"); Param.AssertValidString(propertyName, "propertyName"); PropertyCollection properties = this.GetAddInSettings(addIn); if (properties != null) { properties.Remove(propertyName); if (properties.Count == 0) { Dictionary <string, AddInPropertyCollection> collection = this.GetPropertyCollectionDictionary(addIn); collection.Remove(addIn.Id); } } }
/// <summary> /// Initializes a new instance of the SourceAnalyzer class. /// </summary> protected SourceAnalyzer() { // Get the SourceAnalyzer attribute from the type. object[] attributes = this.GetType().GetCustomAttributes(typeof(SourceAnalyzerAttribute), true); if (attributes == null || attributes.Length == 0) { throw new ArgumentException(Strings.SourceAnalyzerAttributeMissing); } // Make sure the parser type is set. SourceAnalyzerAttribute attribute = (SourceAnalyzerAttribute)attributes[0]; if (attribute.ParserType == null) { throw new ArgumentException(Strings.SourceAnalyzerAttributeMissing); } // Set the parser ID. this.parserId = StyleCopAddIn.GetIdFromAddInType(attribute.ParserType); }
internal UsingSettings(StyleCopAddIn sourceAnalyzer, Settings settings) { this.settingsManager = ServiceLocator.GetService<SettingsManager>(); this.AliasShouldBeLast = this.settingsManager.GetSetting<bool>("AliasShouldBeLast", sourceAnalyzer, settings); string usingDirectiveGroups = this.settingsManager.GetSetting<string>("UsingDirectiveGroups", sourceAnalyzer, settings); this.GroupPrefixes = new List<IList<string>>(); foreach (string groupValue in usingDirectiveGroups.Split(UsingSettings.GroupSeparator)) { this.GroupPrefixes.Add(groupValue.Split(UsingSettings.UsingSeparator)); } foreach (IList<string> prefixList in this.GroupPrefixes) { foreach (string prefix in prefixList) { if (prefix == null) throw new InvalidOperationException("using group cannot be empty"); if (string.IsNullOrEmpty(prefix.Trim())) throw new InvalidOperationException("using group cannot be empty"); } } }
/// <summary> /// Stores the properties for the given add-in. /// </summary> /// <param name="addIn"> /// The add-in. /// </param> private void StoreAddinProperties(StyleCopAddIn addIn) { Param.AssertNotNull(addIn, "addIn"); ICollection<PropertyDescriptor> addInPropertyDescriptors = addIn.PropertyDescriptors; if (addInPropertyDescriptors != null && addInPropertyDescriptors.Count > 0) { List<BooleanProperty> storedProperties = new List<BooleanProperty>(addInPropertyDescriptors.Count); foreach (PropertyDescriptor propertyDescriptor in addInPropertyDescriptors) { if (propertyDescriptor.PropertyType == PropertyType.Boolean && propertyDescriptor.DisplaySettings) { PropertyDescriptor<bool> booleanPropertyDescriptor = (PropertyDescriptor<bool>)propertyDescriptor; // Ensure that the property has a friendly name and a description. if (string.IsNullOrEmpty(propertyDescriptor.FriendlyName)) { throw new ArgumentException(Strings.PropertyFriendlyNameNotSet); } if (string.IsNullOrEmpty(propertyDescriptor.Description)) { throw new ArgumentException(Strings.PropertyDescriptionNotSet); } BooleanProperty storedProperty = new BooleanProperty(booleanPropertyDescriptor, booleanPropertyDescriptor.DefaultValue); this.InitializePropertyState(addIn, storedProperty); storedProperties.Add(storedProperty); } } this.properties.Add(addIn, storedProperties.ToArray()); } }
/// <summary> /// Sets the check state for the given property. /// </summary> /// <param name="addIn"> /// The addin that owns the property. /// </param> /// <param name="property"> /// The property. /// </param> private void InitializePropertyState(StyleCopAddIn addIn, BooleanProperty property) { Param.AssertNotNull(addIn, "addIn"); Param.AssertNotNull(property, "property"); BooleanProperty mergedProperty = addIn.GetSetting(this.tabControl.MergedSettings, property.PropertyName) as BooleanProperty; if (mergedProperty == null) { property.Value = property.DefaultValue; } else { property.Value = mergedProperty.Value; } }
/// <summary> /// Determines whether a local add-in setting overrides the parent setting. /// </summary> /// <param name="addIn">The add-in.</param> /// <param name="propertyName">The name of the property.</param> /// <returns>Returns true if the local add-in setting overrides the parent setting.</returns> public bool IsParserSettingOverwritten(StyleCopAddIn addIn, string propertyName) { Param.RequireNotNull(addIn, "addIn"); Param.RequireValidString(propertyName, "propertyName"); if (this.localSettings == null) { return false; } PropertyCollection localAddInSettings = this.localSettings.GetAddInSettings(addIn); if (localAddInSettings == null) { return false; } PropertyValue localProperty = localAddInSettings[propertyName]; if (localProperty == null) { return false; } return this.IsAddInSettingOverwritten(addIn, propertyName, localProperty); }
public bool IsAddInSettingOverwritten(StyleCopAddIn addIn, string propertyName, PropertyValue localProperty) { Param.RequireNotNull(addIn, "addIn"); Param.RequireValidString(propertyName, "propertyName"); Param.Ignore(localProperty); if (this.parentSettings == null) { return false; } // Try to find this property in the parent settings file. PropertyValue parentProperty = null; PropertyCollection parentParserProperties = this.parentSettings.GetAddInSettings(addIn); if (parentParserProperties != null) { parentProperty = parentParserProperties[propertyName]; } if (parentProperty == null) { // If there is no parent setting, then the parent is set to the default. If the local setting // is not set to the default, then we consider that the local setting is overriding the parent setting. return !localProperty.HasDefaultValue || !localProperty.IsDefault; } // Compare the local and parent properties. return IsSettingOverwritten(localProperty, parentProperty); }
/// <summary> /// Gets the correct property collection dictionary depending on whether the given add-in is a parser or an analyzer. /// </summary> /// <param name="addIn"> /// The add-in. /// </param> /// <returns> /// Returns the correct dictionary. /// </returns> private Dictionary<string, AddInPropertyCollection> GetPropertyCollectionDictionary(StyleCopAddIn addIn) { Param.AssertNotNull(addIn, "addIn"); Dictionary<string, AddInPropertyCollection> collection = this.parserSettings; if (addIn is SourceAnalyzer) { collection = this.analyzerSettings; } return collection; }
/// <summary> /// Gets the correct property collection dictionary depending on whether the given add-in is a parser or an analyzer. /// </summary> /// <param name="addIn"> /// The add-in. /// </param> /// <returns> /// Returns the correct dictionary. /// </returns> private Dictionary <string, AddInPropertyCollection> GetPropertyCollectionDictionary(StyleCopAddIn addIn) { Param.AssertNotNull(addIn, "addIn"); Dictionary <string, AddInPropertyCollection> collection = this.parserSettings; if (addIn is SourceAnalyzer) { collection = this.analyzerSettings; } return(collection); }
internal UsingValidator(StyleCopAddIn sourceAnalyzer, UsingSettings usingSettings, IEnumerable<UsingDirective> usingDirectives) { this.sourceAnalyzer = sourceAnalyzer; this.usingSettings = usingSettings; this.usingDirectives = usingDirectives.ToList(); }
/// <summary> /// Initializes a new instance of the AddInPropertyCollection class. /// </summary> /// <param name="addIn">An analyzer or parser add-in.</param> internal AddInPropertyCollection(StyleCopAddIn addIn) { Param.AssertNotNull(addIn, "addIn"); this.addIn = addIn; }
/// <summary> /// Applies the properties for the given add-in. /// </summary> /// <param name="addIn"> /// The add-in. /// </param> private void ApplyProperties(StyleCopAddIn addIn) { Param.AssertNotNull(addIn, "addIn"); ICollection<BooleanProperty> addInProperties = null; if (this.properties.TryGetValue(addIn, out addInProperties)) { foreach (BooleanProperty property in addInProperties) { addIn.SetSetting(this.tabControl.LocalSettings, property); } } }
/// <summary> /// Applies settings for rules under the given node. /// </summary> /// <param name="addIn"> /// The addin owning the rules. /// </param> /// <param name="parentNode"> /// The parent node of the rules. /// </param> private void ApplyRules(StyleCopAddIn addIn, TreeNode parentNode) { Param.AssertNotNull(addIn, "addIn"); Param.AssertNotNull(parentNode, "parentNode"); foreach (TreeNode node in parentNode.Nodes) { Rule rule = node.Tag as Rule; if (rule == null) { this.ApplyRules(addIn, node); } else { addIn.SetSetting(this.tabControl.LocalSettings, new BooleanProperty(addIn, rule.Name + "#Enabled", node.Checked)); } } }
/// <summary> /// Gets the settings for the given add-in. /// </summary> /// <param name="addIn"> /// The add-in. /// </param> /// <returns> /// Returns the add-in settings or null if there are no settings for the add-in. /// </returns> public AddInPropertyCollection GetAddInSettings(StyleCopAddIn addIn) { Param.RequireNotNull(addIn, "addIn"); Dictionary<string, AddInPropertyCollection> collection = this.GetPropertyCollectionDictionary(addIn); AddInPropertyCollection settingsForAddIn; if (collection.TryGetValue(addIn.Id, out settingsForAddIn)) { return settingsForAddIn; } return null; }
public PropertyValue GetAddInSetting(StyleCopAddIn addIn, string propertyName) { Param.RequireNotNull(addIn, "addIn"); Param.RequireValidString(propertyName, "propertyName"); PropertyCollection properties = this.GetAddInSettings(addIn); if (properties != null) { return properties[propertyName]; } return null; }
/// <summary> /// Clears a setting for the given add-in. /// </summary> /// <param name="addIn"> /// The add-in. /// </param> /// <param name="propertyName"> /// The name of the property to clear. /// </param> internal void ClearAddInSettingInternal(StyleCopAddIn addIn, string propertyName) { Param.AssertNotNull(addIn, "addIn"); Param.AssertValidString(propertyName, "propertyName"); PropertyCollection properties = this.GetAddInSettings(addIn); if (properties != null) { properties.Remove(propertyName); if (properties.Count == 0) { Dictionary<string, AddInPropertyCollection> collection = this.GetPropertyCollectionDictionary(addIn); collection.Remove(addIn.Id); } } }