-
Notifications
You must be signed in to change notification settings - Fork 4k
/
SyntaxNodePartials.vb
133 lines (109 loc) · 6.16 KB
/
SyntaxNodePartials.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
'-----------------------------------------------------------------------------------------------------------
' Contains hand-written Partial class extensions to certain of the syntax nodes (other that the
' base node SyntaxNode, which is in a different file.)
'-----------------------------------------------------------------------------------------------------------
Imports System.Threading
Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.VisualBasic.Symbols
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Namespace Microsoft.CodeAnalysis.VisualBasic.Syntax
Public Partial Class DocumentationCommentTriviaSyntax
Friend Function GetInteriorXml() As String
' NOTE: is only used in parse tests
Return DirectCast(Me.Green, InternalSyntax.DocumentationCommentTriviaSyntax).GetInteriorXml
End Function
End Class
Public Partial Class DirectiveTriviaSyntax
Private Shared ReadOnly s_hasDirectivesFunction As Func(Of SyntaxToken, Boolean) = Function(n) n.ContainsDirectives
Public Function GetNextDirective(Optional predicate As Func(Of DirectiveTriviaSyntax, Boolean) = Nothing) As DirectiveTriviaSyntax
Dim token = CType(MyBase.ParentTrivia.Token, SyntaxToken)
Dim [next] As Boolean = False
Do While (token.Kind <> SyntaxKind.None)
Dim tr As SyntaxTrivia
For Each tr In token.LeadingTrivia
If [next] Then
If tr.IsDirective Then
Dim d As DirectiveTriviaSyntax = DirectCast(tr.GetStructure, DirectiveTriviaSyntax)
If ((predicate Is Nothing) OrElse predicate.Invoke(d)) Then
Return d
End If
End If
Continue For
End If
If (tr.UnderlyingNode Is MyBase.Green) Then
[next] = True
End If
Next
token = token.GetNextToken(s_hasDirectivesFunction)
Loop
Return Nothing
End Function
Public Function GetPreviousDirective(Optional predicate As Func(Of DirectiveTriviaSyntax, Boolean) = Nothing) As DirectiveTriviaSyntax
Dim token As SyntaxToken = CType(MyBase.ParentTrivia.Token, SyntaxToken)
Dim [next] As Boolean = False
Do While (token.Kind <> SyntaxKind.None)
For Each tr In token.LeadingTrivia.Reverse()
If [next] Then
If tr.IsDirective Then
Dim d As DirectiveTriviaSyntax = DirectCast(tr.GetStructure, DirectiveTriviaSyntax)
If ((predicate Is Nothing) OrElse predicate.Invoke(d)) Then
Return d
End If
End If
ElseIf (tr.UnderlyingNode Is MyBase.Green) Then
[next] = True
End If
Next
token = token.GetPreviousToken(s_hasDirectivesFunction)
Loop
Return Nothing
End Function
End Class
Partial Public Class SingleLineLambdaExpressionSyntax
''' <summary>
''' Single line subs only have a single statement. However, when binding it is convenient to have a statement list. For example,
''' dim statements are not valid in a single line lambda. However, it is nice to be able to provide semantic info about the local.
''' The only way to create locals is to have a statement list. This method is friend because the statement list should not be part
''' of the public api.
''' </summary>
Friend ReadOnly Property Statements As SyntaxList(Of StatementSyntax)
Get
Debug.Assert(Kind = SyntaxKind.SingleLineSubLambdaExpression, "Only SingleLineSubLambdas have statements.")
Debug.Assert(GetNodeSlot(1) Is Body, "SingleLineLambdaExpressionSyntax structure has changed. Update index passed to GetChildIndex.")
Return New SyntaxList(Of StatementSyntax)(Body)
End Get
End Property
End Class
Public Partial Class MethodBaseSyntax
Friend ReadOnly Property AsClauseInternal As AsClauseSyntax
Get
Select Case Me.Kind
Case SyntaxKind.SubStatement, SyntaxKind.FunctionStatement
Return DirectCast(Me, MethodStatementSyntax).AsClause
Case SyntaxKind.SubLambdaHeader, SyntaxKind.FunctionLambdaHeader
Return DirectCast(Me, LambdaHeaderSyntax).AsClause
Case SyntaxKind.DeclareSubStatement, SyntaxKind.DeclareFunctionStatement
Return DirectCast(Me, DeclareStatementSyntax).AsClause
Case SyntaxKind.DelegateSubStatement, SyntaxKind.DelegateFunctionStatement
Return DirectCast(Me, DelegateStatementSyntax).AsClause
Case SyntaxKind.EventStatement
Return DirectCast(Me, EventStatementSyntax).AsClause
Case SyntaxKind.OperatorStatement
Return DirectCast(Me, OperatorStatementSyntax).AsClause
Case SyntaxKind.PropertyStatement
Return DirectCast(Me, PropertyStatementSyntax).AsClause
Case SyntaxKind.SubNewStatement,
SyntaxKind.GetAccessorStatement,
SyntaxKind.SetAccessorStatement,
SyntaxKind.AddHandlerAccessorStatement,
SyntaxKind.RemoveHandlerAccessorStatement,
SyntaxKind.RaiseEventAccessorStatement
Return Nothing
Case Else
Throw ExceptionUtilities.UnexpectedValue(Me.Kind)
End Select
End Get
End Property
End Class
End Namespace