Exemplo n.º 1
0
        private static SyntaxNode OrderMember(MemberOrderHelper memberOrder, SyntaxList <MemberDeclarationSyntax> members, ElementOrderingChecks checks, SyntaxNode syntaxRoot, IndentationOptions indentationOptions)
        {
            var memberIndex          = members.IndexOf(memberOrder.Member);
            MemberOrderHelper target = default(MemberOrderHelper);

            for (var i = memberIndex - 1; i >= 0; --i)
            {
                var orderHelper = new MemberOrderHelper(members[i], checks);
                if (orderHelper.Priority < memberOrder.Priority)
                {
                    target = orderHelper;
                }
                else
                {
                    break;
                }
            }

            return(target.Member != null?MoveMember(syntaxRoot, memberOrder.Member, target.Member, indentationOptions) : syntaxRoot);
        }
        private static SyntaxNode OrderMember(MemberOrderHelper memberOrder, SyntaxList <MemberDeclarationSyntax> members, ImmutableArray <OrderingTrait> elementOrder, SyntaxNode syntaxRoot, IndentationSettings indentationSettings)
        {
            var memberIndex          = members.IndexOf(memberOrder.Member);
            MemberOrderHelper target = default;

            for (var i = memberIndex - 1; i >= 0; --i)
            {
                var orderHelper = new MemberOrderHelper(members[i], elementOrder);
                if (orderHelper.Priority < memberOrder.Priority)
                {
                    target = orderHelper;
                }
                else
                {
                    break;
                }
            }

            return(target.Member != null?MoveMember(syntaxRoot, memberOrder.Member, target.Member, indentationSettings) : syntaxRoot);
        }
Exemplo n.º 3
0
        private static SyntaxNode MoveField(FieldDeclarationSyntax fieldDeclaration, TypeDeclarationSyntax typeDeclarationNode, SyntaxNode syntaxRoot)
        {
            var fieldToMove = new MemberOrderHelper(fieldDeclaration);

            foreach (var member in typeDeclarationNode.Members)
            {
                if (!member.IsKind(SyntaxKind.FieldDeclaration))
                {
                    continue;
                }

                var orderHelper = new MemberOrderHelper(member);
                if (orderHelper.ModifierPriority < fieldToMove.ModifierPriority)
                {
                    syntaxRoot = MoveField(syntaxRoot, fieldToMove.Member, member);
                    break;
                }
            }

            return(syntaxRoot);
        }
