PageRenderTime 223ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/src/NUnit/UiException/StackTraceParser.cs

#
C# | 106 lines | 45 code | 17 blank | 44 comment | 1 complexity | 1bebd5a72b55b70b003b7dcfd4daefb4 MD5 | raw file
Possible License(s): GPL-2.0
  1. // ****************************************************************
  2. // This is free software licensed under the NUnit license. You may
  3. // obtain a copy of the license at http://nunit.org
  4. // ****************************************************************
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Text;
  8. using NUnit.UiException.StackTraceAnalyzers;
  9. using NUnit.UiException.StackTraceAnalysers;
  10. namespace NUnit.UiException
  11. {
  12. /// <summary>
  13. /// StackTraceParser is the entry class for analyzing and converting a stack
  14. /// trace - as given by .NET - into a manageable and ordered set of ErrorItem
  15. /// instances.
  16. /// StackTraceParser contains internaly a set of autonom, independent and
  17. /// interchangeable algorithms that makes the analysis of the stack robust and
  18. /// opened to changes. Its architecture is designed to abstract callers from
  19. /// secondary details such as the type of culture or file system that can
  20. /// both affect the format of the final stack as provided by .NET.
  21. /// In the future, this class could easily be extended by exposing a
  22. /// kind of register() method that would allow client code to append
  23. /// new algorithms of analysis in its internal list.
  24. /// </summary>
  25. public class StackTraceParser
  26. {
  27. /// <summary>
  28. /// Output list build from the StackTrace analyze .
  29. /// </summary>
  30. private ErrorItemCollection _items;
  31. /// <summary>
  32. /// One or more algorithms designed to locate function names
  33. /// inside a stack trace line.
  34. /// </summary>
  35. private IErrorParser _functionParsers;
  36. /// <summary>
  37. /// One or more algorithms designed to locate path names
  38. /// inside a stack strace line.
  39. /// </summary>
  40. private IErrorParser _pathParsers;
  41. /// <summary>
  42. /// One or more algorithms designed to locate line number
  43. /// information inside a stack strace line.
  44. /// </summary>
  45. private IErrorParser _lineNumberParsers;
  46. /// <summary>
  47. /// Build a new instance of StackTraceParser.
  48. /// </summary>
  49. public StackTraceParser()
  50. {
  51. _items = new ErrorItemCollection();
  52. _functionParsers = new FunctionParser();
  53. _pathParsers = new PathCompositeParser();
  54. _lineNumberParsers = new LineNumberParser();
  55. return;
  56. }
  57. /// <summary>
  58. /// Gives access to the collection of ErrorItem
  59. /// build during the analyze of the StackTrace.
  60. /// </summary>
  61. public ErrorItemCollection Items
  62. {
  63. get { return (_items); }
  64. }
  65. /// <summary>
  66. /// Reads and transforms the given stack trace into a manageable and ordered
  67. /// set of ErrorItem instances. The resulting set is stored into Items property.
  68. /// </summary>
  69. /// <param name="stackTrace">A string value that should contain a .Net stack trace.</param>
  70. public void Parse(string stackTrace)
  71. {
  72. DefaultTextManager lines;
  73. RawError rawError;
  74. _items.Clear();
  75. lines = new DefaultTextManager();
  76. lines.Text = stackTrace;
  77. foreach (string line in lines)
  78. {
  79. rawError = new RawError(line);
  80. if (!_functionParsers.TryParse(this, rawError))
  81. continue;
  82. _pathParsers.TryParse(this, rawError);
  83. _lineNumberParsers.TryParse(this, rawError);
  84. _items.Add(rawError.ToErrorItem());
  85. }
  86. return;
  87. }
  88. }
  89. }