1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
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:
9
// The above copyright notice and this permission notice shall be included in all copies or
10
// substantial portions of the Software.
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.
20
using ICSharpCode.NRefactory.TypeSystem;
22
namespace ICSharpCode.NRefactory.CSharp
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.
31
public class TypeParameterDeclaration : AstNode
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");
37
public override NodeType NodeType {
38
get { return NodeType.Unknown; }
41
public AstNodeCollection<AttributeSection> Attributes {
42
get { return GetChildrenByRole (AttributeRole); }
45
VarianceModifier variance;
47
public VarianceModifier Variance {
48
get { return variance; }
49
set { ThrowIfFrozen(); variance = value; }
52
public CSharpTokenNode VarianceToken {
55
case VarianceModifier.Covariant:
56
return GetChildByRole(OutVarianceKeywordRole);
57
case VarianceModifier.Contravariant:
58
return GetChildByRole(InVarianceKeywordRole);
60
return CSharpTokenNode.Null;
67
return GetChildByRole (Roles.Identifier).Name;
70
SetChildByRole(Roles.Identifier, Identifier.Create (value));
74
public Identifier NameToken {
76
return GetChildByRole (Roles.Identifier);
79
SetChildByRole (Roles.Identifier, value);
83
public TypeParameterDeclaration ()
87
public TypeParameterDeclaration (string name)
92
public override void AcceptVisitor (IAstVisitor visitor)
94
visitor.VisitTypeParameterDeclaration (this);
97
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
99
return visitor.VisitTypeParameterDeclaration (this);
102
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
104
return visitor.VisitTypeParameterDeclaration(this, data);
107
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
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);