5
// Mike Krüger <mkrueger@novell.com>
7
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
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:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
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
28
using System.Collections.Generic;
31
namespace ICSharpCode.NRefactory.CSharp
34
/// [AttributeTarget: Attributes]
36
public class AttributeSection : AstNode
38
#region PatternPlaceholder
39
public static implicit operator AttributeSection(PatternMatching.Pattern pattern)
41
return pattern != null ? new PatternPlaceholder(pattern) : null;
44
sealed class PatternPlaceholder : AttributeSection, PatternMatching.INode
46
readonly PatternMatching.Pattern child;
48
public PatternPlaceholder(PatternMatching.Pattern child)
53
public override NodeType NodeType {
54
get { return NodeType.Pattern; }
57
public override void AcceptVisitor (IAstVisitor visitor)
59
visitor.VisitPatternPlaceholder (this, child);
62
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
64
return visitor.VisitPatternPlaceholder (this, child);
67
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
69
return visitor.VisitPatternPlaceholder(this, child, data);
72
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
74
return child.DoMatch(other, match);
77
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo)
79
return child.DoMatchCollection(role, pos, match, backtrackingInfo);
84
public override NodeType NodeType {
86
return NodeType.Unknown;
90
public CSharpTokenNode LBracketToken {
91
get { return GetChildByRole (Roles.LBracket); }
94
public string AttributeTarget {
96
return GetChildByRole (Roles.Identifier).Name;
99
SetChildByRole (Roles.Identifier, CSharp.Identifier.Create (value));
103
public Identifier AttributeTargetToken {
105
return GetChildByRole (Roles.Identifier);
108
SetChildByRole (Roles.Identifier, value);
112
public AstNodeCollection<Attribute> Attributes {
113
get { return base.GetChildrenByRole (Roles.Attribute); }
116
public CSharpTokenNode RBracketToken {
117
get { return GetChildByRole (Roles.RBracket); }
120
public override void AcceptVisitor (IAstVisitor visitor)
122
visitor.VisitAttributeSection (this);
125
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
127
return visitor.VisitAttributeSection (this);
130
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
132
return visitor.VisitAttributeSection (this, data);
135
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
137
AttributeSection o = other as AttributeSection;
138
return o != null && this.AttributeTarget == o.AttributeTarget && this.Attributes.DoMatch(o.Attributes, match);
141
public AttributeSection()
145
public AttributeSection(Attribute attr)
147
this.Attributes.Add(attr);
150
// public static string GetAttributeTargetName(AttributeTarget attributeTarget)
152
// switch (attributeTarget) {
153
// case AttributeTarget.None:
155
// case AttributeTarget.Assembly:
156
// return "assembly";
157
// case AttributeTarget.Module:
159
// case AttributeTarget.Type:
161
// case AttributeTarget.Param:
163
// case AttributeTarget.Field:
165
// case AttributeTarget.Return:
167
// case AttributeTarget.Method:
170
// throw new NotSupportedException("Invalid value for AttributeTarget");
175
public enum AttributeTarget {