Exemplo n.º 4
0
        private static SyntaxNode UpdateSyntaxRoot(MemberDeclarationSyntax memberDeclaration, ElementOrderingChecks checks, SyntaxNode syntaxRoot, IndentationOptions indentationOptions)
        {
            var parentDeclaration = memberDeclaration.Parent;
            var memberToMove      = new MemberOrderHelper(memberDeclaration, checks);

            if (parentDeclaration is TypeDeclarationSyntax)
            {
                return(HandleTypeDeclaration(memberToMove, (TypeDeclarationSyntax)parentDeclaration, checks, syntaxRoot, indentationOptions));
            }

            if (parentDeclaration is NamespaceDeclarationSyntax)
            {
                return(HandleNamespaceDeclaration(memberToMove, (NamespaceDeclarationSyntax)parentDeclaration, checks, syntaxRoot, indentationOptions));
            }

            if (parentDeclaration is CompilationUnitSyntax)
            {
                return(HandleCompilationUnitDeclaration(memberToMove, (CompilationUnitSyntax)parentDeclaration, checks, syntaxRoot, indentationOptions));
            }

            return(syntaxRoot);
        }
        private static SyntaxNode UpdateSyntaxRoot(MemberDeclarationSyntax memberDeclaration, ImmutableArray<OrderingTrait> elementOrder, SyntaxNode syntaxRoot, IndentationOptions indentationOptions)
        {
            var parentDeclaration = memberDeclaration.Parent;
            var memberToMove = new MemberOrderHelper(memberDeclaration, elementOrder);

            if (parentDeclaration is TypeDeclarationSyntax)
            {
                return HandleTypeDeclaration(memberToMove, (TypeDeclarationSyntax)parentDeclaration, elementOrder, syntaxRoot, indentationOptions);
            }

            if (parentDeclaration is NamespaceDeclarationSyntax)
            {
                return HandleNamespaceDeclaration(memberToMove, (NamespaceDeclarationSyntax)parentDeclaration, elementOrder, syntaxRoot, indentationOptions);
            }

            if (parentDeclaration is CompilationUnitSyntax)
            {
                return HandleCompilationUnitDeclaration(memberToMove, (CompilationUnitSyntax)parentDeclaration, elementOrder, syntaxRoot, indentationOptions);
            }

            return syntaxRoot;
        }
        private static SyntaxNode UpdateSyntaxRoot(MemberDeclarationSyntax memberDeclaration, ImmutableArray <OrderingTrait> elementOrder, SyntaxNode syntaxRoot, IndentationSettings indentationSettings)
        {
            var parentDeclaration = memberDeclaration.Parent;
            var memberToMove      = new MemberOrderHelper(memberDeclaration, elementOrder);

            if (parentDeclaration is TypeDeclarationSyntax)
            {
                return(HandleTypeDeclaration(memberToMove, (TypeDeclarationSyntax)parentDeclaration, elementOrder, syntaxRoot, indentationSettings));
            }

            if (parentDeclaration is NamespaceDeclarationSyntax)
            {
                return(HandleNamespaceDeclaration(memberToMove, (NamespaceDeclarationSyntax)parentDeclaration, elementOrder, syntaxRoot, indentationSettings));
            }

            if (parentDeclaration is CompilationUnitSyntax)
            {
                return(HandleCompilationUnitDeclaration(memberToMove, (CompilationUnitSyntax)parentDeclaration, elementOrder, syntaxRoot, indentationSettings));
            }

            return(syntaxRoot);
        }
 private static SyntaxNode HandleCompilationUnitDeclaration(MemberOrderHelper memberOrder, CompilationUnitSyntax compilationUnitDeclaration, ImmutableArray <OrderingTrait> elementOrder, SyntaxNode syntaxRoot, IndentationSettings indentationSettings)
 {
     return(OrderMember(memberOrder, compilationUnitDeclaration.Members, elementOrder, syntaxRoot, indentationSettings));
 }
 private static SyntaxNode HandleTypeDeclaration(MemberOrderHelper memberOrder, TypeDeclarationSyntax typeDeclarationNode, ImmutableArray <OrderingTrait> elementOrder, SyntaxNode syntaxRoot, IndentationSettings indentationSettings)
 {
     return(OrderMember(memberOrder, typeDeclarationNode.Members, elementOrder, syntaxRoot, indentationSettings));
 }
Exemplo n.º 9
0
        private static void HandleTypeDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
        {
            var elementOrder  = settings.OrderingRules.ElementOrder;
            int constantIndex = elementOrder.IndexOf(OrderingTrait.Constant);

            if (constantIndex < 0)
            {
                return;
            }

            var typeDeclaration = (TypeDeclarationSyntax)context.Node;

            var members = typeDeclaration.Members;
            var previousFieldConstant = true;
            var previousFieldStatic   = false;
            var previousFieldReadonly = false;
            var previousAccessLevel   = AccessLevel.NotSpecified;

            foreach (var member in members)
            {
                var field = member as FieldDeclarationSyntax;
                if (field == null)
                {
                    continue;
                }

                AccessLevel currentAccessLevel   = MemberOrderHelper.GetAccessLevelForOrdering(field, field.Modifiers);
                bool        currentFieldConstant = field.Modifiers.Any(SyntaxKind.ConstKeyword);
                bool        currentFieldReadonly = currentFieldConstant || field.Modifiers.Any(SyntaxKind.ReadOnlyKeyword);
                bool        currentFieldStatic   = currentFieldConstant || field.Modifiers.Any(SyntaxKind.StaticKeyword);
                bool        compareConst         = true;
                for (int j = 0; compareConst && j < constantIndex; j++)
                {
                    switch (elementOrder[j])
                    {
                    case OrderingTrait.Accessibility:
                        if (currentAccessLevel != previousAccessLevel)
                        {
                            compareConst = false;
                        }

                        continue;

                    case OrderingTrait.Readonly:
                        if (currentFieldReadonly != previousFieldReadonly)
                        {
                            compareConst = false;
                        }

                        continue;

                    case OrderingTrait.Static:
                        if (currentFieldStatic != previousFieldStatic)
                        {
                            compareConst = false;
                        }

                        continue;

                    case OrderingTrait.Kind:
                        // Only fields may be marked const, and all fields have the same kind.
                        continue;

                    case OrderingTrait.Constant:
                    default:
                        continue;
                    }
                }

                if (compareConst)
                {
                    if (!previousFieldConstant && currentFieldConstant)
                    {
                        context.ReportDiagnostic(Diagnostic.Create(Descriptor, NamedTypeHelpers.GetNameOrIdentifierLocation(member)));
                    }
                }

                previousFieldConstant = currentFieldConstant;
                previousFieldReadonly = currentFieldReadonly;
                previousFieldStatic   = currentFieldStatic;
                previousAccessLevel   = currentAccessLevel;
            }
        }
