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;
29
using System.ComponentModel;
31
using ICSharpCode.NRefactory.TypeSystem;
33
namespace ICSharpCode.NRefactory.CSharp
35
public class EventDeclaration : EntityDeclaration
37
public static readonly TokenRole EventKeywordRole = new TokenRole ("event");
39
public override EntityType EntityType {
40
get { return EntityType.Event; }
43
public AstNodeCollection<VariableInitializer> Variables {
44
get { return GetChildrenByRole (Roles.Variable); }
47
// Hide .Name and .NameToken from users; the actual field names
48
// are stored in the VariableInitializer.
49
[EditorBrowsable(EditorBrowsableState.Never)]
50
public override string Name {
51
get { return string.Empty; }
52
set { throw new NotSupportedException(); }
55
[EditorBrowsable(EditorBrowsableState.Never)]
56
public override Identifier NameToken {
57
get { return Identifier.Null; }
58
set { throw new NotSupportedException(); }
61
public override void AcceptVisitor (IAstVisitor visitor)
63
visitor.VisitEventDeclaration (this);
66
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
68
return visitor.VisitEventDeclaration (this);
71
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
73
return visitor.VisitEventDeclaration (this, data);
76
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
78
EventDeclaration o = other as EventDeclaration;
79
return o != null && this.MatchAttributesAndModifiers(o, match)
80
&& this.ReturnType.DoMatch(o.ReturnType, match) && this.Variables.DoMatch(o.Variables, match);
84
public class CustomEventDeclaration : EntityDeclaration
86
public static readonly TokenRole EventKeywordRole = new TokenRole ("event");
87
public static readonly TokenRole AddKeywordRole = new TokenRole ("add");
88
public static readonly TokenRole RemoveKeywordRole = new TokenRole ("remove");
90
public static readonly Role<Accessor> AddAccessorRole = new Role<Accessor>("AddAccessor", Accessor.Null);
91
public static readonly Role<Accessor> RemoveAccessorRole = new Role<Accessor>("RemoveAccessor", Accessor.Null);
93
public override EntityType EntityType {
94
get { return EntityType.Event; }
98
/// Gets/Sets the type reference of the interface that is explicitly implemented.
99
/// Null node if this member is not an explicit interface implementation.
101
public AstType PrivateImplementationType {
102
get { return GetChildByRole (PrivateImplementationTypeRole); }
103
set { SetChildByRole (PrivateImplementationTypeRole, value); }
106
public CSharpTokenNode LBraceToken {
107
get { return GetChildByRole (Roles.LBrace); }
110
public Accessor AddAccessor {
111
get { return GetChildByRole (AddAccessorRole); }
112
set { SetChildByRole (AddAccessorRole, value); }
115
public Accessor RemoveAccessor {
116
get { return GetChildByRole (RemoveAccessorRole); }
117
set { SetChildByRole (RemoveAccessorRole, value); }
120
public CSharpTokenNode RBraceToken {
121
get { return GetChildByRole (Roles.RBrace); }
124
public override void AcceptVisitor (IAstVisitor visitor)
126
visitor.VisitCustomEventDeclaration (this);
129
public override T AcceptVisitor<T> (IAstVisitor<T> visitor)
131
return visitor.VisitCustomEventDeclaration (this);
134
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
136
return visitor.VisitCustomEventDeclaration (this, data);
139
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
141
CustomEventDeclaration o = other as CustomEventDeclaration;
142
return o != null && MatchString(this.Name, o.Name)
143
&& this.MatchAttributesAndModifiers(o, match) && this.ReturnType.DoMatch(o.ReturnType, match)
144
&& this.PrivateImplementationType.DoMatch(o.PrivateImplementationType, match)
145
&& this.AddAccessor.DoMatch(o.AddAccessor, match) && this.RemoveAccessor.DoMatch(o.RemoveAccessor, match);