Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.NRefactory/5.5.0/NRefactory.CSharp-5.5.0/Ast/GeneralScope/TypeParameterDeclaration.cs @ 11807

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

#2077: created branch and added first version

File size: 3.5 KB
Line 
1// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4// software and associated documentation files (the "Software"), to deal in the Software
5// without restriction, including without limitation the rights to use, copy, modify, merge,
6// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7// to whom the Software is furnished to do so, subject to the following conditions:
8//
9// The above copyright notice and this permission notice shall be included in all copies or
10// substantial portions of the Software.
11//
12// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17// DEALINGS IN THE SOFTWARE.
18
19using System;
20using ICSharpCode.NRefactory.TypeSystem;
21
22namespace ICSharpCode.NRefactory.CSharp
23{
24  /// <summary>
25  /// [in|out] Name
26  ///
27  /// Represents a type parameter.
28  /// Note: mirroring the C# syntax, constraints are not part of the type parameter declaration, but belong
29  /// to the parent type or method.
30  /// </summary>
31  public class TypeParameterDeclaration : AstNode
32  {
33    public static readonly Role<AttributeSection> AttributeRole = EntityDeclaration.AttributeRole;
34    public static readonly TokenRole OutVarianceKeywordRole = new TokenRole ("out");
35    public static readonly TokenRole InVarianceKeywordRole = new TokenRole ("in");
36   
37    public override NodeType NodeType {
38      get { return NodeType.Unknown; }
39    }
40   
41    public AstNodeCollection<AttributeSection> Attributes {
42      get { return GetChildrenByRole (AttributeRole); }
43    }
44   
45    VarianceModifier variance;
46   
47    public VarianceModifier Variance {
48      get { return variance; }
49      set { ThrowIfFrozen(); variance = value; }
50    }
51   
52    public CSharpTokenNode VarianceToken {
53      get {
54        switch (Variance) {
55          case VarianceModifier.Covariant:
56            return GetChildByRole(OutVarianceKeywordRole);
57          case VarianceModifier.Contravariant:
58            return GetChildByRole(InVarianceKeywordRole);
59          default:
60            return CSharpTokenNode.Null;
61        }
62      }
63    }
64   
65    public string Name {
66      get {
67        return GetChildByRole (Roles.Identifier).Name;
68      }
69      set {
70        SetChildByRole(Roles.Identifier, Identifier.Create (value));
71      }
72    }
73   
74    public Identifier NameToken {
75      get {
76        return GetChildByRole (Roles.Identifier);
77      }
78      set {
79        SetChildByRole (Roles.Identifier, value);
80      }
81    }
82
83    public TypeParameterDeclaration ()
84    {
85    }
86
87    public TypeParameterDeclaration (string name)
88    {
89      Name = name;
90    }
91
92    public override void AcceptVisitor (IAstVisitor visitor)
93    {
94      visitor.VisitTypeParameterDeclaration (this);
95    }
96   
97    public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
98    {
99      return visitor.VisitTypeParameterDeclaration (this);
100    }
101   
102    public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
103    {
104      return visitor.VisitTypeParameterDeclaration(this, data);
105    }
106   
107    protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
108    {
109      TypeParameterDeclaration o = other as TypeParameterDeclaration;
110      return o != null && this.Variance == o.Variance && MatchString(this.Name, o.Name) && this.Attributes.DoMatch(o.Attributes, match);
111    }
112  }
113}
Note: See TracBrowser for help on using the repository browser.