/// <summary>
        /// Performs the QuickFix, inserts the configured modifier into the location specified by the violation.
        /// </summary>
        /// <param name="solution">
        /// Current Solution.
        /// </param>
        /// <param name="textControl">
        /// Current Text Control to modify.
        /// </param>
        public void Execute(ISolution solution, ITextControl textControl)
        {
            JetBrains.DataFlow.LifetimeDefinition definition = JetBrains.DataFlow.Lifetimes.Define(solution.GetLifetime());
            JetBrains.DataFlow.Lifetime           lifetime   = definition.Lifetime;
            try
            {
                unsafe
                {
                    ChangeInspectionSeverityDialog dialog = new ChangeInspectionSeverityDialog(lifetime, this.commonIconsComponent);
                    IContextBoundSettingsStore     contextBoundSettingsStore =
                        this.settingsStore.BindToContextTransient(ContextRange.Smart(textControl.Document.ToDataContext()));
                    ConfigurableSeverityItem item = this.highlightingSettingsManager.GetSeverityItem(this.HighlightID);

                    dialog.Severity             = this.highlightingSettingsManager.GetConfigurableSeverity(this.HighlightID, solution);
                    dialog.SeverityOptionsTitle = string.Format(item.FullTitle + ":");
                    dialog.CanBeError           = !item.SolutionAnalysisRequired;

                    if (dialog.ShowDialog(User32Dll.GetForegroundWindow()) == true)
                    {
                        IContextBoundSettingsStore store = contextBoundSettingsStore;
                        if (dialog.SelectedSettingsLayer != null)
                        {
                            store = dialog.SelectedSettingsLayer.Model.SettingsStoreContext;
                        }

                        store.SetIndexedValue(HighlightingSettingsAccessor.InspectionSeverities, this.HighlightID, dialog.Severity);
                    }
                }
            }
            finally
            {
                definition.Terminate();
            }
        }
Exemplo n.º 2
0
        private void Register(StyleCopCore core)
        {
            Dictionary <SourceAnalyzer, List <StyleCopRule> > analyzerRulesDictionary = StyleCopRule.GetRules(core);

            var configurableSeverityItems = new List <Tuple <PsiLanguageType, ConfigurableSeverityItem> >();

            foreach (KeyValuePair <SourceAnalyzer, List <StyleCopRule> > analyzerRule in analyzerRulesDictionary)
            {
                string analyzerName     = analyzerRule.Key.Name;
                string compoundItemName = string.Format(GroupTitleTemplate, analyzerName);

                foreach (StyleCopRule rule in analyzerRule.Value)
                {
                    string ruleName    = rule.RuleID + ": " + SplitCamelCase(rule.Name);
                    string highlightID = GetHighlightID(rule.RuleID);
                    ConfigurableSeverityItem severityItem = new ConfigurableSeverityItem(
                        highlightID,
                        compoundItemName,
                        "StyleCop",
                        ruleName,
                        rule.Description,
                        Severity.WARNING,
                        false,
                        false,
                        null,
                        null);
                    configurableSeverityItems.Add(Tuple.Create((PsiLanguageType)CSharpLanguage.Instance, severityItem));
                }
            }
            this.ConfigurableSeverityItems = configurableSeverityItems;
        }
Exemplo n.º 3
0
        private static void RegisterConfigurableSeverity(
            HighlightingSettingsManager highlightManager, string highlightId, string groupName, string ruleName, string description, Severity defaultSeverity)
        {
            // TODO: This can be implemented with ICustomConfigurableSeverityItemProvider
            FieldInfo allConfigurableSeverityItems = highlightManager.GetType().GetField("myConfigurableSeverityItem", BindingFlags.Instance | BindingFlags.NonPublic);

            if (allConfigurableSeverityItems != null)
            {
                Dictionary<string, ConfigurableSeverityItem> configurableSeverityItems =
                    allConfigurableSeverityItems.GetValue(highlightManager) as Dictionary<string, ConfigurableSeverityItem>;

                if (configurableSeverityItems != null)
                {
                    if (!configurableSeverityItems.ContainsKey(highlightId))
                    {
                        ConfigurableSeverityItem item = new ConfigurableSeverityItem(highlightId, null, groupName, ruleName, description, defaultSeverity, false, false, null);
                        configurableSeverityItems.Add(highlightId, item);
                    }
                }
            }

            FieldInfo configurableSeverityImplementation = highlightManager.GetType()
                                                                           .GetField(
                                                                               "myConfigurableSeverityImplementation", BindingFlags.Instance | BindingFlags.NonPublic);

            if (configurableSeverityImplementation != null)
            {
                JetBrains.Util.OneToListMap<string, PsiLanguageType> mapToLanguage =
                    configurableSeverityImplementation.GetValue(highlightManager) as JetBrains.Util.OneToListMap<string, PsiLanguageType>;

                if (mapToLanguage != null)
                {
                    if (!mapToLanguage.ContainsKey(highlightId))
                    {
                        PsiLanguageType languageType = Languages.Instance.GetLanguageByName("CSHARP");
                        mapToLanguage.Add(highlightId, languageType);
                    }
                }
            }
        }