/src/NUnit/UiException/CSharpParser/CSToken.cs
C# | 130 lines | 54 code | 18 blank | 58 comment | 5 complexity | 9b31c1984fd263e86fc446ba6a962798 MD5 | raw file
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 6using System; 7using System.Collections.Generic; 8using System.Text; 9 10namespace NUnit.UiException.CodeFormatters 11{ 12 /// <summary> 13 /// This enum indicate the kind of a string sequence. 14 /// </summary> 15 public enum ClassificationTag : byte 16 { 17 /// <summary> 18 /// The string refer to C# source code. 19 /// </summary> 20 Code = 0, // 0 21 22 /// <summary> 23 /// The string refers to C# keywords. 24 /// </summary> 25 Keyword = 1, // 1 26 27 /// <summary> 28 /// The string refers to C# comments. 29 /// </summary> 30 Comment = 2, // 2 31 32 /// <summary> 33 /// The string refers to a string/char value. 34 /// </summary> 35 String = 3 // 3 36 } 37 38 /// <summary> 39 /// (formerly named CSToken) 40 /// 41 /// Classifies a string and make it falls into one of the categories below: 42 /// - Code (the value should be interpreted as regular code) 43 /// - Keyword (the value should be interpreted as a language keyword) 44 /// - Comment (the value should be interpreted as comments) 45 /// - String (the value should be interpreted as a string) 46 /// </summary> 47 public class ClassifiedToken 48 { 49 /// <summary> 50 /// The string held by this token. 51 /// </summary> 52 protected string _text; 53 54 /// <summary> 55 /// The matching tag. 56 /// </summary> 57 protected ClassificationTag _tag; 58 59 /// <summary> 60 /// Starting startingPosition of the string. 61 /// </summary> 62 protected int _indexStart; 63 64 /// <summary> 65 /// This class cannot be build directly. 66 /// </summary> 67 protected ClassifiedToken() 68 { 69 // this class requires subclassing 70 } 71 72 /// <summary> 73 /// Gets the string value. 74 /// </summary> 75 public string Text 76 { 77 get { return (_text); } 78 } 79 80 /// <summary> 81 /// Gets the classification value for the string in Text. 82 /// - Code: Text should be interpreted as regular code, 83 /// - Keyword: Text should be interpreted as a language keyword, 84 /// - Comments: Text should be interpreted as comments, 85 /// - String: Text should be interpreted as a string. 86 /// </summary> 87 public ClassificationTag Tag 88 { 89 get { return (_tag); } 90 } 91 92 /// <summary> 93 /// Gets the string's starting startingPosition. 94 /// </summary> 95 public int IndexStart 96 { 97 get { return (_indexStart); } 98 } 99 100 /// <summary> 101 /// Returns true if 'obj' is an instance of ClassifiedToken 102 /// that contains same data that the current instance. 103 /// </summary> 104 public override bool Equals(object obj) 105 { 106 ClassifiedToken token; 107 108 if (obj == null || !(obj is ClassifiedToken)) 109 return (false); 110 111 token = obj as ClassifiedToken; 112 113 return (Text == token.Text && 114 Tag == token.Tag); 115 } 116 117 public override int GetHashCode() 118 { 119 return base.GetHashCode(); 120 } 121 122 public override string ToString() 123 { 124 return (String.Format( 125 "ClassifiedToken {Text='{0}', Tag={1}}", 126 Text, 127 Tag)); 128 } 129 } 130}