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/GeneralScope/NewLineNode.cs

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

#2077: created branch and added first version

File size: 1.9 KB
Line 
1using System;
2namespace ICSharpCode.NRefactory.CSharp
3{
4
5  /// <summary>
6  /// A New line node represents a line break in the text.
7  /// </summary>
8  public sealed class NewLineNode : AstNode
9  {
10    public override NodeType NodeType {
11      get {
12        return NodeType.Whitespace;
13      }
14    }
15
16    const uint newLineMask = 0xfu << AstNodeFlagsUsedBits;
17    static readonly UnicodeNewline[] newLineTypes = {
18      UnicodeNewline.Unknown,
19      UnicodeNewline.LF,
20      UnicodeNewline.CRLF,
21      UnicodeNewline.CR,
22      UnicodeNewline.NEL,
23      UnicodeNewline.VT,
24      UnicodeNewline.FF,
25      UnicodeNewline.LS,
26      UnicodeNewline.PS
27    };
28   
29    public UnicodeNewline NewLineType {
30      get {
31        return newLineTypes[(flags & newLineMask) >> AstNodeFlagsUsedBits];
32      }
33      set {
34        ThrowIfFrozen();
35        int pos = Array.IndexOf(newLineTypes, value);
36        if (pos < 0)
37          pos = 0;
38        flags &= ~newLineMask; // clear old newline type
39        flags |= (uint)pos << AstNodeFlagsUsedBits;
40      }
41    }
42
43    TextLocation startLocation;
44    public override TextLocation StartLocation {
45      get {
46        return startLocation;
47      }
48    }
49   
50    public override TextLocation EndLocation {
51      get {
52        return new TextLocation (startLocation.Line + 1, 1);
53      }
54    }
55
56    public NewLineNode() : this (TextLocation.Empty)
57    {
58    }
59
60    public NewLineNode(TextLocation startLocation)
61    {
62      this.startLocation = startLocation;
63    }
64
65    public sealed override string ToString(CSharpFormattingOptions formattingOptions)
66    {
67      return NewLine.GetString (NewLineType);
68    }
69
70    public override void AcceptVisitor(IAstVisitor visitor)
71    {
72      visitor.VisitNewLine (this);
73    }
74     
75    public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
76    {
77      return visitor.VisitNewLine (this);
78    }
79   
80    public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
81    {
82      return visitor.VisitNewLine (this, data);
83    }
84   
85    protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match)
86    {
87      return other is NewLineNode;
88    }
89  }
90}
91
Note: See TracBrowser for help on using the repository browser.