Ejemplo n.º 1
0
        public static async Task <bool> CheckedInMethodContract(this ParameterSyntax parameter, SemanticModel semanticModel, CancellationToken token)
        {
            BaseMethodDeclarationSyntax method = parameter.AncestorsAndSelf().OfType <BaseMethodDeclarationSyntax>().FirstOrDefault();

            if (method != null)
            {
                ContractBlock contractBlock = await ContractBlock.CreateForMethodAsync(method, semanticModel, token);

                return(contractBlock.Preconditions.Any(p => p.ChecksForNotNull(parameter)));
            }

            // It seems that this parameter was declared in indexer
            var indexer = parameter.AncestorsAndSelf().OfType <IndexerDeclarationSyntax>().FirstOrDefault();

            if (indexer == null)
            {
                // That's strage!
                Contract.Assert(false, "This should never happend!! Right?");
                return(false);
            }

            return(indexer.AccessorList.Accessors.All(a =>
            {
                ContractBlock contractBlock = ContractBlock.CreateForMethodAsync(a, semanticModel, token).Result;
                return contractBlock.Preconditions.Any(p => p.ChecksForNotNull(parameter));
            }));
        }
        public static BaseMethodDeclarationSyntax AddRequires(ParameterSyntax parameter)
        {
            Contract.Requires(parameter != null);
            Contract.Requires(parameter != null);
            var method = parameter.AncestorsAndSelf().OfType <BaseMethodDeclarationSyntax>().FirstOrDefault();

            return(AddRequires(parameter, method));
        }
        public static MethodLikeSyntax GetEnclosingMethod(ParameterSyntax parameter)
        {
            var method = parameter.AncestorsAndSelf().OfType <BaseMethodDeclarationSyntax>().FirstOrDefault();

            if (method != null)
            {
                return(new MethodLikeSyntax(method));
            }

            // Maybe parameter declared in the indexer
            var indexer = parameter.AncestorsAndSelf().OfType <IndexerDeclarationSyntax>().FirstOrDefault();

            if (indexer == null)
            {
                // That's strage!
                Contract.Assert(false, "This should never happend!! Right?");
                throw new InvalidOperationException("Unknown enclosing declaration for paramter.");
            }

            return(new MethodLikeSyntax(indexer));
        }
Ejemplo n.º 4
0
        public static bool DeclaredMethodIsAbstract(this ParameterSyntax parameter)
        {
            Contract.Requires(parameter != null);

            var method = parameter.AncestorsAndSelf().OfType <BaseMethodDeclarationSyntax>().FirstOrDefault();

            if (method != null)
            {
                return(method.IsAbstract());
            }

            // Maybe parameter declared in the indexer
            var indexer = parameter.AncestorsAndSelf().OfType <IndexerDeclarationSyntax>().FirstOrDefault();

            if (indexer == null)
            {
                // That's strage!
                Contract.Assert(false, "This should never happend!! Right?");
                return(false);
            }

            return(indexer.AccessorList.Accessors.FirstOrDefault().IsAbstract());
        }