public static string GetText(this CAError code, object[] args) { var codeString = code.ToString(); var memInfo = typeof(CAError).GetMember(codeString); if (memInfo == null || memInfo.Length == 0) { return(codeString); } var attrib = memInfo[0].GetCustomAttributes(typeof(ErrorMessageAttribute), false); if (attrib == null || attrib.Length == 0) { return(codeString); } var message = ((ErrorMessageAttribute)attrib[0]).Message; if (args != null && args.Length > 0) { message = string.Format(message, args); } return(string.Concat(codeString, ": ", message)); }
public void ReportErrorAbsolute(Span span, CAError errorCode, params object[] args) { //if (span.IsEmpty) //{ // Log.Debug("Error {0} not reported because the span is empty.", errorCode); // return; //} string fileName; bool isPrimary; var fileSpan = _prepModel.Source.GetFileSpan(span, out fileName, out isPrimary); string fileContent = null; foreach (var incl in _prepModel.IncludeDependencies) { if (string.Equals(incl.FileName, fileName, StringComparison.OrdinalIgnoreCase)) { fileContent = incl.Content; break; } } ReportErrorLocal(fileName, fileSpan, isPrimary, fileContent, errorCode, args); }
public void ReportErrorAbsolute(Span span, CAError errorCode, params object[] args) { if (_errorReported.HasValue && _errorReported.Value == ErrorTagging.ErrorType.Error) { return; } Statement.CodeAnalyzer.ReportErrorAbsolute(span, errorCode, args); _errorReported = ErrorTagging.ErrorType.Error; }
public static ErrorType GetErrorType(this CAError code) { var memInfo = typeof(CAError).GetMember(code.ToString()); if (memInfo == null || memInfo.Length == 0) { return(ErrorType.Error); } var attrib = memInfo[0].GetCustomAttributes(typeof(WarningAttribute), false); if (attrib == null || attrib.Length == 0) { return(ErrorType.Error); } return(ErrorType.Warning); }
public void ReportErrorLocal(string fileName, Span fileSpan, bool isPrimary, string fileContent, CAError errorCode, params object[] args) { int lineNum = 0, linePos = 0; if (fileContent == null) { foreach (var incl in _prepModel.IncludeDependencies) { if (string.Equals(incl.FileName, fileName, StringComparison.OrdinalIgnoreCase)) { fileContent = incl.Content; isPrimary = string.Equals(fileName, _codeModel.FileName, StringComparison.OrdinalIgnoreCase); break; } } } if (fileContent != null) { Util.CalcLineAndPosFromOffset(fileContent, fileSpan.Start, out lineNum, out linePos); // Check for any exclusions on this line var lineText = GetLineText(fileContent, fileSpan.Start); var code = new CodeParser(lineText) { ReturnComments = true }; while (code.Read()) { if (code.Type != CodeType.Comment) { continue; } foreach (Match match in _rxExclusion.Matches(code.Text)) { CAError excludedErrorCode; if (Enum.TryParse <CAError>(match.Value, true, out excludedErrorCode) && excludedErrorCode == errorCode) { return; } } } } var message = errorCode.GetText(args); var type = errorCode.GetErrorType(); if (type == ErrorType.Warning) { _numWarnings++; } else { _numErrors++; } if (_pane != null) { _pane.WriteLine(string.Format("{0}({1},{2}) : {3} : {4}", fileName, lineNum + 1, linePos + 1, type, message)); } var task = new ErrorTagging.ErrorTask(fileName, lineNum, linePos, message, ErrorType.CodeAnalysisError, ErrorTaskSource.CodeAnalysis, _codeModel.FileName, isPrimary ? _codeModel.Snapshot : null, fileSpan); ErrorTaskProvider.Instance.Add(task, true); }
public void ReportError(Span span, CAError errorCode, params object[] args) { ReportErrorAbsolute(span.Offset(_read.FuncOffset), errorCode, args); }
public void ReportError(CodeModel.Span span, CAError errorCode, params object[] args) { CodeAnalyzer.ReportError(span, errorCode, args); }
public void ReportError(CAError errorCode, params object[] args) { ReportError(Span, errorCode, args); }