Public Sub New()

in src/Workspaces/VisualBasic/Portable/Utilities/ModifierCollectionFacts.vb [29:209]


        Public Sub New(syntaxTree As SyntaxTree, position As Integer, token As SyntaxToken, cancellationToken As CancellationToken)
            Contract.Requires(token = syntaxTree.GetTargetToken(position, cancellationToken))

            Dim targetToken = token

            
            _declarationTypes = ComputeAllowableDeclarationTypes(syntaxTree, position, token, cancellationToken)

            Dim defaultMethodFlags = PossibleDeclarationTypes.Method Or PossibleDeclarationTypes.ProtectedMember Or PossibleDeclarationTypes.OverridableMethod
            Dim defaultPropertyFlags = PossibleDeclarationTypes.Property Or PossibleDeclarationTypes.ProtectedMember Or PossibleDeclarationTypes.OverridableMethod

            Do While targetToken.IsModifier() OrElse
                     targetToken.Kind = SyntaxKind.DimKeyword OrElse
                     targetToken.HasMatchingText(SyntaxKind.AsyncKeyword) OrElse
                     targetToken.HasMatchingText(SyntaxKind.IteratorKeyword)

                Select Case targetToken.Kind
                    Case SyntaxKind.PublicKeyword
                        _accessibilityKeyword = targetToken

                    Case SyntaxKind.FriendKeyword
                        If _accessibilityKeyword.IsKind(SyntaxKind.ProtectedKeyword) Then
                            _hasProtectedAndFriend = True
                        End If

                        _accessibilityKeyword = targetToken

                        
                        _declarationTypes = _declarationTypes And Not PossibleDeclarationTypes.Operator

                    Case SyntaxKind.ProtectedKeyword, SyntaxKind.PrivateKeyword
                        If targetToken.IsKind(SyntaxKind.ProtectedKeyword) AndAlso _accessibilityKeyword.IsKind(SyntaxKind.FriendKeyword) Then
                            _hasProtectedAndFriend = True
                        End If

                        _accessibilityKeyword = targetToken

                        
                        If syntaxTree.IsDeclarationContextWithinTypeBlocks(position, token, True, cancellationToken, SyntaxKind.CompilationUnit, SyntaxKind.NamespaceBlock) Then
                            _declarationTypes = _declarationTypes And Not PossibleDeclarationTypes.AllTypes
                        End If

                        
                        _declarationTypes = _declarationTypes And Not PossibleDeclarationTypes.Operator

                    Case SyntaxKind.OverridesKeyword
                        _overridesOrShadowsKeyword = targetToken

                        
                        
                        If syntaxTree.IsDeclarationContextWithinTypeBlocks(position, token, True, cancellationToken, SyntaxKind.ClassBlock) Then
                            _declarationTypes = _declarationTypes And (defaultMethodFlags Or defaultPropertyFlags)
                        ElseIf syntaxTree.IsDeclarationContextWithinTypeBlocks(position, token, True, cancellationToken, SyntaxKind.StructureBlock) Then
                            
                            _declarationTypes = _declarationTypes And PossibleDeclarationTypes.Method
                        Else
                            _declarationTypes = Nothing
                        End If

                    Case SyntaxKind.MustOverrideKeyword, SyntaxKind.NotOverridableKeyword, SyntaxKind.OverridableKeyword
                        _overridableSharedOrPartialKeyword = targetToken

                        
                        
                        If syntaxTree.IsDeclarationContextWithinTypeBlocks(position, token, True, cancellationToken, SyntaxKind.ClassBlock) Then
                            _declarationTypes = _declarationTypes And (defaultMethodFlags Or
                                                                       defaultPropertyFlags Or
                                                                       PossibleDeclarationTypes.IteratorFunction Or
                                                                       PossibleDeclarationTypes.IteratorProperty)
                        Else
                            _declarationTypes = Nothing
                        End If

                    Case SyntaxKind.MustInheritKeyword, SyntaxKind.NotInheritableKeyword
                        _inheritenceKeyword = targetToken
                        _declarationTypes = _declarationTypes And PossibleDeclarationTypes.Class

                    Case SyntaxKind.SharedKeyword
                        _overridableSharedOrPartialKeyword = targetToken
                        _sharedKeyword = targetToken
                        _declarationTypes = _declarationTypes And (PossibleDeclarationTypes.Event Or
                                                                   PossibleDeclarationTypes.Field Or
                                                                   PossibleDeclarationTypes.Method Or
                                                                   PossibleDeclarationTypes.Property Or
                                                                   PossibleDeclarationTypes.Operator Or
                                                                   PossibleDeclarationTypes.IteratorFunction Or
                                                                   PossibleDeclarationTypes.IteratorProperty)

                    Case SyntaxKind.NarrowingKeyword, SyntaxKind.WideningKeyword
                        _narrowingOrWideningKeyword = targetToken
                        _declarationTypes = _declarationTypes And PossibleDeclarationTypes.Operator

                    Case SyntaxKind.ReadOnlyKeyword
                        _mutabilityOrWithEventsKeyword = targetToken
                        _declarationTypes = _declarationTypes And (defaultPropertyFlags Or
                                                                   PossibleDeclarationTypes.Field Or
                                                                   PossibleDeclarationTypes.IteratorProperty)

                    Case SyntaxKind.WriteOnlyKeyword
                        _mutabilityOrWithEventsKeyword = targetToken
                        _declarationTypes = _declarationTypes And defaultPropertyFlags
                        _declarationTypes = _declarationTypes And Not (PossibleDeclarationTypes.IteratorFunction Or
                                                                       PossibleDeclarationTypes.IteratorProperty)

                    Case SyntaxKind.ConstKeyword
                        _mutabilityOrWithEventsKeyword = targetToken
                        _declarationTypes = _declarationTypes And PossibleDeclarationTypes.Field

                    Case SyntaxKind.DefaultKeyword
                        _defaultKeyword = targetToken
                        _declarationTypes = _declarationTypes And (defaultPropertyFlags Or
                                                                   PossibleDeclarationTypes.IteratorProperty)

                    Case SyntaxKind.OverloadsKeyword
                        _overloadsKeyword = targetToken
                        _declarationTypes = _declarationTypes And (defaultMethodFlags Or
                                                                   defaultPropertyFlags Or
                                                                   PossibleDeclarationTypes.ExternalMethod Or
                                                                   PossibleDeclarationTypes.Operator)

                    Case SyntaxKind.WithEventsKeyword
                        _mutabilityOrWithEventsKeyword = targetToken
                        _declarationTypes = _declarationTypes And PossibleDeclarationTypes.Field

                    Case SyntaxKind.CustomKeyword
                        _customKeyword = targetToken
                        _declarationTypes = _declarationTypes And PossibleDeclarationTypes.Event

                    Case SyntaxKind.ShadowsKeyword
                        _overridesOrShadowsKeyword = targetToken
                        _declarationTypes = _declarationTypes And (PossibleDeclarationTypes.Property Or
                                                                   PossibleDeclarationTypes.Method Or
                                                                   PossibleDeclarationTypes.OverridableMethod Or
                                                                   PossibleDeclarationTypes.Delegate Or
                                                                   PossibleDeclarationTypes.Event Or
                                                                   PossibleDeclarationTypes.IteratorFunction Or
                                                                   PossibleDeclarationTypes.IteratorProperty)

                    Case SyntaxKind.PartialKeyword
                        _overridableSharedOrPartialKeyword = targetToken
                        _declarationTypes = _declarationTypes And (PossibleDeclarationTypes.Method Or
                                                                   PossibleDeclarationTypes.Class Or
                                                                   PossibleDeclarationTypes.Structure Or
                                                                   PossibleDeclarationTypes.Interface Or
                                                                   PossibleDeclarationTypes.Module)

                    Case SyntaxKind.DimKeyword
                        _dimKeyword = targetToken
                        _declarationTypes = _declarationTypes And PossibleDeclarationTypes.Field

                    Case SyntaxKind.IteratorKeyword
                        _iteratorKeyword = targetToken
                        _declarationTypes = _declarationTypes And (defaultMethodFlags Or
                                                                   defaultPropertyFlags Or
                                                                   PossibleDeclarationTypes.IteratorFunction Or
                                                                   PossibleDeclarationTypes.IteratorProperty)

                    Case SyntaxKind.AsyncKeyword
                        _asyncKeyword = targetToken
                        _declarationTypes = _declarationTypes And defaultMethodFlags

                    Case Else
                        If targetToken.HasMatchingText(SyntaxKind.AsyncKeyword) Then
                            
                            _asyncKeyword = targetToken
                            _declarationTypes = _declarationTypes And defaultMethodFlags
                        ElseIf targetToken.HasMatchingText(SyntaxKind.IteratorKeyword) Then
                            
                            _iteratorKeyword = targetToken
                            _declarationTypes = _declarationTypes And (defaultMethodFlags Or
                                                                       defaultPropertyFlags Or
                                                                       PossibleDeclarationTypes.IteratorFunction Or
                                                                       PossibleDeclarationTypes.IteratorProperty)
                        Else
                            Throw New InvalidOperationException("Unhandled modifier. Every modifier needs to be processed.")
                        End If
                End Select

                targetToken = targetToken.GetPreviousToken()
            Loop
        End Sub