<commit_before>﻿namespace StyleCop.Analyzers.OrderingRules
{
    using System.Collections.Immutable;
    using Microsoft.CodeAnalysis;
    using Microsoft.CodeAnalysis.CSharp;
    using Microsoft.CodeAnalysis.Diagnostics;

    /// <summary>
    /// The keyword <c>protected</c> is positioned after the keyword <c>internal</c> within the declaration of a
    /// protected internal C# element.
    /// </summary>
    /// <remarks>
    /// <para>A violation of this rule occurs when a protected internal element's access modifiers are written as
    /// <c>internal protected</c>. In reality, an element with the keywords <c>protected internal</c> will have the same
    /// access level as an element with the keywords <c>internal protected</c>. To make the code easier to read and more
    /// consistent, StyleCop standardizes the ordering of these keywords, so that a protected internal element will
    /// always be described as such, and never as internal protected. This can help to reduce confusion about whether
    /// these access levels are indeed the same.</para>
    /// </remarks>
    [DiagnosticAnalyzer(LanguageNames.CSharp)]
    public class SA1207ProtectedMustComeBeforeInternal : DiagnosticAnalyzer
    {
        /// <summary>
        /// The ID for diagnostics produced by the <see cref="SA1207ProtectedMustComeBeforeInternal"/> analyzer.
        /// </summary>
        public const string DiagnosticId = "SA1207";
        private const string Title = "Protected must come before internal";
        private const string MessageFormat = "The keyword 'protected' must come before 'internal'.";
        private const string Description = "The keyword 'protected' is positioned after the keyword 'internal' within the declaration of a protected internal C# element.";
        private const string HelpLink = "http://www.stylecop.com/docs/SA1207.html";

        private static readonly DiagnosticDescriptor Descriptor =
            new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.OrderingRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, Description, HelpLink);

        private static readonly ImmutableArray<DiagnosticDescriptor> SupportedDiagnosticsValue =
            ImmutableArray.Create(Descriptor);

        /// <inheritdoc/>
        public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
        {
            get
            {
                return SupportedDiagnosticsValue;
            }
        }

        /// <inheritdoc/>
        public override void Initialize(AnalysisContext context)
        {
            context.RegisterSyntaxNodeActionHonorExclusions(
                HandleDeclaration,
                SyntaxKind.ClassDeclaration,
                SyntaxKind.DelegateDeclaration,
                SyntaxKind.EventDeclaration,
                SyntaxKind.EventFieldDeclaration,
                SyntaxKind.FieldDeclaration,
                SyntaxKind.IndexerDeclaration,
                SyntaxKind.InterfaceDeclaration,
                SyntaxKind.MethodDeclaration,
                SyntaxKind.PropertyDeclaration,
                SyntaxKind.StructDeclaration);
        }

        private static void HandleDeclaration(SyntaxNodeAnalysisContext context)
        {
            var childTokens = context.Node?.ChildTokens();
            if (childTokens == null)
            {
                return;
            }

            bool internalKeywordFound = false;
            foreach (var childToken in childTokens)
            {
                if (childToken.IsKind(SyntaxKind.InternalKeyword))
                {
                    internalKeywordFound = true;
                    continue;
                }

                if (childToken.IsKind(SyntaxKind.ProtectedKeyword) && internalKeywordFound)
                {
                    context.ReportDiagnostic(Diagnostic.Create(Descriptor, childToken.GetLocation()));
                    break;
                }
            }
        }
    }
}<commit_msg>SA1207 analyzer performance increased by reordering operands.<commit_after>﻿namespace StyleCop.Analyzers.OrderingRules
{
    using System.Collections.Immutable;
    using Microsoft.CodeAnalysis;
    using Microsoft.CodeAnalysis.CSharp;
    using Microsoft.CodeAnalysis.Diagnostics;

    /// <summary>
    /// The keyword <c>protected</c> is positioned after the keyword <c>internal</c> within the declaration of a
    /// protected internal C# element.
    /// </summary>
    /// <remarks>
    /// <para>A violation of this rule occurs when a protected internal element's access modifiers are written as
    /// <c>internal protected</c>. In reality, an element with the keywords <c>protected internal</c> will have the same
    /// access level as an element with the keywords <c>internal protected</c>. To make the code easier to read and more
    /// consistent, StyleCop standardizes the ordering of these keywords, so that a protected internal element will
    /// always be described as such, and never as internal protected. This can help to reduce confusion about whether
    /// these access levels are indeed the same.</para>
    /// </remarks>
    [DiagnosticAnalyzer(LanguageNames.CSharp)]
    public class SA1207ProtectedMustComeBeforeInternal : DiagnosticAnalyzer
    {
        /// <summary>
        /// The ID for diagnostics produced by the <see cref="SA1207ProtectedMustComeBeforeInternal"/> analyzer.
        /// </summary>
        public const string DiagnosticId = "SA1207";
        private const string Title = "Protected must come before internal";
        private const string MessageFormat = "The keyword 'protected' must come before 'internal'.";
        private const string Description = "The keyword 'protected' is positioned after the keyword 'internal' within the declaration of a protected internal C# element.";
        private const string HelpLink = "http://www.stylecop.com/docs/SA1207.html";

        private static readonly DiagnosticDescriptor Descriptor =
            new DiagnosticDescriptor(DiagnosticId, Title, MessageFormat, AnalyzerCategory.OrderingRules, DiagnosticSeverity.Warning, AnalyzerConstants.EnabledByDefault, Description, HelpLink);

        private static readonly ImmutableArray<DiagnosticDescriptor> SupportedDiagnosticsValue =
            ImmutableArray.Create(Descriptor);

        /// <inheritdoc/>
        public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
        {
            get
            {
                return SupportedDiagnosticsValue;
            }
        }

        /// <inheritdoc/>
        public override void Initialize(AnalysisContext context)
        {
            context.RegisterSyntaxNodeActionHonorExclusions(
                HandleDeclaration,
                SyntaxKind.ClassDeclaration,
                SyntaxKind.DelegateDeclaration,
                SyntaxKind.EventDeclaration,
                SyntaxKind.EventFieldDeclaration,
                SyntaxKind.FieldDeclaration,
                SyntaxKind.IndexerDeclaration,
                SyntaxKind.InterfaceDeclaration,
                SyntaxKind.MethodDeclaration,
                SyntaxKind.PropertyDeclaration,
                SyntaxKind.StructDeclaration);
        }

        private static void HandleDeclaration(SyntaxNodeAnalysisContext context)
        {
            var childTokens = context.Node?.ChildTokens();
            if (childTokens == null)
            {
                return;
            }

            bool internalKeywordFound = false;
            foreach (var childToken in childTokens)
            {
                if (childToken.IsKind(SyntaxKind.InternalKeyword))
                {
                    internalKeywordFound = true;
                    continue;
                }

                if (internalKeywordFound && childToken.IsKind(SyntaxKind.ProtectedKeyword))
                {
                    context.ReportDiagnostic(Diagnostic.Create(Descriptor, childToken.GetLocation()));
                    break;
                }
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.07420713577799802, 'fraction_numerical': 0.0044598612487611496, 'mean_word_length': 2.2526188557614826, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1094264', 'n_tokens_mistral': 1866, 'n_tokens_neox': 1764, 'n_words': 542}