private static string GetFixName(MalformedContractError error) { if (error == MalformedContractError.DuplicatedEndContractBlock) { return("Remove redundant EndContractBlock"); } if (error == MalformedContractError.ContractStatementInTheMiddleOfTheMethod) { return("Remove redundant Contract.Ensures"); } return("Remove redundant contact statement"); }
public static string GetErrorText(this MalformedContractError error, string contractMethodName) { switch (error) { case MalformedContractError.VoidReturnMethodCall: // Code Contract error: error CC1027: Malformed contract. return(string.Format("Malformed contract. Detected expression statement evaluated for side-effect in contracts of method '{0}'", contractMethodName)); case MalformedContractError.AssertOrAssumeInContractBlock: // Code Contract error: error CC1016: Contract.Assert/Contract.Assume cannot be used in contract section. Use only Requires and Ensures. return(string.Format("Contract.Assert/Contract.Assume cannot be used in contract section of method '{0}'. Use only Requires and Ensures", contractMethodName)); case MalformedContractError.AssignmentInContractBlock: // Code Contract error: error CC1004: Malformed contract. Found Requires after assignment in method 'CodeContractInvestigations.InconsistentPreconditionVisibility.AssignmentBeforeRequires'. return(string.Format("Malformed contract. Assignment cannot be used in contract section of method '{0}'", contractMethodName)); case MalformedContractError.RequiresAfterEnsures: // error CC1014: Precondition found after postcondition. return(string.Format("Malformed contract. Precondition found after postcondition in contract section of method '{0}'", contractMethodName)); case MalformedContractError.ReqruiesOrEnsuresAfterEndContractBlock: // error CC1012: Contract call found after prior EndContractBlock. return(string.Format("Malformed contract. Contract call found after prior EndContractBlock in method '{0}'", contractMethodName)); case MalformedContractError.DuplicatedEndContractBlock: //error CC1012: Contract call found after prior EndContractBlock. return(string.Format("Malformed contract. Duplicated call of EndContractBlock in method '{0}'", contractMethodName)); case MalformedContractError.MethodContractInTryBlock: // error CC1024: Contract section within try block. return(string.Format("Malformed contract. Contract section within try block in method '{0}'", contractMethodName)); case MalformedContractError.ContractStatementInTheMiddleOfTheMethod: // error CC1017: Malformed contract section in method 'MalformedContractErrors.ContractInTheMiddleOfTheMethod(System.String)' return(string.Format("Contract statements in the middle of the method '{0}'", contractMethodName)); default: Contract.Assert(false, "Unknown malformed contract error: " + error); throw new InvalidOperationException("Unknown malformed contract error: " + error); } }
private static string GetFixName(MalformedContractError error) { if (error == MalformedContractError.DuplicatedEndContractBlock) return "Remove redundant EndContractBlock"; if (error == MalformedContractError.ContractStatementInTheMiddleOfTheMethod) return "Remove redundant Contract.Ensures"; return "Remove redundant contact statement"; }
public CodeContractErrorValidationResult(ICSharpStatement statement, MalformedContractError error, string message) : base(statement) { _message = message; Error = error; }
public static ValidationResult CreateError(ICSharpStatement statement, MalformedContractError error, string message = null) { return(new CodeContractErrorValidationResult(statement, error, message)); }