Exemplo n.º 10
0
        private static void HandleMemberList(SyntaxNodeAnalysisContext context, ImmutableArray <OrderingTrait> elementOrder, int staticIndex, SyntaxList <MemberDeclarationSyntax> members)
        {
            var previousSyntaxKind     = SyntaxKind.None;
            var previousAccessLevel    = AccessLevel.NotSpecified;
            var previousMemberStatic   = true;
            var previousMemberConstant = false;
            var previousMemberReadonly = false;

            foreach (var member in members)
            {
                var modifiers = member.GetModifiers();

                var currentSyntaxKind = member.Kind();
                currentSyntaxKind = currentSyntaxKind == SyntaxKind.EventFieldDeclaration ? SyntaxKind.EventDeclaration : currentSyntaxKind;
                var  currentAccessLevel    = MemberOrderHelper.GetAccessLevelForOrdering(member, modifiers);
                bool currentMemberConstant = modifiers.Any(SyntaxKind.ConstKeyword);
                bool currentMemberReadonly = currentMemberConstant || modifiers.Any(SyntaxKind.ReadOnlyKeyword);
                bool currentMemberStatic   = currentMemberConstant || modifiers.Any(SyntaxKind.StaticKeyword);
                bool compareStatic         = true;
                for (int j = 0; compareStatic && j < staticIndex; j++)
                {
                    switch (elementOrder[j])
                    {
                    case OrderingTrait.Accessibility:
                        if (currentAccessLevel != previousAccessLevel)
                        {
                            compareStatic = false;
                        }

                        continue;

                    case OrderingTrait.Readonly:
                        if (currentMemberReadonly != previousMemberReadonly)
                        {
                            compareStatic = false;
                        }

                        continue;

                    case OrderingTrait.Constant:
                        if (currentMemberConstant != previousMemberConstant)
                        {
                            compareStatic = false;
                        }

                        continue;

                    case OrderingTrait.Kind:
                        if (previousSyntaxKind != currentSyntaxKind)
                        {
                            compareStatic = false;
                        }

                        continue;

                    case OrderingTrait.Static:
                    default:
                        continue;
                    }
                }

                if (compareStatic)
                {
                    if (currentMemberStatic && !previousMemberStatic)
                    {
                        context.ReportDiagnostic(
                            Diagnostic.Create(
                                Descriptor,
                                NamedTypeHelpers.GetNameOrIdentifierLocation(member),
                                AccessLevelHelper.GetName(currentAccessLevel)));
                    }
                }

                previousSyntaxKind     = currentSyntaxKind;
                previousAccessLevel    = currentAccessLevel;
                previousMemberStatic   = currentMemberStatic;
                previousMemberConstant = currentMemberConstant;
                previousMemberReadonly = currentMemberReadonly;
            }
        }
 private static SyntaxNode HandleTypeDeclaration(MemberOrderHelper memberOrder, TypeDeclarationSyntax typeDeclarationNode, ImmutableArray<OrderingTrait> elementOrder, SyntaxNode syntaxRoot, IndentationOptions indentationOptions)
 {
     return OrderMember(memberOrder, typeDeclarationNode.Members, elementOrder, syntaxRoot, indentationOptions);
 }
 private static SyntaxNode HandleCompilationUnitDeclaration(MemberOrderHelper memberOrder, CompilationUnitSyntax compilationUnitDeclaration, ElementOrderingChecks checks, SyntaxNode syntaxRoot, IndentationOptions indentationOptions)
 {
     return OrderMember(memberOrder, compilationUnitDeclaration.Members, checks, syntaxRoot, indentationOptions);
 }
