private static bool IsValidContextForMember(CSharpSyntaxContext context, CancellationToken cancellationToken)
        {
            if (context.SyntaxTree.IsGlobalMemberDeclarationContext(context.Position, SyntaxKindSet.AllGlobalMemberModifiers, cancellationToken) ||
                context.IsMemberDeclarationContext(
                    validModifiers: SyntaxKindSet.AllMemberModifiers,
                    validTypeDeclarations: SyntaxKindSet.ClassInterfaceStructTypeDeclarations,
                    canBePartial: false,
                    cancellationToken: cancellationToken))
            {
                return(CheckPreviousAccessibilityModifiers(context));
            }

            return(false);
        }
Esempio n. 2
0
 protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
 {
     return
         (context.IsGlobalStatementContext ||
          IsRefReadOnlyContext(context) ||
          IsValidContextForType(context, cancellationToken) ||
          context.SyntaxTree.IsGlobalMemberDeclarationContext(context.Position, SyntaxKindSet.AllGlobalMemberModifiers, cancellationToken) ||
          context.IsMemberDeclarationContext(
              validModifiers: s_validMemberModifiers,
              validTypeDeclarations: SyntaxKindSet.ClassInterfaceStructRecordTypeDeclarations,
              canBePartial: false,
              cancellationToken: cancellationToken) ||
          IsStructAccessorContext(context));
 }
        protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
        {
            if (context.IsMemberDeclarationContext(validModifiers: s_validMemberModifiers, validTypeDeclarations: SyntaxKindSet.ClassStructTypeDeclarations, canBePartial: false, cancellationToken: cancellationToken))
            {
                // operators must be both public and static
                var modifiers = context.PrecedingModifiers;

                return
                    (modifiers.Contains(SyntaxKind.PublicKeyword) &&
                     modifiers.Contains(SyntaxKind.StaticKeyword));
            }

            return(false);
        }
Esempio n. 4
0
        protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
        {
            var syntaxTree = context.SyntaxTree;

            return
                (IsExternAliasContext(context) ||
                 context.IsGlobalStatementContext ||
                 syntaxTree.IsGlobalMemberDeclarationContext(position, s_validGlobalModifiers, cancellationToken) ||
                 context.IsMemberDeclarationContext(
                     validModifiers: s_validModifiers,
                     validTypeDeclarations: SyntaxKindSet.ClassInterfaceStructTypeDeclarations,
                     canBePartial: false,
                     cancellationToken: cancellationToken));
        }
 protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
 {
     return
         (context.IsGlobalStatementContext ||
          context.IsMemberDeclarationContext(
              validModifiers: s_validMemberModifiers,
              validTypeDeclarations: SyntaxKindSet.ClassOnlyTypeDeclarations,
              canBePartial: false,
              cancellationToken: cancellationToken) ||
          context.IsTypeDeclarationContext(
              validModifiers: s_validTypeModifiers,
              validTypeDeclarations: SyntaxKindSet.ClassStructTypeDeclarations,
              canBePartial: false,
              cancellationToken: cancellationToken));
 }
 protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
 {
     return
         context.IsGlobalStatementContext ||
         context.IsMemberDeclarationContext(
             validModifiers: s_validMemberModifiers,
             validTypeDeclarations: SyntaxKindSet.ClassOnlyTypeDeclarations,
             canBePartial: false,
             cancellationToken: cancellationToken) ||
         context.IsTypeDeclarationContext(
             validModifiers: s_validTypeModifiers,
             validTypeDeclarations: SyntaxKindSet.ClassStructTypeDeclarations,
             canBePartial: false,
             cancellationToken: cancellationToken);
 }
        protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
        {
            if (!context.IsMemberDeclarationContext(
                    validModifiers: s_validMemberModifiers,
                    validTypeDeclarations: SyntaxKindSet.ClassStructRecordTypeDeclarations,
                    canBePartial: false,
                    cancellationToken: cancellationToken))
            {
                return(false);
            }

            var modifiers = context.PrecedingModifiers;

            return(!modifiers.Contains(SyntaxKind.PrivateKeyword) || modifiers.Contains(SyntaxKind.ProtectedKeyword));
        }
