Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.ExtLibs/HeuristicLab.NRefactory/5.5.0/NRefactory.CSharp-5.5.0/Ast/GeneralScope/Comment.cs

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

#2077: created branch and added first version

File size: 3.6 KB
Line 
1//
2// Comment.cs
3// 
4// Author:
5//       Mike Krüger <mkrueger@novell.com>
6//
7// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
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
27namespace ICSharpCode.NRefactory.CSharp
28{
29  public enum CommentType
30  {
31    /// <summary>
32    /// "//" comment
33    /// </summary>
34    SingleLine,
35    /// <summary>
36    /// "/* */" comment
37    /// </summary>
38    MultiLine,
39    /// <summary>
40    /// "///" comment
41    /// </summary>
42    Documentation,
43    /// <summary>
44    /// Inactive code (code in non-taken "#if")
45    /// </summary>
46    InactiveCode,
47    /// <summary>
48    /// "/** */" comment
49    /// </summary>
50    MultiLineDocumentation
51  }
52 
53  public class Comment : AstNode
54  {
55    public override NodeType NodeType {
56      get {
57        return NodeType.Whitespace;
58      }
59    }
60   
61    CommentType commentType;
62   
63    public CommentType CommentType {
64      get { return commentType; }
65      set { ThrowIfFrozen(); commentType = value; }
66    }
67   
68    /// <summary>
69    /// Returns true if the <see cref="CommentType"/> is Documentation or MultiLineDocumentation.
70    /// </summary>
71    public bool IsDocumentation {
72      get {
73        return commentType == CommentType.Documentation || commentType == CommentType.MultiLineDocumentation;
74      }
75    }
76   
77    bool startsLine;
78   
79    public bool StartsLine {
80      get { return startsLine; }
81      set { ThrowIfFrozen(); startsLine = value; }
82    }
83   
84    string content;
85   
86    public string Content {
87      get { return content; }
88      set { ThrowIfFrozen(); content = value; }
89    }
90   
91    TextLocation startLocation;
92    public override TextLocation StartLocation {
93      get {
94        return startLocation;
95      }
96    }
97   
98    TextLocation endLocation;
99    public override TextLocation EndLocation {
100      get {
101        return endLocation;
102      }
103    }
104   
105    public Comment (string content, CommentType type = CommentType.SingleLine)
106    {
107      this.CommentType = type;
108      this.Content = content;
109    }
110   
111    public Comment (CommentType commentType, TextLocation startLocation, TextLocation endLocation)
112    {
113      this.CommentType = commentType;
114      this.startLocation = startLocation;
115      this.endLocation = endLocation;
116    }
117   
118    public override void AcceptVisitor (IAstVisitor visitor)
119    {
120      visitor.VisitComment (this);
121    }
122     
123    public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
124    {
125      return visitor.VisitComment (this);
126    }
127   
128    public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
129    {
130      return visitor.VisitComment (this, data);
131    }
132   
133    protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
134    {
135      Comment o = other as Comment;
136      return o != null && this.CommentType == o.CommentType && MatchString(this.Content, o.Content);
137    }
138  }
139}
140
Note: See TracBrowser for help on using the repository browser.