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; }
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); }
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())); } } }
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())); } } }
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; }
public bool AppliesTo(ISymbol symbol, ISymbolCategorizationService categorizationService) { return SymbolSpecification.AppliesTo(symbol, categorizationService); }