Exemplo n.º 13
0
        private static void HandleMemberList(SyntaxNodeAnalysisContext context, ImmutableArray <OrderingTrait> elementOrder, int kindIndex, SyntaxList <MemberDeclarationSyntax> members, ImmutableArray <SyntaxKind> order)
        {
            for (int i = 0; i < members.Count - 1; i++)
            {
                if (members[i + 1].IsKind(SyntaxKind.IncompleteMember))
                {
                    i++;
                    continue;
                }

                if (members[i].IsKind(SyntaxKind.IncompleteMember))
                {
                    continue;
                }

                bool compareKind = true;
                for (int j = 0; compareKind && j < kindIndex; j++)
                {
                    switch (elementOrder[j])
                    {
                    case OrderingTrait.Accessibility:
                        if (MemberOrderHelper.GetAccessLevelForOrdering(members[i + 1], members[i + 1].GetModifiers())
                            != MemberOrderHelper.GetAccessLevelForOrdering(members[i], members[i].GetModifiers()))
                        {
                            compareKind = false;
                        }

                        continue;

                    case OrderingTrait.Constant:
                    case OrderingTrait.Readonly:
                        // Only fields may be marked const or readonly, and all fields have the same kind.
                        continue;

                    case OrderingTrait.Static:
                        bool currentIsStatic = members[i].GetModifiers().Any(SyntaxKind.StaticKeyword);
                        bool nextIsStatic    = members[i + 1].GetModifiers().Any(SyntaxKind.StaticKeyword);
                        if (currentIsStatic != nextIsStatic)
                        {
                            compareKind = false;
                        }

                        continue;

                    case OrderingTrait.Kind:
                    default:
                        continue;
                    }
                }

                if (!compareKind)
                {
                    continue;
                }

                var elementSyntaxKind = members[i].Kind();
                elementSyntaxKind = elementSyntaxKind == SyntaxKind.EventFieldDeclaration ? SyntaxKind.EventDeclaration : elementSyntaxKind;
                int index = order.IndexOf(elementSyntaxKind);

                var nextElementSyntaxKind = members[i + 1].Kind();
                nextElementSyntaxKind = nextElementSyntaxKind == SyntaxKind.EventFieldDeclaration ? SyntaxKind.EventDeclaration : nextElementSyntaxKind;
                int nextIndex = order.IndexOf(nextElementSyntaxKind);

                if (index > nextIndex)
                {
                    context.ReportDiagnostic(Diagnostic.Create(Descriptor, NamedTypeHelpers.GetNameOrIdentifierLocation(members[i + 1]), MemberNames[nextElementSyntaxKind], MemberNames[elementSyntaxKind]));
                }
            }
        }
 private static SyntaxNode HandleNamespaceDeclaration(MemberOrderHelper memberOrder, NamespaceDeclarationSyntax namespaceDeclaration, ImmutableArray <OrderingTrait> elementOrder, SyntaxNode syntaxRoot, IndentationSettings indentationSettings)
 {
     return(OrderMember(memberOrder, namespaceDeclaration.Members, elementOrder, syntaxRoot, indentationSettings));
 }
 private static SyntaxNode HandleNamespaceDeclaration(MemberOrderHelper memberOrder, NamespaceDeclarationSyntax namespaceDeclaration, ElementOrderingChecks checks, SyntaxNode syntaxRoot, IndentationOptions indentationOptions)
 {
     return OrderMember(memberOrder, namespaceDeclaration.Members, checks, syntaxRoot, indentationOptions);
 }
