Free cookie consent management tool by TermsFeed Policy Generator

source: branches/CodeEditor/HeuristicLab.ExtLibs/HeuristicLab.NRefactory/5.5.0/NRefactory.CSharp-5.5.0/Ast/TypeMembers/ConstructorDeclaration.cs @ 11700

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

#2077: created branch and added first version

File size: 5.5 KB
Line 
1//
2// ConstructorDeclaration.cs
3//
4// Author:
5//       Mike Krüger <mkrueger@novell.com>
6//
7// Copyright (c) 2009 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
27using ICSharpCode.NRefactory.TypeSystem;
28
29namespace ICSharpCode.NRefactory.CSharp
30{
31  public class ConstructorDeclaration : EntityDeclaration
32  {
33    public static readonly Role<ConstructorInitializer> InitializerRole = new Role<ConstructorInitializer>("Initializer", ConstructorInitializer.Null);
34   
35    public override SymbolKind SymbolKind {
36      get { return SymbolKind.Constructor; }
37    }
38   
39    public CSharpTokenNode LParToken {
40      get { return GetChildByRole (Roles.LPar); }
41    }
42   
43    public AstNodeCollection<ParameterDeclaration> Parameters {
44      get { return GetChildrenByRole (Roles.Parameter); }
45    }
46   
47    public CSharpTokenNode RParToken {
48      get { return GetChildByRole (Roles.RPar); }
49    }
50   
51    public CSharpTokenNode ColonToken {
52      get { return GetChildByRole (Roles.Colon); }
53    }
54   
55    public ConstructorInitializer Initializer {
56      get { return GetChildByRole (InitializerRole); }
57      set { SetChildByRole( InitializerRole, value); }
58    }
59   
60    public BlockStatement Body {
61      get { return GetChildByRole (Roles.Body); }
62      set { SetChildByRole (Roles.Body, value); }
63    }
64   
65    public override void AcceptVisitor (IAstVisitor visitor)
66    {
67      visitor.VisitConstructorDeclaration (this);
68    }
69     
70    public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
71    {
72      return visitor.VisitConstructorDeclaration (this);
73    }
74   
75    public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
76    {
77      return visitor.VisitConstructorDeclaration (this, data);
78    }
79   
80    protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
81    {
82      ConstructorDeclaration o = other as ConstructorDeclaration;
83      return o != null && this.MatchAttributesAndModifiers(o, match) && this.Parameters.DoMatch(o.Parameters, match)
84        && this.Initializer.DoMatch(o.Initializer, match) && this.Body.DoMatch(o.Body, match);
85    }
86  }
87 
88  public enum ConstructorInitializerType {
89    Any,
90    Base,
91    This
92  }
93 
94  public class ConstructorInitializer : AstNode
95  {
96    public static readonly TokenRole BaseKeywordRole = new TokenRole ("base");
97    public static readonly TokenRole ThisKeywordRole = new TokenRole ("this");
98   
99    public static readonly new ConstructorInitializer Null = new NullConstructorInitializer ();
100    class NullConstructorInitializer : ConstructorInitializer
101    {
102      public override NodeType NodeType {
103        get {
104          return NodeType.Unknown;
105        }
106      }
107     
108      public override bool IsNull {
109        get {
110          return true;
111        }
112      }
113     
114      public override void AcceptVisitor (IAstVisitor visitor)
115      {
116        visitor.VisitNullNode(this);
117      }
118     
119      public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
120      {
121        return visitor.VisitNullNode(this);
122      }
123     
124      public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
125      {
126        return visitor.VisitNullNode(this, data);
127      }
128     
129      protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
130      {
131        return other == null || other.IsNull;
132      }
133    }
134   
135    public override NodeType NodeType {
136      get {
137        return NodeType.Unknown;
138      }
139    }
140   
141    public ConstructorInitializerType ConstructorInitializerType {
142      get;
143      set;
144    }
145   
146    public CSharpTokenNode Keyword {
147      get {
148        if (ConstructorInitializerType == ConstructorInitializerType.Base)
149          return GetChildByRole(BaseKeywordRole);
150        else
151          return GetChildByRole(ThisKeywordRole);
152      }
153    }
154   
155    public CSharpTokenNode LParToken {
156      get { return GetChildByRole (Roles.LPar); }
157    }
158   
159    public AstNodeCollection<Expression> Arguments {
160      get { return GetChildrenByRole (Roles.Argument); }
161    }
162   
163    public CSharpTokenNode RParToken {
164      get { return GetChildByRole (Roles.RPar); }
165    }
166   
167    public override void AcceptVisitor (IAstVisitor visitor)
168    {
169      visitor.VisitConstructorInitializer (this);
170    }
171     
172    public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
173    {
174      return visitor.VisitConstructorInitializer (this);
175    }
176   
177    public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
178    {
179      return visitor.VisitConstructorInitializer (this, data);
180    }
181   
182    protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
183    {
184      ConstructorInitializer o = other as ConstructorInitializer;
185      return o != null && !o.IsNull
186        && (this.ConstructorInitializerType == ConstructorInitializerType.Any || this.ConstructorInitializerType == o.ConstructorInitializerType)
187        && this.Arguments.DoMatch(o.Arguments, match);
188    }
189  }
190}
Note: See TracBrowser for help on using the repository browser.