Esempio n. 8
0
        protected override bool IsValidContext(
            int position,
            CSharpSyntaxContext context,
            CancellationToken cancellationToken
            )
        {
            var syntaxTree = context.SyntaxTree;

            return(context.IsNonAttributeExpressionContext ||
                   context.IsDefiniteCastTypeContext ||
                   context.IsStatementContext ||
                   context.IsGlobalStatementContext ||
                   context.IsObjectCreationTypeContext ||
                   (
                       context.IsGenericTypeArgumentContext &&
                       !context.TargetToken.Parent.HasAncestor <XmlCrefAttributeSyntax>()
                   ) ||
                   context.IsFunctionPointerTypeArgumentContext ||
                   context.IsIsOrAsTypeContext ||
                   context.IsLocalVariableDeclarationContext ||
                   context.IsParameterTypeContext ||
                   context.IsPossibleLambdaOrAnonymousMethodParameterTypeContext ||
                   context.IsImplicitOrExplicitOperatorTypeContext ||
                   context.IsTypeOfExpressionContext ||
                   context.IsCrefContext ||
                   syntaxTree.IsDefaultExpressionContext(position, context.LeftToken) ||
                   syntaxTree.IsAfterKeyword(position, SyntaxKind.ConstKeyword, cancellationToken) ||
                   syntaxTree.IsAfterKeyword(position, SyntaxKind.RefKeyword, cancellationToken) ||
                   syntaxTree.IsAfterKeyword(
                       position,
                       SyntaxKind.ReadOnlyKeyword,
                       cancellationToken
                       ) ||
                   context.IsDelegateReturnTypeContext ||
                   syntaxTree.IsGlobalMemberDeclarationContext(
                       position,
                       SyntaxKindSet.AllGlobalMemberModifiers,
                       cancellationToken
                       ) ||
                   context.IsPossibleTupleContext ||
                   context.IsMemberDeclarationContext(
                       validModifiers: SyntaxKindSet.AllMemberModifiers,
                       validTypeDeclarations: SyntaxKindSet.ClassInterfaceStructRecordTypeDeclarations,
                       canBePartial: false,
                       cancellationToken: cancellationToken
                       ));
        }
Esempio n. 9
0
 private static bool IsValidContextForMember(
     CSharpSyntaxContext context,
     CancellationToken cancellationToken
     )
 {
     return(context.SyntaxTree.IsGlobalMemberDeclarationContext(
                context.Position,
                s_validGlobalMemberModifiers,
                cancellationToken
                ) ||
            context.IsMemberDeclarationContext(
                validModifiers: s_validMemberModifiers,
                validTypeDeclarations: SyntaxKindSet.ClassInterfaceStructRecordTypeDeclarations,
                canBePartial: false,
                cancellationToken: cancellationToken
                ));
 }
Esempio n. 10
0
        private bool IsMemberDeclarationContext(CSharpSyntaxContext context, CancellationToken cancellationToken)
        {
            if (context.IsMemberDeclarationContext(validModifiers: ValidMemberModifiers, validTypeDeclarations: SyntaxKindSet.ClassStructTypeDeclarations, canBePartial: false, cancellationToken: cancellationToken))
            {
                var token = context.LeftToken;
                var decl  = token.GetAncestor <TypeDeclarationSyntax>();

                // partial methods must be in partial types
                if (!decl.Modifiers.Any(t => t.IsKindOrHasMatchingText(SyntaxKind.PartialKeyword)))
                {
                    return(false);
                }

                return(true);
            }

            return(false);
        }
