private bool ComputeIsAvailable(out ICSharpFunctionDeclaration currentFunction)
        {
            if (!EnsuresAvailableForSelectedReturnType(out currentFunction))
                return false;

            // For abstract and interface methods contract method differs from the
            // current method
            var contractMethod = currentFunction.GetContractFunction();
            if (contractMethod == null)
                return false;

            if (ResultIsAlreadyCheckedByContractEnsures(contractMethod))
                return false;

            return true;
        }
예제 #2
0
        private List <ArgumentDescription> GetArgumentsAvailableForRequiresCheck(ICSharpFunctionDeclaration selectedMethod)
        {
            Contract.Requires(selectedMethod != null);
            Contract.Ensures(Contract.Result <List <ArgumentDescription> >() != null);

            var parameterRequiresAvailability =
                selectedMethod.DeclaredElement.Parameters
                .SelectMany(pm => pm.GetDeclarations())
                .Select(pm => pm as IParameterDeclaration)
                .Where(pm => pm != null)
                .Select(p => ParameterRequiresAvailability.Create(_provider, p))
                .Where(p => p.IsAvailable)
                .ToList();

            // Contract function could be absent, but in this case we'll generate contract
            // class (and function) before adding all preconditions!
            var contractFunction = selectedMethod.GetContractFunction();

            if (contractFunction == null)
            {
                return(parameterRequiresAvailability.Select(p =>
                                                            new ArgumentDescription {
                    Name = p.ParameterName, Type = p.ParameterType
                })
                       .ToList());
            }

            Func <ParameterRequiresAvailability, bool> isFuncAvailable =
                p => new FunctionRequiresAvailability(_provider, p.ParameterName, contractFunction).IsAvailable;

            var availableArguments =
                parameterRequiresAvailability
                .Where(isFuncAvailable)
                .Select(pa =>
                        new ArgumentDescription {
                Name = pa.ParameterName, Type = pa.ParameterType
            })
                .ToList();

            return(availableArguments);
        }
예제 #3
0
        private bool ComputeIsAvailable(out ICSharpFunctionDeclaration currentFunction)
        {
            if (!EnsuresAvailableForSelectedReturnType(out currentFunction))
            {
                return(false);
            }

            // For abstract and interface methods contract method differs from the
            // current method
            var contractMethod = currentFunction.GetContractFunction();

            if (contractMethod == null)
            {
                return(false);
            }

            if (ResultIsAlreadyCheckedByContractEnsures(contractMethod))
            {
                return(false);
            }

            return(true);
        }