Exemplo n.º 16
0
 private static SyntaxNode HandleNamespaceDeclaration(MemberOrderHelper memberOrder, NamespaceDeclarationSyntax namespaceDeclaration, ElementOrderingChecks checks, SyntaxNode syntaxRoot, IndentationOptions indentationOptions)
 {
     return(OrderMember(memberOrder, namespaceDeclaration.Members, checks, syntaxRoot, indentationOptions));
 }
Exemplo n.º 17
0
 private static SyntaxNode HandleCompilationUnitDeclaration(MemberOrderHelper memberOrder, CompilationUnitSyntax compilationUnitDeclaration, ElementOrderingChecks checks, SyntaxNode syntaxRoot, IndentationOptions indentationOptions)
 {
     return(OrderMember(memberOrder, compilationUnitDeclaration.Members, checks, syntaxRoot, indentationOptions));
 }
Exemplo n.º 18
0
 private static SyntaxNode HandleTypeDeclaration(MemberOrderHelper memberOrder, TypeDeclarationSyntax typeDeclarationNode, ElementOrderingChecks checks, SyntaxNode syntaxRoot, IndentationOptions indentationOptions)
 {
     return(OrderMember(memberOrder, typeDeclarationNode.Members, checks, syntaxRoot, indentationOptions));
 }
        private static void HandleTypeDeclaration(SyntaxNodeAnalysisContext context, StyleCopSettings settings)
        {
            var elementOrder  = settings.OrderingRules.ElementOrder;
            int readonlyIndex = elementOrder.IndexOf(OrderingTrait.Readonly);

            if (readonlyIndex < 0)
            {
                return;
            }

            var typeDeclaration = (TypeDeclarationSyntax)context.Node;

            // This variable is null when the previous member is not a field.
            FieldDeclarationSyntax previousField = null;
            var previousFieldConst    = true;
            var previousFieldStatic   = false;
            var previousFieldReadonly = false;
            var previousAccessLevel   = AccessLevel.NotSpecified;

            foreach (var member in typeDeclaration.Members)
            {
                FieldDeclarationSyntax field = member as FieldDeclarationSyntax;
                if (field == null)
                {
                    previousField = null;
                    continue;
                }

                var  modifiers            = member.GetModifiers();
                var  currentAccessLevel   = MemberOrderHelper.GetAccessLevelForOrdering(member, modifiers);
                bool currentFieldConst    = modifiers.Any(SyntaxKind.ConstKeyword);
                bool currentFieldStatic   = currentFieldConst || modifiers.Any(SyntaxKind.StaticKeyword);
                bool currentFieldReadonly = currentFieldConst || modifiers.Any(SyntaxKind.ReadOnlyKeyword);
                if (previousField == null)
                {
                    previousField         = field;
                    previousFieldConst    = currentFieldConst;
                    previousFieldStatic   = currentFieldStatic;
                    previousFieldReadonly = currentFieldReadonly;
                    previousAccessLevel   = currentAccessLevel;
                    continue;
                }

                bool compareReadonly = true;
                for (int j = 0; compareReadonly && j < readonlyIndex; j++)
                {
                    switch (elementOrder[j])
                    {
                    case OrderingTrait.Kind:
                        // This analyzer only ever looks at sequences of fields.
                        continue;

                    case OrderingTrait.Accessibility:
                        if (previousAccessLevel != currentAccessLevel)
                        {
                            compareReadonly = false;
                        }

                        continue;

                    case OrderingTrait.Constant:
                        if (previousFieldConst != currentFieldConst)
                        {
                            compareReadonly = false;
                        }

                        continue;

                    case OrderingTrait.Static:
                        if (previousFieldStatic != currentFieldStatic)
                        {
                            compareReadonly = false;
                        }

                        continue;

                    case OrderingTrait.Readonly:
                    default:
                        continue;
                    }
                }

                if (compareReadonly)
                {
                    if (currentFieldReadonly && !previousFieldReadonly)
                    {
                        context.ReportDiagnostic(Diagnostic.Create(Descriptor, NamedTypeHelpers.GetNameOrIdentifierLocation(member)));
                    }
                }

                previousField         = field;
                previousFieldConst    = currentFieldConst;
                previousFieldStatic   = currentFieldStatic;
                previousFieldReadonly = currentFieldReadonly;
                previousAccessLevel   = currentAccessLevel;
            }
        }
 private static SyntaxNode HandleCompilationUnitDeclaration(MemberOrderHelper memberOrder, CompilationUnitSyntax compilationUnitDeclaration, ImmutableArray<OrderingTrait> elementOrder, SyntaxNode syntaxRoot, IndentationOptions indentationOptions)
 {
     return OrderMember(memberOrder, compilationUnitDeclaration.Members, elementOrder, syntaxRoot, indentationOptions);
 }
 private static SyntaxNode HandleNamespaceDeclaration(MemberOrderHelper memberOrder, NamespaceDeclarationSyntax namespaceDeclaration, ImmutableArray<OrderingTrait> elementOrder, SyntaxNode syntaxRoot, IndentationOptions indentationOptions)
 {
     return OrderMember(memberOrder, namespaceDeclaration.Members, elementOrder, syntaxRoot, indentationOptions);
 }
