-
Notifications
You must be signed in to change notification settings - Fork 4k
/
HandledEvent.vb
117 lines (93 loc) · 3.71 KB
/
HandledEvent.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Collections.Generic
Imports System.Threading
Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.VisualBasic.Symbols
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Namespace Microsoft.CodeAnalysis.VisualBasic
''' <summary>
''' represents a single item in Handles list.
''' </summary>
Public NotInheritable Class HandledEvent
Friend Sub New(kind As HandledEventKind,
eventSymbol As EventSymbol,
withEventsContainerOpt As PropertySymbol,
withEventsSourcePropertyOpt As PropertySymbol,
delegateCreation As BoundExpression,
hookupMethod As MethodSymbol)
Me._kind = kind
Debug.Assert(eventSymbol IsNot Nothing)
Me._eventSymbol = eventSymbol
Debug.Assert((withEventsContainerOpt Is Nothing) Or kind = HandledEventKind.WithEvents)
Me._WithEventsContainerOpt = withEventsContainerOpt
Me._WithEventsSourcePropertyOpt = withEventsSourcePropertyOpt
Me.delegateCreation = delegateCreation
Me.hookupMethod = hookupMethod
End Sub
' kind of Handles
Private ReadOnly _kind As HandledEventKind
' E1 in "Handles obj.E1"
Private ReadOnly _eventSymbol As EventSymbol
' obj in "Handles obj.E1"
' only makes sense when kind is WithEvents.
Private ReadOnly _WithEventsContainerOpt As PropertySymbol
' P1 in "Handles obj.P1.E1"
' only makes sense when kind is WithEvents.
Private ReadOnly _WithEventsSourcePropertyOpt As PropertySymbol
''' <summary>
''' Kind of Handles event container. (Me, MyBase, MyClass or a WithEvents variable)
''' </summary>
Public ReadOnly Property HandlesKind As HandledEventKind
Get
Return _kind
End Get
End Property
''' <summary>
''' Symbol for the event handled in current Handles item.
''' </summary>
Public ReadOnly Property EventSymbol As IEventSymbol
Get
Return _eventSymbol
End Get
End Property
Public ReadOnly Property EventContainer As IPropertySymbol
Get
Return _WithEventsContainerOpt
End Get
End Property
Public ReadOnly Property WithEventsSourceProperty As IPropertySymbol
Get
Return _WithEventsSourcePropertyOpt
End Get
End Property
' delegate creation expression used to hook/unhook handlers
' note that it may contain relaxation lambdas and will need to be injected
' into the host method before lowering.
' Used in rewriter.
Friend ReadOnly delegateCreation As BoundExpression
' this is the host method into which hookups will be injected
' Used in rewriter.
Friend ReadOnly hookupMethod As MethodSymbol
End Class
''' <summary>
''' Kind of a Handles item represented by a HandledEvent
''' </summary>
Public Enum HandledEventKind
''' <summary>
''' Handles Me.Event1
''' </summary>
[Me] = 0
''' <summary>
''' Handles MyClass.Event1
''' </summary>
[MyClass] = 1
''' <summary>
''' Handles MyBase.Event1
''' </summary>
[MyBase] = 2
''' <summary>
''' Handles SomeWithEventsVariable.Event1
''' </summary>
[WithEvents] = 3
End Enum
End Namespace