PageRenderTime 57ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/BuildError.cs

http://github.com/mono/monodevelop
C# | 118 lines | 79 code | 14 blank | 25 comment | 7 complexity | e041ce241512817af7b098f1e8d92629 MD5 | raw file
Possible License(s): LGPL-2.0, GPL-2.0, CC-BY-SA-3.0, MIT, LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. //
  2. // BuildError.cs
  3. //
  4. // Author:
  5. // Michael Hutchinson <m.j.hutchinson@gmail.com>
  6. //
  7. // Copyright (c) 2015 Xamarin Inc.
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining a copy
  10. // of this software and associated documentation files (the "Software"), to deal
  11. // in the Software without restriction, including without limitation the rights
  12. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. // copies of the Software, and to permit persons to whom the Software is
  14. // furnished to do so, subject to the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be included in
  17. // all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. // THE SOFTWARE.
  26. using System;
  27. using System.CodeDom.Compiler;
  28. namespace MonoDevelop.Projects
  29. {
  30. public class BuildError
  31. {
  32. public BuildError () : this (String.Empty, 0, 0, String.Empty, String.Empty)
  33. {
  34. }
  35. public BuildError (string fileName, int line, int column, string errorNumber, string errorText)
  36. {
  37. FileName = fileName;
  38. Line = line;
  39. Column = column;
  40. ErrorNumber = errorNumber;
  41. ErrorText = errorText;
  42. }
  43. public BuildError (CompilerError error)
  44. {
  45. FileName = error.FileName;
  46. Line = error.Line;
  47. Column = error.Column;
  48. ErrorNumber = error.ErrorNumber;
  49. ErrorText = error.ErrorText;
  50. IsWarning = error.IsWarning;
  51. }
  52. public override string ToString ()
  53. {
  54. var sb = new System.Text.StringBuilder ();
  55. if (!string.IsNullOrEmpty (FileName)) {
  56. sb.Append (FileName);
  57. if (Line > 1) {
  58. sb.Append ('(').Append (Line);
  59. if (Column > 1)
  60. sb.Append (',').Append (Column);
  61. sb.Append (')');
  62. }
  63. sb.Append (" : ");
  64. }
  65. if (IsWarning)
  66. sb.Append ("warning");
  67. else
  68. sb.Append ("error");
  69. if (!string.IsNullOrEmpty (ErrorNumber))
  70. sb.Append (' ').Append (ErrorNumber);
  71. sb.Append (": ").Append (ErrorText);
  72. return sb.ToString ();
  73. }
  74. public string FileName { get; set; }
  75. public string Subcategory { get; set; }
  76. public bool IsWarning { get; set; }
  77. public string ErrorNumber { get; set; }
  78. public string ErrorText { get; set; }
  79. public string HelpKeyword { get; set; }
  80. public int Line { get; set; }
  81. public int Column { get; set; }
  82. public int EndLine { get; set; }
  83. public int EndColumn { get; set; }
  84. public IBuildTarget SourceTarget { get; set; }
  85. public static BuildError FromMSBuildErrorFormat (string lineText)
  86. {
  87. var result = MSBuildErrorParser.TryParseLine (lineText);
  88. if (result == null)
  89. return null;
  90. return new BuildError {
  91. FileName = result.Origin ?? "",
  92. Subcategory = result.Subcategory,
  93. IsWarning = !result.IsError,
  94. ErrorNumber = result.Code,
  95. ErrorText = result.Message,
  96. Line = result.Line,
  97. EndLine = result.EndLine,
  98. Column = result.Column,
  99. EndColumn = result.EndColumn,
  100. HelpKeyword = result.HelpKeyword,
  101. };
  102. }
  103. }
  104. }