Exemplo n.º 22
0
        private static void HandleMemberList(SyntaxNodeAnalysisContext context, ImmutableArray <OrderingTrait> elementOrder, int accessibilityIndex, SyntaxList <MemberDeclarationSyntax> members)
        {
            var  previousSyntaxKind  = SyntaxKind.None;
            var  previousAccessLevel = AccessLevel.NotSpecified;
            bool previousIsConst     = false;
            bool previousIsReadonly  = false;
            bool previousIsStatic    = false;

            foreach (var member in members)
            {
                var currentSyntaxKind = member.Kind();
                currentSyntaxKind = currentSyntaxKind == SyntaxKind.EventFieldDeclaration ? SyntaxKind.EventDeclaration : currentSyntaxKind;

                // if the SyntaxKind of this member (e.g. SyntaxKind.IncompleteMember) will not
                // be handled, skip early.
                if (!MemberKinds.Contains(currentSyntaxKind))
                {
                    continue;
                }

                var         modifiers          = member.GetModifiers();
                AccessLevel currentAccessLevel = MemberOrderHelper.GetAccessLevelForOrdering(member, modifiers);
                bool        currentIsConst     = modifiers.Any(SyntaxKind.ConstKeyword);
                bool        currentIsReadonly  = modifiers.Any(SyntaxKind.ReadOnlyKeyword);
                bool        currentIsStatic    = modifiers.Any(SyntaxKind.StaticKeyword);

                if (previousAccessLevel != AccessLevel.NotSpecified)
                {
                    bool compareAccessLevel = true;
                    for (int j = 0; compareAccessLevel && j < accessibilityIndex; j++)
                    {
                        switch (elementOrder[j])
                        {
                        case OrderingTrait.Kind:
                            if (previousSyntaxKind != currentSyntaxKind)
                            {
                                compareAccessLevel = false;
                            }

                            continue;

                        case OrderingTrait.Constant:
                            if (previousIsConst != currentIsConst)
                            {
                                compareAccessLevel = false;
                            }

                            continue;

                        case OrderingTrait.Readonly:
                            if (previousIsReadonly != currentIsReadonly)
                            {
                                compareAccessLevel = false;
                            }

                            continue;

                        case OrderingTrait.Static:
                            if (previousIsStatic != currentIsStatic)
                            {
                                compareAccessLevel = false;
                            }

                            continue;

                        case OrderingTrait.Accessibility:
                        default:
                            continue;
                        }
                    }

                    if (compareAccessLevel && currentAccessLevel > previousAccessLevel)
                    {
                        context.ReportDiagnostic(
                            Diagnostic.Create(
                                Descriptor,
                                NamedTypeHelpers.GetNameOrIdentifierLocation(member),
                                AccessLevelHelper.GetName(currentAccessLevel),
                                AccessLevelHelper.GetName(previousAccessLevel)));
                    }
                }

                previousSyntaxKind  = currentSyntaxKind;
                previousAccessLevel = currentAccessLevel;
                previousIsConst     = currentIsConst;
                previousIsReadonly  = currentIsReadonly;
                previousIsStatic    = currentIsStatic;
            }
        }
        private static SyntaxNode OrderMember(MemberOrderHelper memberOrder, SyntaxList<MemberDeclarationSyntax> members, ImmutableArray<OrderingTrait> elementOrder, SyntaxNode syntaxRoot, IndentationOptions indentationOptions)
        {
            var memberIndex = members.IndexOf(memberOrder.Member);
            MemberOrderHelper target = default(MemberOrderHelper);

            for (var i = memberIndex - 1; i >= 0; --i)
            {
                var orderHelper = new MemberOrderHelper(members[i], elementOrder);
                if (orderHelper.Priority < memberOrder.Priority)
                {
                    target = orderHelper;
                }
                else
                {
                    break;
                }
            }

            return target.Member != null ? MoveMember(syntaxRoot, memberOrder.Member, target.Member, indentationOptions) : syntaxRoot;
        }