Esempio n. 11
0
 private static bool InMemberDeclarationContext(
     int position,
     CSharpSyntaxContext context,
     CancellationToken cancellationToken
     )
 {
     return(context.IsGlobalStatementContext ||
            context.SyntaxTree.IsGlobalMemberDeclarationContext(
                position,
                SyntaxKindSet.AllGlobalMemberModifiers,
                cancellationToken
                ) ||
            context.IsMemberDeclarationContext(
                validModifiers: SyntaxKindSet.AllMemberModifiers,
                validTypeDeclarations: SyntaxKindSet.ClassInterfaceStructRecordTypeDeclarations,
                canBePartial: true,
                cancellationToken: cancellationToken
                ));
 }
Esempio n. 12
0
 private static bool IsMemberDeclarationContext(
     CSharpSyntaxContext context,
     CancellationToken cancellationToken
     )
 {
     return(context.TargetToken.IsUnsafeContext() &&
            (
                context.SyntaxTree.IsGlobalMemberDeclarationContext(
                    context.Position,
                    SyntaxKindSet.AllGlobalMemberModifiers,
                    cancellationToken
                    ) ||
                context.IsMemberDeclarationContext(
                    validModifiers: s_validModifiers,
                    validTypeDeclarations: SyntaxKindSet.StructOnlyTypeDeclarations,
                    canBePartial: false,
                    cancellationToken: cancellationToken
                    )
            ));
 }
        private static bool IsValidContextForMember(CSharpSyntaxContext context, CancellationToken cancellationToken)
        {
            if (context.SyntaxTree.IsGlobalMemberDeclarationContext(context.Position, SyntaxKindSet.AllGlobalMemberModifiers, cancellationToken) ||
                context.IsMemberDeclarationContext(validModifiers: SyntaxKindSet.AllMemberModifiers, validTypeDeclarations: SyntaxKindSet.ClassInterfaceStructRecordTypeDeclarations, canBePartial: false, cancellationToken: cancellationToken))
            {
                var modifiers = context.PrecedingModifiers;

                // can't have private + abstract/virtual/override/sealed
                if (modifiers.Contains(SyntaxKind.AbstractKeyword) ||
                    modifiers.Contains(SyntaxKind.VirtualKeyword) ||
                    modifiers.Contains(SyntaxKind.OverrideKeyword) ||
                    modifiers.Contains(SyntaxKind.SealedKeyword))
                {
                    return(false);
                }

                return(CheckPreviousAccessibilityModifiers(context));
            }

            return(false);
        }
Esempio n. 14
0
 private static bool IsValidNewByRefContext(
     SyntaxTree syntaxTree,
     int position,
     CSharpSyntaxContext context,
     CancellationToken cancellationToken
     )
 {
     return(IsValidRefExpressionContext(context) ||
            context.IsDelegateReturnTypeContext ||
            syntaxTree.IsGlobalMemberDeclarationContext(
                position,
                syntaxTree.IsScript()
               ? RefGlobalMemberScriptModifiers
               : RefGlobalMemberModifiers,
                cancellationToken
                ) ||
            context.IsMemberDeclarationContext(
                validModifiers: RefMemberModifiers,
                validTypeDeclarations: SyntaxKindSet.ClassInterfaceStructRecordTypeDeclarations,
                canBePartial: true,
                cancellationToken: cancellationToken
                ));
 }
Esempio n. 15
0
 private static bool IsMemberReturnTypeContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
 => context.SyntaxTree.IsGlobalMemberDeclarationContext(position, SyntaxKindSet.AllGlobalMemberModifiers, cancellationToken) ||
 context.IsMemberDeclarationContext(validModifiers: s_validClassInterfaceRecordModifiers, validTypeDeclarations: SyntaxKindSet.ClassInterfaceRecordTypeDeclarations, canBePartial: true, cancellationToken) ||
 context.IsMemberDeclarationContext(validModifiers: s_validStructModifiers, validTypeDeclarations: SyntaxKindSet.StructOnlyTypeDeclarations, canBePartial: false, cancellationToken);
Esempio n. 16
0
 protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
 {
     return(context.IsMemberDeclarationContext(s_validModifiers, s_validTypeDeclarations, canBePartial: true, cancellationToken));
 }