internal bool AppliesTo(ISymbol symbol, ISymbolCategorizationService categorizationService)
        {
            if (ApplicableSymbolKindList.Any() && !ApplicableSymbolKindList.Any(k => k.AppliesTo(symbol)))
            {
                return(false);
            }

            if (!RequiredModifierList.All(m => m.MatchesSymbol(symbol)))
            {
                return(false);
            }

            if (ApplicableAccessibilityList.Any() && !ApplicableAccessibilityList.Any(k => k.MatchesSymbol(symbol)))
            {
                return(false);
            }

            // TODO: More efficient to find the categorizers that are relevant and only check those
            var applicableCategories = categorizationService.GetCategorizers().SelectMany(c => c.Categorize(symbol));

            if (!RequiredCustomTagList.All(t => applicableCategories.Contains(t)))
            {
                return(false);
            }

            return(true);
        }
        internal bool AppliesTo(ISymbol symbol, ISymbolCategorizationService categorizationService)
        {
            if (ApplicableSymbolKindList.Any() && !ApplicableSymbolKindList.Any(k => k.AppliesTo(symbol)))
            {
                return false;
            }

            if (!RequiredModifierList.All(m => m.MatchesSymbol(symbol)))
            {
                return false;
            }

            if (ApplicableAccessibilityList.Any() && !ApplicableAccessibilityList.Any(k => k.MatchesSymbol(symbol)))
            {
                return false;
            }

            // TODO: More efficient to find the categorizers that are relevant and only check those
            var applicableCategories = categorizationService.GetCategorizers().SelectMany(c => c.Categorize(symbol));
            if (!RequiredCustomTagList.All(t => applicableCategories.Contains(t)))
            {
                return false;
            }

            return true;
        }
Beispiel #3
0
        internal NamingRule GetBestMatchingRule(ISymbol symbol, ISymbolCategorizationService categorizationService)
        {
            Debug.Assert(SymbolSpecification.AppliesTo(symbol, categorizationService));
            var matchingChild = Children.FirstOrDefault(r => r.AppliesTo(symbol, categorizationService));

            return(matchingChild?.GetBestMatchingRule(symbol, categorizationService) ?? this);
        }
Beispiel #4
0
        internal bool TryGetApplicableRule(ISymbol symbol, ISymbolCategorizationService categorizationService, out NamingRule applicableRule)
        {
            if (NamingRules == null)
            {
                applicableRule = null;
                return(false);
            }

            if (!IsSymbolNameAnalyzable(symbol))
            {
                applicableRule = null;
                return(false);
            }

            var matchingRule = NamingRules.FirstOrDefault(r => r.AppliesTo(symbol, categorizationService));

            if (matchingRule == null)
            {
                applicableRule = null;
                return(false);
            }

            applicableRule = matchingRule.GetBestMatchingRule(symbol, categorizationService);
            return(true);
        }
        internal bool TryGetApplicableRule(ISymbol symbol, ISymbolCategorizationService categorizationService, out NamingRule applicableRule)
        {
            if (NamingRules == null)
            {
                applicableRule = null;
                return false;
            }

            var matchingRule = NamingRules.FirstOrDefault(r => r.AppliesTo(symbol, categorizationService));
            if (matchingRule == null)
            {
                applicableRule = null;
                return false;
            }

            applicableRule = matchingRule.GetBestMatchingRule(symbol, categorizationService);
            return true;
        }
        private void SymbolAction(SymbolAnalysisContext context, NamingStylePreferencesInfo preferences, ISymbolCategorizationService categorizationService)
        {
            NamingRule applicableRule;
            if (preferences.TryGetApplicableRule(context.Symbol, categorizationService, out applicableRule))
            {
                string failureReason;
                if (applicableRule.EnforcementLevel != DiagnosticSeverity.Hidden &&
                    !applicableRule.IsNameCompliant(context.Symbol.Name, out failureReason))
                {
                    var descriptor = new DiagnosticDescriptor(IDEDiagnosticIds.NamingRuleId,
                         s_localizableTitleNamingStyle,
                         string.Format(FeaturesResources._0_naming_violation_1, applicableRule.Title, failureReason),
                         DiagnosticCategory.Style,
                         applicableRule.EnforcementLevel,
                         isEnabledByDefault: true);

                    var builder = ImmutableDictionary.CreateBuilder<string, string>();
                    builder[nameof(NamingStyle)] = applicableRule.NamingStyle.CreateXElement().ToString();
                    builder["OptionName"] = nameof(SimplificationOptions.NamingPreferences);
                    builder["OptionLanguage"] = context.Compilation.Language;
                    context.ReportDiagnostic(Diagnostic.Create(descriptor, context.Symbol.Locations.First(), builder.ToImmutable()));
                }
            }
        }
Beispiel #7
0
 public bool AppliesTo(ISymbol symbol, ISymbolCategorizationService categorizationService)
 {
     return(SymbolSpecification.AppliesTo(symbol, categorizationService));
 }
        private void SymbolAction(SymbolAnalysisContext context, NamingStylePreferencesInfo preferences, ISymbolCategorizationService categorizationService)
        {
            NamingRule applicableRule;

            if (preferences.TryGetApplicableRule(context.Symbol, categorizationService, out applicableRule))
            {
                string failureReason;
                if (applicableRule.EnforcementLevel != DiagnosticSeverity.Hidden &&
                    !applicableRule.IsNameCompliant(context.Symbol.Name, out failureReason))
                {
                    var descriptor = new DiagnosticDescriptor(IDEDiagnosticIds.NamingRuleId,
                                                              s_localizableTitleNamingStyle,
                                                              string.Format(FeaturesResources._0_naming_violation_1, applicableRule.Title, failureReason),
                                                              DiagnosticCategory.Style,
                                                              applicableRule.EnforcementLevel,
                                                              isEnabledByDefault: true);

                    var builder = ImmutableDictionary.CreateBuilder <string, string>();
                    builder[nameof(NamingStyle)] = applicableRule.NamingStyle.CreateXElement().ToString();
                    builder["OptionName"]        = nameof(SimplificationOptions.NamingPreferences);
                    builder["OptionLanguage"]    = context.Compilation.Language;
                    context.ReportDiagnostic(Diagnostic.Create(descriptor, context.Symbol.Locations.First(), builder.ToImmutable()));
                }
            }
        }
Beispiel #9
0
 internal NamingRule GetBestMatchingRule(ISymbol symbol, ISymbolCategorizationService categorizationService)
 {
     Debug.Assert(SymbolSpecification.AppliesTo(symbol, categorizationService));
     var matchingChild = Children.FirstOrDefault(r => r.AppliesTo(symbol, categorizationService));
     return matchingChild?.GetBestMatchingRule(symbol, categorizationService) ?? this;
 }
Beispiel #10
0
 public bool AppliesTo(ISymbol symbol, ISymbolCategorizationService categorizationService)
 {
     return SymbolSpecification.AppliesTo(symbol, categorizationService);
 }