Exemplo n.º 24
0
        private static void HandleMemberList(SyntaxNodeAnalysisContext context, ImmutableArray <OrderingTrait> elementOrder, int kindIndex, SyntaxList <MemberDeclarationSyntax> members, ImmutableArray <SyntaxKind> order)
        {
            for (int i = 0; i < members.Count - 1; i++)
            {
                if (members[i + 1].IsKind(SyntaxKind.IncompleteMember))
                {
                    i++;
                    continue;
                }

                if (members[i].IsKind(SyntaxKind.IncompleteMember))
                {
                    continue;
                }

                bool compareKind = true;
                for (int j = 0; compareKind && j < kindIndex; j++)
                {
                    switch (elementOrder[j])
                    {
                    case OrderingTrait.Accessibility:
                        if (MemberOrderHelper.GetAccessLevelForOrdering(members[i + 1], members[i + 1].GetModifiers())
                            != MemberOrderHelper.GetAccessLevelForOrdering(members[i], members[i].GetModifiers()))
                        {
                            compareKind = false;
                        }

                        continue;

                    case OrderingTrait.Constant:
                    case OrderingTrait.Readonly:
                        // Only fields may be marked const or readonly, and all fields have the same kind.
                        continue;

                    case OrderingTrait.Static:
                        bool currentIsStatic = members[i].GetModifiers().Any(SyntaxKind.StaticKeyword);
                        bool nextIsStatic    = members[i + 1].GetModifiers().Any(SyntaxKind.StaticKeyword);
                        if (currentIsStatic != nextIsStatic)
                        {
                            compareKind = false;
                        }

                        continue;

                    case OrderingTrait.Kind:
                    default:
                        continue;
                    }
                }

                if (!compareKind)
                {
                    continue;
                }

                var elementSyntaxKind = members[i].Kind();
                int index             = order.IndexOf(GetSyntaxKindForOrdering(elementSyntaxKind));

                var nextElementSyntaxKind = members[i + 1].Kind();
                int nextIndex             = order.IndexOf(GetSyntaxKindForOrdering(nextElementSyntaxKind));

                if (index > nextIndex)
                {
                    // [Issue #3160] Added hardening here to make sure that this won't crash when working with invalid code.
                    var nextElementMemberName = MemberNames.GetValueOrDefault(nextElementSyntaxKind, "<unknown>");
                    var elementMemberName     = MemberNames.GetValueOrDefault(elementSyntaxKind, "<unknown>");

                    context.ReportDiagnostic(Diagnostic.Create(Descriptor, NamedTypeHelpers.GetNameOrIdentifierLocation(members[i + 1]), nextElementMemberName, elementMemberName));
                }
            }
        }
 private static SyntaxNode HandleTypeDeclaration(MemberOrderHelper memberOrder, TypeDeclarationSyntax typeDeclarationNode, ElementOrderingChecks checks, SyntaxNode syntaxRoot, IndentationOptions indentationOptions)
 {
     return OrderMember(memberOrder, typeDeclarationNode.Members, checks, syntaxRoot, indentationOptions);
 }