private void AnalyzeMemberDeclaration(SyntaxNodeAnalysisContext context) { if (GeneratedCodeAnalyzer?.IsGeneratedCode(context) == true) { return; } var declaration = (MemberDeclarationSyntax)context.Node; SyntaxTokenList modifiers = declaration.GetModifiers(); if (modifiers.Count > 1 && !ModifierUtility.IsSorted(modifiers) && !declaration.ContainsDirectives(modifiers.Span)) { context.ReportDiagnostic( DiagnosticDescriptors.ReorderModifiers, Location.Create(context.Node.SyntaxTree, modifiers.Span)); } AccessModifier accessModifier = GetAccessModifier(context, declaration, modifiers); if (accessModifier != AccessModifier.None) { Location location = GetLocation(declaration); if (location != null) { context.ReportDiagnostic( DiagnosticDescriptors.AddDefaultAccessModifier, location, ImmutableDictionary.CreateRange(new KeyValuePair <string, string>[] { new KeyValuePair <string, string>(nameof(AccessModifier), accessModifier.ToString()) })); } } }
private static SyntaxTokenList CreateModifiers(SyntaxTokenList modifiers) { modifiers = RemoveVirtualKeywordIfPresent(modifiers); modifiers = AddAbstractKeywordIfNotPresent(modifiers); if (!ModifierUtility.IsSorted(modifiers)) { modifiers = TokenList(modifiers.OrderBy(f => f, ModifierComparer.Instance)); } return(modifiers); }