Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2389-EpsLexicase/HeuristicLab.ExtLibs/HeuristicLab.NRefactory/5.5.0/NRefactory.CSharp-5.5.0/Ast/TokenRole.cs @ 18242

Last change on this file since 18242 was 11700, checked in by jkarder, 10 years ago

#2077: created branch and added first version

File size: 1.2 KB
Line 
1using System;
2using System.Collections.Generic;
3
4namespace ICSharpCode.NRefactory.CSharp
5{
6  /// <summary>
7  /// A specific role only used for C# tokens
8  /// </summary>
9  public sealed class TokenRole : Role<CSharpTokenNode>
10  {
11    internal readonly static List<string> Tokens = new List<string> ();
12    internal readonly static List<int>    TokenLengths = new List<int> ();
13    internal readonly uint TokenIndex;
14
15    static TokenRole ()
16    {
17      // null token
18      Tokens.Add ("");
19      TokenLengths.Add (0);
20    }
21
22    /// <summary>
23    /// Gets the token as string. Note that the token Name and Token value may differ.
24    /// </summary>
25    public string Token {
26      get;
27      private set;
28    }
29   
30    /// <summary>
31    /// Gets the char length of the token.
32    /// </summary>
33    public int Length {
34      get;
35      private set;
36    }
37
38
39    public TokenRole(string token) : base (token, CSharpTokenNode.Null)
40    {
41      this.Token = token;
42      this.Length = token.Length;
43
44      bool found = false;
45      for (int i = 0; i < Tokens.Count; i++) {
46        var existingToken = Tokens [i];
47        if (existingToken == token) {
48          TokenIndex = (uint)i;
49          found = true;
50          break;
51        }
52      }
53      if (!found) {
54        TokenIndex = (uint)Tokens.Count;
55        Tokens.Add (token);
56        TokenLengths.Add (this.Length);
57      }
58    }
59  }
60}
61
Note: See TracBrowser for help on using the repository browser.