public static ContractRequires GetLastRequiresFor(this ICSharpFunctionDeclaration functionDeclaration, string parameterName) { var parameters = functionDeclaration.DeclaredElement.Parameters .Select(p => p.ShortName).TakeWhile(paramName => paramName != parameterName) .Reverse().ToList(); // Creating lookup where key is argument name, and the value is statements. var requiresStatements = functionDeclaration .GetRequires() .ToList(); /*.SelectMany(x => x.ArgumentNames.Select(a => new {Statement = x, ArgumentName = a})) * .ToLookup(x => x.ArgumentName, x => x.Statement)*/ ; // Looking for the last usage of the parameters in the requires statements foreach (var p in parameters) { // TODO: it seems terrible!!! and ugly! var precondition = requiresStatements .LastOrDefault(r => r.ChecksForNotNull(pa => pa.CompareReferenceArgument(ra => ra.BaseArgumentName == p))); if (precondition != null) { return(precondition); } } return(null); }
private ICSharpStatement GetLastRequiresStatementIfAny(ICSharpFunctionDeclaration functionDeclaration) { return functionDeclaration.GetRequires().Select(r => r.CSharpStatement).LastOrDefault(); }
private ICSharpStatement GetLastRequiresStatementIfAny(ICSharpFunctionDeclaration functionDeclaration) { return(functionDeclaration.GetRequires().Select(r => r.CSharpStatement).LastOrDefault()); }