1 | // |
---|
2 | // AttributeSection.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 | |
---|
27 | using System; |
---|
28 | using System.Collections.Generic; |
---|
29 | using System.Linq; |
---|
30 | |
---|
31 | namespace ICSharpCode.NRefactory.CSharp |
---|
32 | { |
---|
33 | /// <summary> |
---|
34 | /// [AttributeTarget: Attributes] |
---|
35 | /// </summary> |
---|
36 | public class AttributeSection : AstNode |
---|
37 | { |
---|
38 | #region PatternPlaceholder |
---|
39 | public static implicit operator AttributeSection(PatternMatching.Pattern pattern) |
---|
40 | { |
---|
41 | return pattern != null ? new PatternPlaceholder(pattern) : null; |
---|
42 | } |
---|
43 | |
---|
44 | sealed class PatternPlaceholder : AttributeSection, PatternMatching.INode |
---|
45 | { |
---|
46 | readonly PatternMatching.Pattern child; |
---|
47 | |
---|
48 | public PatternPlaceholder(PatternMatching.Pattern child) |
---|
49 | { |
---|
50 | this.child = child; |
---|
51 | } |
---|
52 | |
---|
53 | public override NodeType NodeType { |
---|
54 | get { return NodeType.Pattern; } |
---|
55 | } |
---|
56 | |
---|
57 | public override void AcceptVisitor (IAstVisitor visitor) |
---|
58 | { |
---|
59 | visitor.VisitPatternPlaceholder (this, child); |
---|
60 | } |
---|
61 | |
---|
62 | public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
---|
63 | { |
---|
64 | return visitor.VisitPatternPlaceholder (this, child); |
---|
65 | } |
---|
66 | |
---|
67 | public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
---|
68 | { |
---|
69 | return visitor.VisitPatternPlaceholder(this, child, data); |
---|
70 | } |
---|
71 | |
---|
72 | protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
---|
73 | { |
---|
74 | return child.DoMatch(other, match); |
---|
75 | } |
---|
76 | |
---|
77 | bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo) |
---|
78 | { |
---|
79 | return child.DoMatchCollection(role, pos, match, backtrackingInfo); |
---|
80 | } |
---|
81 | } |
---|
82 | #endregion |
---|
83 | |
---|
84 | public override NodeType NodeType { |
---|
85 | get { |
---|
86 | return NodeType.Unknown; |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | public CSharpTokenNode LBracketToken { |
---|
91 | get { return GetChildByRole (Roles.LBracket); } |
---|
92 | } |
---|
93 | |
---|
94 | public string AttributeTarget { |
---|
95 | get { |
---|
96 | return GetChildByRole (Roles.Identifier).Name; |
---|
97 | } |
---|
98 | set { |
---|
99 | SetChildByRole (Roles.Identifier, CSharp.Identifier.Create (value)); |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | public Identifier AttributeTargetToken { |
---|
104 | get { |
---|
105 | return GetChildByRole (Roles.Identifier); |
---|
106 | } |
---|
107 | set { |
---|
108 | SetChildByRole (Roles.Identifier, value); |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | public AstNodeCollection<Attribute> Attributes { |
---|
113 | get { return base.GetChildrenByRole (Roles.Attribute); } |
---|
114 | } |
---|
115 | |
---|
116 | public CSharpTokenNode RBracketToken { |
---|
117 | get { return GetChildByRole (Roles.RBracket); } |
---|
118 | } |
---|
119 | |
---|
120 | public override void AcceptVisitor (IAstVisitor visitor) |
---|
121 | { |
---|
122 | visitor.VisitAttributeSection (this); |
---|
123 | } |
---|
124 | |
---|
125 | public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
---|
126 | { |
---|
127 | return visitor.VisitAttributeSection (this); |
---|
128 | } |
---|
129 | |
---|
130 | public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
---|
131 | { |
---|
132 | return visitor.VisitAttributeSection (this, data); |
---|
133 | } |
---|
134 | |
---|
135 | protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
---|
136 | { |
---|
137 | AttributeSection o = other as AttributeSection; |
---|
138 | return o != null && MatchString(this.AttributeTarget, o.AttributeTarget) && this.Attributes.DoMatch(o.Attributes, match); |
---|
139 | } |
---|
140 | |
---|
141 | public AttributeSection() |
---|
142 | { |
---|
143 | } |
---|
144 | |
---|
145 | public AttributeSection(Attribute attr) |
---|
146 | { |
---|
147 | this.Attributes.Add(attr); |
---|
148 | } |
---|
149 | |
---|
150 | // public static string GetAttributeTargetName(AttributeTarget attributeTarget) |
---|
151 | // { |
---|
152 | // switch (attributeTarget) { |
---|
153 | // case AttributeTarget.None: |
---|
154 | // return null; |
---|
155 | // case AttributeTarget.Assembly: |
---|
156 | // return "assembly"; |
---|
157 | // case AttributeTarget.Module: |
---|
158 | // return "module"; |
---|
159 | // case AttributeTarget.Type: |
---|
160 | // return "type"; |
---|
161 | // case AttributeTarget.Param: |
---|
162 | // return "param"; |
---|
163 | // case AttributeTarget.Field: |
---|
164 | // return "field"; |
---|
165 | // case AttributeTarget.Return: |
---|
166 | // return "return"; |
---|
167 | // case AttributeTarget.Method: |
---|
168 | // return "method"; |
---|
169 | // default: |
---|
170 | // throw new NotSupportedException("Invalid value for AttributeTarget"); |
---|
171 | // } |
---|
172 | // } |
---|
173 | } |
---|
174 | } |
---|