/
SyntaxFactory.vb
1126 lines (980 loc) · 70.4 KB
/
SyntaxFactory.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
' Licensed to the .NET Foundation under one or more agreements.
' The .NET Foundation licenses this file to you under the MIT license.
' See the LICENSE file in the project root for more information.
Imports System.Xml.Linq
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Imports VbObjectDisplay = Microsoft.CodeAnalysis.VisualBasic.ObjectDisplay.ObjectDisplay
Imports Parser = Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.Parser
Imports Feature = Microsoft.CodeAnalysis.VisualBasic.Syntax.InternalSyntax.Feature
Namespace Microsoft.CodeAnalysis.VisualBasic
Partial Public Class SyntaxFactory
''' <summary>
''' A trivia with kind EndOfLineTrivia containing both the carriage return And line feed characters.
''' </summary>
Public Shared ReadOnly Property CarriageReturnLineFeed As SyntaxTrivia = CType(InternalSyntax.SyntaxFactory.CarriageReturnLineFeed, SyntaxTrivia)
''' <summary>
''' A trivia with kind EndOfLineTrivia containing a single line feed character.
''' </summary>
Public Shared ReadOnly Property LineFeed As SyntaxTrivia = CType(InternalSyntax.SyntaxFactory.LineFeed, SyntaxTrivia)
''' <summary>
''' A trivia with kind EndOfLineTrivia containing a single carriage return character.
''' </summary>
Public Shared ReadOnly Property CarriageReturn As SyntaxTrivia = CType(InternalSyntax.SyntaxFactory.CarriageReturn, SyntaxTrivia)
''' <summary>
''' A trivia with kind WhitespaceTrivia containing a single space character.
''' </summary>
Public Shared ReadOnly Property Space As SyntaxTrivia = CType(InternalSyntax.SyntaxFactory.Space, SyntaxTrivia)
''' <summary>
''' A trivia with kind WhitespaceTrivia containing a single tab character.
''' </summary>
Public Shared ReadOnly Property Tab As SyntaxTrivia = CType(InternalSyntax.SyntaxFactory.Tab, SyntaxTrivia)
''' <summary>
''' An elastic trivia with kind EndOfLineTrivia containing both the carriage return And line feed characters.
''' Elastic trivia are used to denote trivia that was Not produced by parsing source text, And are usually Not
''' preserved during formatting.
''' </summary>
Public Shared ReadOnly Property ElasticCarriageReturnLineFeed As SyntaxTrivia = CType(InternalSyntax.SyntaxFactory.ElasticCarriageReturnLineFeed, SyntaxTrivia)
''' <summary>
''' An elastic trivia with kind EndOfLineTrivia containing a single line feed character. Elastic trivia are used
''' to denote trivia that was Not produced by parsing source text, And are usually Not preserved during
''' formatting.
''' </summary>
Public Shared ReadOnly Property ElasticLineFeed As SyntaxTrivia = CType(InternalSyntax.SyntaxFactory.ElasticLineFeed, SyntaxTrivia)
''' <summary>
''' An elastic trivia with kind EndOfLineTrivia containing a single carriage return character. Elastic trivia
''' are used to denote trivia that was Not produced by parsing source text, And are usually Not preserved during
''' formatting.
''' </summary>
Public Shared ReadOnly Property ElasticCarriageReturn As SyntaxTrivia = CType(InternalSyntax.SyntaxFactory.ElasticCarriageReturn, SyntaxTrivia)
''' <summary>
''' An elastic trivia with kind WhitespaceTrivia containing a single space character. Elastic trivia are used to
''' denote trivia that was Not produced by parsing source text, And are usually Not preserved during formatting.
''' </summary>
Public Shared ReadOnly Property ElasticSpace As SyntaxTrivia = CType(InternalSyntax.SyntaxFactory.ElasticSpace, SyntaxTrivia)
''' <summary>
''' An elastic trivia with kind WhitespaceTrivia containing a single tab character. Elastic trivia are used to
''' denote trivia that was Not produced by parsing source text, And are usually Not preserved during formatting.
''' </summary>
Public Shared ReadOnly Property ElasticTab As SyntaxTrivia = CType(InternalSyntax.SyntaxFactory.ElasticTab, SyntaxTrivia)
''' <summary>
''' An elastic trivia with kind WhitespaceTrivia containing no characters. Elastic marker trivia are included
''' automatically by factory methods when trivia Is Not specified. Syntax formatting will replace elastic
''' markers with appropriate trivia.
''' </summary>
Public Shared ReadOnly Property ElasticMarker As SyntaxTrivia = CType(InternalSyntax.SyntaxFactory.ElasticZeroSpace, SyntaxTrivia)
Private Shared ReadOnly s_elasticMarkerList As SyntaxTriviaList = SyntaxFactory.TriviaList(CType(InternalSyntax.SyntaxFactory.ElasticZeroSpace, SyntaxTrivia))
''' <summary>
''' Creates a trivia with kind EndOfLineTrivia containing the specified text.
''' </summary>
''' <param name="text">The text of the end of line. Any text can be specified here, however only carriage return And
''' line feed characters are recognized by the parser as end of line.</param>
Public Shared Function EndOfLine(text As String) As SyntaxTrivia
Return CType(InternalSyntax.SyntaxFactory.EndOfLine(text, elastic:=False), SyntaxTrivia)
End Function
''' <summary>
''' Creates a trivia with kind EndOfLineTrivia containing the specified text. Elastic trivia are used to
''' denote trivia that was Not produced by parsing source text, And are usually Not preserved during formatting.
''' </summary>
''' <param name="text">The text of the end of line. Any text can be specified here, however only carriage return And
''' line feed characters are recognized by the parser as end of line.</param>
Public Shared Function ElasticEndOfLine(text As String) As SyntaxTrivia
Return CType(InternalSyntax.SyntaxFactory.EndOfLine(text, elastic:=True), SyntaxTrivia)
End Function
<Obsolete("Use SyntaxFactory.EndOfLine or SyntaxFactory.ElasticEndOfLine")>
<System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)>
Public Shared Function EndOfLine(text As String, elastic As Boolean) As SyntaxTrivia
Return CType(InternalSyntax.SyntaxFactory.EndOfLine(text, elastic), SyntaxTrivia)
End Function
''' <summary>
''' Creates a trivia with kind WhitespaceTrivia containing the specified text.
''' </summary>
''' <param name="text">The text of the whitespace. Any text can be specified here, however only specific
''' whitespace characters are recognized by the parser.</param>
Public Shared Function Whitespace(text As String) As SyntaxTrivia
Return CType(InternalSyntax.SyntaxFactory.Whitespace(text, elastic:=False), SyntaxTrivia)
End Function
''' <summary>
''' Creates a trivia with kind WhitespaceTrivia containing the specified text. Elastic trivia are used to
''' denote trivia that was Not produced by parsing source text, And are usually Not preserved during formatting.
''' </summary>
''' <param name="text">The text of the whitespace. Any text can be specified here, however only specific
''' whitespace characters are recognized by the parser.</param>
Public Shared Function ElasticWhitespace(text As String) As SyntaxTrivia
Return CType(InternalSyntax.SyntaxFactory.Whitespace(text, elastic:=True), SyntaxTrivia)
End Function
<Obsolete("Use SyntaxFactory.Whitespace or SyntaxFactory.ElasticWhitespace")>
<System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)>
Public Shared Function Whitespace(text As String, elastic As Boolean) As SyntaxTrivia
Return CType(InternalSyntax.SyntaxFactory.Whitespace(text, elastic), SyntaxTrivia)
End Function
''' <summary>
''' Names on the right of qualified names and member access expressions are not stand-alone expressions.
''' This method returns the appropriate parent of name syntax nodes that are on right of these constructs.
''' </summary>
Public Shared Function GetStandaloneExpression(node As ExpressionSyntax) As ExpressionSyntax
Dim expr = TryCast(node, ExpressionSyntax)
If expr IsNot Nothing Then
Dim parent = TryCast(node.Parent, ExpressionSyntax)
If parent IsNot Nothing Then
Select Case node.Kind
Case SyntaxKind.IdentifierName, SyntaxKind.GenericName
Select Case parent.Kind
Case SyntaxKind.QualifiedName
If (DirectCast(parent, QualifiedNameSyntax)).Right Is node Then
Return parent
End If
Case SyntaxKind.SimpleMemberAccessExpression
If (DirectCast(parent, MemberAccessExpressionSyntax)).Name Is node Then
Return parent
End If
End Select
Case SyntaxKind.XmlBracketedName
Select Case parent.Kind
Case SyntaxKind.XmlElementAccessExpression, SyntaxKind.XmlAttributeAccessExpression, SyntaxKind.XmlDescendantAccessExpression
If (DirectCast(parent, XmlMemberAccessExpressionSyntax)).Name Is node Then
Return parent
End If
End Select
Case SyntaxKind.XmlElementStartTag, SyntaxKind.XmlElementEndTag
If parent.Kind = SyntaxKind.XmlElement Then
Return parent
End If
End Select
End If
End If
Return expr
End Function
Friend Shared Sub VerifySyntaxKindOfToken(kind As SyntaxKind)
Select Case kind
Case SyntaxKind.AddHandlerKeyword To SyntaxKind.EndOfXmlToken,
SyntaxKind.NameOfKeyword,
SyntaxKind.DollarSignDoubleQuoteToken,
SyntaxKind.InterpolatedStringTextToken,
SyntaxKind.EndOfInterpolatedStringToken
Case Else
Throw New ArgumentOutOfRangeException(NameOf(kind))
End Select
End Sub
Public Shared Function Token(kind As SyntaxKind, Optional text As String = Nothing) As SyntaxToken
VerifySyntaxKindOfToken(kind)
Return CType(InternalSyntax.SyntaxFactory.Token(ElasticMarker.UnderlyingNode, kind, ElasticMarker.UnderlyingNode, text), SyntaxToken)
End Function
Friend Shared Function Token(kind As SyntaxKind, trailing As SyntaxTrivia, Optional text As String = Nothing) As SyntaxToken
Return Token(kind, SyntaxTriviaList.Create(trailing), text)
End Function
Public Shared Function Token(kind As SyntaxKind, trailing As SyntaxTriviaList, Optional text As String = Nothing) As SyntaxToken
VerifySyntaxKindOfToken(kind)
Return CType(InternalSyntax.SyntaxFactory.Token(ElasticMarker.UnderlyingNode, kind, trailing.Node, text), SyntaxToken)
End Function
Public Shared Function Token(leading As SyntaxTriviaList, kind As SyntaxKind, Optional text As String = Nothing) As SyntaxToken
VerifySyntaxKindOfToken(kind)
Return CType(InternalSyntax.SyntaxFactory.Token(leading.Node, kind, ElasticMarker.UnderlyingNode, text), SyntaxToken)
End Function
Friend Shared Function Token(leading As SyntaxTrivia, kind As SyntaxKind, trailing As SyntaxTrivia, Optional text As String = Nothing) As SyntaxToken
Return Token(SyntaxTriviaList.Create(leading), kind, SyntaxTriviaList.Create(trailing), text)
End Function
Public Shared Function Token(leading As SyntaxTriviaList, kind As SyntaxKind, trailing As SyntaxTriviaList, Optional text As String = Nothing) As SyntaxToken
VerifySyntaxKindOfToken(kind)
Return CType(InternalSyntax.SyntaxFactory.Token(leading.Node, kind, trailing.Node, text), SyntaxToken)
End Function
''' <summary> Creates a token with kind IntegerLiteralToken from a 4-byte signed integer value. </summary>
''' <param name="value">The 4-byte signed integer value to be represented by the returned token.</param>
Public Shared Function Literal(value As Integer) As SyntaxToken
Return Literal(VbObjectDisplay.FormatLiteral(value, ObjectDisplayOptions.None), value)
End Function
''' <summary> Creates a token with kind IntegerLiteralToken from the text and corresponding 4-byte signed integer value. </summary>
''' <param name="text">The raw text of the literal.</param> <param name="value">The 4-byte signed integer value to be represented by the returned token.</param>
Public Shared Function Literal(text As String, value As Integer) As SyntaxToken
Return Literal(s_elasticMarkerList, text, value, s_elasticMarkerList)
End Function
''' <summary> Creates a token with kind IntegerLiteralToken from the text and corresponding 4-byte signed integer value. </summary>
''' <param name="leading">A list of trivia immediately preceding the token.</param>
''' <param name="text">The raw text of the literal.</param>
''' <param name="value">The 4-byte signed integer value to be represented by the returned token.</param>
''' <param name="trailing">A list of trivia immediately following the token.</param>
Public Shared Function Literal(leading As SyntaxTriviaList, text As String, value As Integer, trailing As SyntaxTriviaList) As SyntaxToken
Return CType(InternalSyntax.SyntaxFactory.IntegerLiteralToken(text, If(text.StartsWith("&H", StringComparison.OrdinalIgnoreCase), LiteralBase.Hexadecimal, If(text.StartsWith("&O", StringComparison.OrdinalIgnoreCase), LiteralBase.Octal, If(text.StartsWith("&B", StringComparison.OrdinalIgnoreCase), LiteralBase.Binary, LiteralBase.Decimal))), If(text.EndsWith("I", StringComparison.OrdinalIgnoreCase), TypeCharacter.IntegerLiteral, TypeCharacter.None), CULng(value),
leading.Node, trailing.Node), SyntaxToken)
End Function
''' <summary> Creates a token with kind IntegerLiteralToken from a 4-byte unsigned integer
''' value. </summary>
''' <param name="value">The 4-byte unsigned integer value to be represented by the returned token.</param>
Public Shared Function Literal(value As UInteger) As SyntaxToken
Return Literal(VbObjectDisplay.FormatLiteral(value, ObjectDisplayOptions.IncludeTypeSuffix), value)
End Function
''' <summary> Creates a token with kind IntegerLiteralToken from the text and corresponding 4-byte unsigned integer value. </summary>
''' <param name="text">The raw text of the literal.</param>
''' <param name="value">The 4-byte unsigned integer value to be represented by the returned token.</param>
Public Shared Function Literal(text As String, value As UInteger) As SyntaxToken
Return Literal(s_elasticMarkerList, text, value, s_elasticMarkerList)
End Function
''' <summary> Creates a token with kind IntegerLiteralToken from the text and corresponding 4-byte unsigned integer value. </summary>
''' <param name="leading">A list of trivia immediately preceding the token.</param>
''' <param name="text">The raw text of the literal.</param>
''' <param name="value">The 4-byte unsigned integer value to be represented by the returned token.</param>
''' <param name="trailing">A list of trivia immediately following the token.</param>
Public Shared Function Literal(leading As SyntaxTriviaList, text As String, value As UInteger, trailing As SyntaxTriviaList) As SyntaxToken
Return CType(InternalSyntax.SyntaxFactory.IntegerLiteralToken(text, If(text.StartsWith("&H", StringComparison.OrdinalIgnoreCase), LiteralBase.Hexadecimal, If(text.StartsWith("&O", StringComparison.OrdinalIgnoreCase), LiteralBase.Octal, If(text.StartsWith("&B", StringComparison.OrdinalIgnoreCase), LiteralBase.Binary, LiteralBase.Decimal))), If(text.EndsWith("UI", StringComparison.OrdinalIgnoreCase), TypeCharacter.UIntegerLiteral, TypeCharacter.None), value,
leading.Node, trailing.Node), SyntaxToken)
End Function
''' <summary> Creates a token with kind IntegerLiteralToken from an 8-byte signed integer value. </summary>
''' <param name="value">The 8-byte signed integer value to be represented by the returned token.</param>
Public Shared Function Literal(value As Long) As SyntaxToken
Return Literal(VbObjectDisplay.FormatLiteral(value, ObjectDisplayOptions.IncludeTypeSuffix), value)
End Function
''' <summary> Creates a token with kind IntegerLiteralToken from the text and corresponding 8-byte signed integer value. </summary>
''' <param name="text">The raw text of the literal.</param>
''' <param name="value">The 8-byte signed integer value to be represented by the returned token.</param>
Public Shared Function Literal(text As String, value As Long) As SyntaxToken
Return Literal(s_elasticMarkerList, text, value, s_elasticMarkerList)
End Function
''' <summary> Creates a token with kind IntegerLiteralToken from the text and corresponding 8-byte signed integer value. </summary>
''' <param name="leading">A list of trivia immediately preceding the token.</param>
''' <param name="text">The raw text of the literal.</param>
''' <param name="value">The 8-byte signed integer value to be represented by the returned token.</param>
''' <param name="trailing">A list of trivia immediately following the token.</param>
Public Shared Function Literal(leading As SyntaxTriviaList, text As String, value As Long, trailing As SyntaxTriviaList) As SyntaxToken
Return CType(InternalSyntax.SyntaxFactory.IntegerLiteralToken(text, If(text.StartsWith("&H", StringComparison.OrdinalIgnoreCase), LiteralBase.Hexadecimal, If(text.StartsWith("&O", StringComparison.OrdinalIgnoreCase), LiteralBase.Octal, If(text.StartsWith("&B", StringComparison.OrdinalIgnoreCase), LiteralBase.Binary, LiteralBase.Decimal))), If(text.EndsWith("L", StringComparison.OrdinalIgnoreCase), TypeCharacter.LongLiteral, TypeCharacter.None), CULng(value),
leading.Node, trailing.Node), SyntaxToken)
End Function
''' <summary> Creates a token with kind IntegerLiteralToken from an 8-byte unsigned integer value. </summary>
''' <param name="value">The 8-byte unsigned integer value to be represented by the returned token.</param>
Public Shared Function Literal(value As ULong) As SyntaxToken
Return Literal(VbObjectDisplay.FormatLiteral(value, ObjectDisplayOptions.IncludeTypeSuffix), value)
End Function
''' <summary> Creates a token with kind IntegerLiteralToken from the text and corresponding 8-byte unsigned integer value. </summary>
''' <param name="text">The raw text of the literal.</param>
''' <param name="value">The 8-byte unsigned integer value to be represented by the returned token.</param>
Public Shared Function Literal(text As String, value As ULong) As SyntaxToken
Return Literal(s_elasticMarkerList, text, value, s_elasticMarkerList)
End Function
''' <summary> Creates a token with kind IntegerLiteralToken from the text and corresponding 8-byte unsigned integer value. </summary>
''' <param name="leading">A list of trivia immediately preceding the token.</param>
''' <param name="text">The raw text of the literal.</param>
''' <param name="value">The 8-byte unsigned integer value to be represented by the returned token.</param>
''' <param name="trailing">A list of trivia immediately following the token.</param>
Public Shared Function Literal(leading As SyntaxTriviaList, text As String, value As ULong, trailing As SyntaxTriviaList) As SyntaxToken
Return CType(InternalSyntax.SyntaxFactory.IntegerLiteralToken(text, If(text.StartsWith("&H", StringComparison.OrdinalIgnoreCase), LiteralBase.Hexadecimal, If(text.StartsWith("&O", StringComparison.OrdinalIgnoreCase), LiteralBase.Octal, If(text.StartsWith("&B", StringComparison.OrdinalIgnoreCase), LiteralBase.Binary, LiteralBase.Decimal))), If(text.EndsWith("UL", StringComparison.OrdinalIgnoreCase), TypeCharacter.ULongLiteral, TypeCharacter.None), value,
leading.Node, trailing.Node), SyntaxToken)
End Function
''' <summary> Creates a token with kind FloatingLiteralToken from a 4-byte floating point value. </summary>
''' <param name="value">The 4-byte floating point value to be represented by the returned token.</param>
Public Shared Function Literal(value As Single) As SyntaxToken
Return Literal(VbObjectDisplay.FormatLiteral(value, ObjectDisplayOptions.IncludeTypeSuffix), value)
End Function
''' <summary> Creates a token with kind FloatingLiteralToken from the text and corresponding 4-byte floating point value. </summary>
''' <param name="text">The raw text of the literal.</param>
''' <param name="value">The 4-byte floating point value to be represented by the returned token.</param>
Public Shared Function Literal(text As String, value As Single) As SyntaxToken
Return Literal(s_elasticMarkerList, text, value, s_elasticMarkerList)
End Function
''' <summary> Creates a token with kind FloatingLiteralToken from the text and corresponding 4-byte floating point value. </summary>
''' <param name="leading">A list of trivia immediately preceding the token.</param>
''' <param name="text">The raw text of the literal.</param>
''' <param name="value">The 4-byte floating point value to be represented by the returned token.</param>
''' <param name="trailing">A list of trivia immediately following the token.</param>
Public Shared Function Literal(leading As SyntaxTriviaList, text As String, value As Single, trailing As SyntaxTriviaList) As SyntaxToken
Return CType(InternalSyntax.SyntaxFactory.FloatingLiteralToken(text, If(text.EndsWith("F", StringComparison.Ordinal), TypeCharacter.Single, TypeCharacter.None), value,
leading.Node, trailing.Node), SyntaxToken)
End Function
''' <summary> Creates a token with kind FloatingLiteralToken from an 8-byte floating point value. </summary>
''' <param name="value">The 8-byte floating point value to be represented by the returned token.</param>
Public Shared Function Literal(value As Double) As SyntaxToken
Return Literal(VbObjectDisplay.FormatLiteral(value, ObjectDisplayOptions.None), value)
End Function
''' <summary> Creates a token with kind FloatingLiteralToken from the text and corresponding 8-byte floating point value. </summary>
''' <param name="text">The raw text of the literal.</param>
''' <param name="value">The 8-byte floating point value to be represented by the returned token.</param>
Public Shared Function Literal(text As String, value As Double) As SyntaxToken
Return Literal(s_elasticMarkerList, text, value, s_elasticMarkerList)
End Function
''' <summary> Creates a token with kind FloatingLiteralToken from the text and corresponding 8-byte floating point value. </summary>
''' <param name="leading">A list of trivia immediately preceding the token.</param>
''' <param name="text">The raw text of the literal.</param>
''' <param name="value">The 8-byte floating point value to be represented by the returned token.</param>
''' <param name="trailing">A list of trivia immediately following the token.</param>
Public Shared Function Literal(leading As SyntaxTriviaList, text As String, value As Double, trailing As SyntaxTriviaList) As SyntaxToken
Return CType(InternalSyntax.SyntaxFactory.FloatingLiteralToken(text, If(text.EndsWith("R", StringComparison.OrdinalIgnoreCase), TypeCharacter.DoubleLiteral, TypeCharacter.None), value,
leading.Node, trailing.Node), SyntaxToken)
End Function
''' <summary> Creates a token with kind DecimalLiteralToken from a decimal value. </summary>
''' <param name="value">The decimal value to be represented by the returned token.</param>
Public Shared Function Literal(value As Decimal) As SyntaxToken
Return Literal(VbObjectDisplay.FormatLiteral(value, ObjectDisplayOptions.IncludeTypeSuffix), value)
End Function
''' <summary> Creates a token with kind DecimalLiteralToken from the text and corresponding decimal value. </summary>
''' <param name="text">The raw text of the literal.</param>
''' <param name="value">The decimal value to be represented by the returned token.</param>
Public Shared Function Literal(text As String, value As Decimal) As SyntaxToken
Return Literal(s_elasticMarkerList, text, value, s_elasticMarkerList)
End Function
''' <summary> Creates a token with kind DecimalLiteralToken from the text and corresponding decimal value. </summary>
''' <param name="leading">A list of trivia immediately preceding the token.</param>
''' <param name="text">The raw text of the literal.</param>
''' <param name="value">The decimal value to be represented by the returned token.</param>
''' <param name="trailing">A list of trivia immediately following the token.</param>
Public Shared Function Literal(leading As SyntaxTriviaList, text As String, value As Decimal, trailing As SyntaxTriviaList) As SyntaxToken
Return CType(InternalSyntax.SyntaxFactory.DecimalLiteralToken(text, If(text.EndsWith("M", StringComparison.OrdinalIgnoreCase), TypeCharacter.DecimalLiteral, TypeCharacter.None), value,
leading.Node, trailing.Node), SyntaxToken)
End Function
''' <summary> Creates a token with kind StringLiteralToken from a string value. </summary>
''' <param name="value">The string value to be represented by the returned token.</param>
Public Shared Function Literal(value As String) As SyntaxToken
Return Literal(VbObjectDisplay.FormatLiteral(value, ObjectDisplayOptions.UseQuotes Or ObjectDisplayOptions.EscapeNonPrintableCharacters), value)
End Function
''' <summary> Creates a token with kind StringLiteralToken from the text and corresponding string value. </summary>
''' <param name="text">The raw text of the literal, including quotes and escape sequences.</param>
''' <param name="value">The string value to be represented by the returned token.</param>
Public Shared Function Literal(text As String, value As String) As SyntaxToken
Return Literal(s_elasticMarkerList, text, value, s_elasticMarkerList)
End Function
''' <summary> Creates a token with kind StringLiteralToken from the text and corresponding string value. </summary>
''' <param name="leading">A list of trivia immediately preceding the token.</param>
''' <param name="text">The raw text of the literal, including quotes and escape sequences.</param>
''' <param name="value">The string value to be represented by the returned token.</param>
''' <param name="trailing">A list of trivia immediately following the token.</param>
Public Shared Function Literal(leading As SyntaxTriviaList, text As String, value As String, trailing As SyntaxTriviaList) As SyntaxToken
Return CType(InternalSyntax.SyntaxFactory.StringLiteralToken(text, value,
leading.Node, trailing.Node), SyntaxToken)
End Function
''' <summary> Creates a token with kind CharacterLiteralToken from a character value. </summary>
''' <param name="value">The character value to be represented by the returned token.</param>
Public Shared Function Literal(value As Char) As SyntaxToken
Return Literal(VbObjectDisplay.FormatLiteral(value, ObjectDisplayOptions.UseQuotes Or ObjectDisplayOptions.EscapeNonPrintableCharacters), value)
End Function
''' <summary> Creates a token with kind CharacterLiteralToken from the text and corresponding character value. </summary>
''' <param name="text">The raw text of the literal, including quotes and escape sequences.</param>
''' <param name="value">The character value to be represented by the returned token.</param>
Public Shared Function Literal(text As String, value As Char) As SyntaxToken
Return Literal(s_elasticMarkerList, text, value, s_elasticMarkerList)
End Function
''' <summary> Creates a token with kind CharacterLiteralToken from the text and corresponding character value. </summary>
''' <param name="leading">A list of trivia immediately preceding the token.</param>
''' <param name="text">The raw text of the literal, including quotes and escape sequences.</param>
''' <param name="value">The character value to be represented by the returned token.</param>
''' <param name="trailing">A list of trivia immediately following the token.</param>
Public Shared Function Literal(leading As SyntaxTriviaList, text As String, value As Char, trailing As SyntaxTriviaList) As SyntaxToken
Return CType(InternalSyntax.SyntaxFactory.CharacterLiteralToken(text, value,
leading.Node, trailing.Node), SyntaxToken)
End Function
Public Shared Function TypeBlock(ByVal blockKind As SyntaxKind, ByVal begin As TypeStatementSyntax, Optional ByVal [inherits] As SyntaxList(Of InheritsStatementSyntax) = Nothing, Optional ByVal [implements] As SyntaxList(Of ImplementsStatementSyntax) = Nothing, Optional ByVal members As SyntaxList(Of StatementSyntax) = Nothing, Optional ByVal [end] As EndBlockStatementSyntax = Nothing) As TypeBlockSyntax
Select Case blockKind
Case SyntaxKind.ModuleBlock
Return SyntaxFactory.ModuleBlock(DirectCast(begin, ModuleStatementSyntax), [inherits], [implements], members, [end])
Case SyntaxKind.ClassBlock
Return SyntaxFactory.ClassBlock(DirectCast(begin, ClassStatementSyntax), [inherits], [implements], members, [end])
Case SyntaxKind.StructureBlock
Return SyntaxFactory.StructureBlock(DirectCast(begin, StructureStatementSyntax), [inherits], [implements], members, [end])
Case SyntaxKind.InterfaceBlock
Return SyntaxFactory.InterfaceBlock(DirectCast(begin, InterfaceStatementSyntax), [inherits], [implements], members, [end])
Case Else
Throw ExceptionUtilities.UnexpectedValue(blockKind)
End Select
End Function
Public Shared Function TypeStatement(ByVal statementKind As SyntaxKind, Optional ByVal attributes As SyntaxList(Of AttributeListSyntax) = Nothing, Optional ByVal modifiers As SyntaxTokenList = Nothing, Optional ByVal keyword As SyntaxToken = Nothing, Optional ByVal identifier As SyntaxToken = Nothing, Optional ByVal typeParameterList As TypeParameterListSyntax = Nothing) As TypeStatementSyntax
Select Case statementKind
Case SyntaxKind.ModuleStatement
Return SyntaxFactory.ModuleStatement(attributes, modifiers, keyword, identifier, typeParameterList)
Case SyntaxKind.ClassStatement
Return SyntaxFactory.ClassStatement(attributes, modifiers, keyword, identifier, typeParameterList)
Case SyntaxKind.StructureStatement
Return SyntaxFactory.StructureStatement(attributes, modifiers, keyword, identifier, typeParameterList)
Case SyntaxKind.InterfaceStatement
Return SyntaxFactory.InterfaceStatement(attributes, modifiers, keyword, identifier, typeParameterList)
Case Else
Throw ExceptionUtilities.UnexpectedValue(statementKind)
End Select
End Function
''' <summary>
''' Creates an xml documentation comment that abstracts xml syntax creation.
''' </summary>
''' <param name="content">
''' A list of xml node syntax that will be the content within the xml documentation comment
''' (e.g. a summary element, a returns element, exception element and so on).
''' </param>
Public Shared Function DocumentationComment(ParamArray content As XmlNodeSyntax()) As DocumentationCommentTriviaSyntax
Return DocumentationCommentTrivia(List(content)).WithLeadingTrivia(DocumentationCommentExteriorTrivia("''' ")).WithTrailingTrivia(EndOfLine(""))
End Function
''' <summary>
''' Creates a summary element within an xml documentation comment.
''' </summary>
''' <param name="content">A list of xml node syntax that will be the content within the summary element.</param>
Public Shared Function XmlSummaryElement(ParamArray content As XmlNodeSyntax()) As XmlElementSyntax
Return XmlSummaryElement(List(content))
End Function
''' <summary>
''' Creates a summary element within an xml documentation comment.
''' </summary>
''' <param name="content">A list of xml node syntax that will be the content within the summary element.</param>
Public Shared Function XmlSummaryElement(content As SyntaxList(Of XmlNodeSyntax)) As XmlElementSyntax
Return XmlMultiLineElement(DocumentationCommentXmlNames.SummaryElementName, content)
End Function
''' <summary>
''' Creates a see element within an xml documentation comment.
''' </summary>
''' <param name="cref">A cref syntax node that points to the referenced item (e.g. a class, struct).</param>
Public Shared Function XmlSeeElement(cref As CrefReferenceSyntax) As XmlEmptyElementSyntax
Return XmlEmptyElement(DocumentationCommentXmlNames.SeeElementName).AddAttributes(XmlCrefAttribute(cref))
End Function
''' <summary>
''' Creates a seealso element within an xml documentation comment.
''' </summary>
''' <param name="cref">A cref syntax node that points to the referenced item (e.g. a class, struct).</param>
Public Shared Function XmlSeeAlsoElement(cref As CrefReferenceSyntax) As XmlEmptyElementSyntax
Return XmlEmptyElement(DocumentationCommentXmlNames.SeeAlsoElementName).AddAttributes(XmlCrefAttribute(cref))
End Function
''' <summary>
''' Creates a seealso element within an xml documentation comment.
''' </summary>
''' <param name="linkAddress">The uri of the referenced item.</param>
''' <param name="linkText"> A list of xml node syntax that will be used as the link text for the referenced item.</param>
Public Shared Function XmlSeeAlsoElement(linkAddress As Uri, linkText As SyntaxList(Of XmlNodeSyntax)) As XmlElementSyntax
Dim linkAddressString = linkAddress.ToString().ToLowerInvariant()
Dim element = XmlElement(DocumentationCommentXmlNames.SeeAlsoElementName, linkText)
Return element.WithStartTag(element.StartTag.AddAttributes(
XmlAttribute(
XmlName(Nothing, XmlTextLiteralToken(DocumentationCommentXmlNames.CrefAttributeName, DocumentationCommentXmlNames.CrefAttributeName)),
XmlString(
Token(SyntaxKind.DoubleQuoteToken),
SyntaxTokenList.Create(
XmlTextLiteralToken(linkAddressString, linkAddressString)),
Token(SyntaxKind.DoubleQuoteToken)))))
End Function
''' <summary>
''' Creates a threadsafety element within an xml documentation comment.
''' </summary>
Public Shared Function XmlThreadSafetyElement() As XmlEmptyElementSyntax
Return XmlThreadSafetyElement(True, False)
End Function
''' <summary>
''' Creates a threadsafety element within an xml documentation comment.
''' </summary>
''' <param name="isStatic" static="sfd">Indicates whether static member of this type are safe for multi-threaded operations.</param>
''' <param name="isInstance">Indicates whether instance members of this type are safe for multi-threaded operations.</param>
''' <threadsafety static="true" instance=""/>
Public Shared Function XmlThreadSafetyElement(isStatic As Boolean, isInstance As Boolean) As XmlEmptyElementSyntax
Dim staticValueString = isStatic.ToString().ToLowerInvariant()
Dim instanceValueString = isInstance.ToString().ToLowerInvariant()
Return XmlEmptyElement(XmlName(Nothing, XmlNameToken(DocumentationCommentXmlNames.ThreadSafetyElementName, SyntaxKind.XmlNameToken)).WithTrailingTrivia(ElasticSpace)).AddAttributes(
XmlAttribute(
XmlName(Nothing, XmlNameToken(DocumentationCommentXmlNames.StaticAttributeName, SyntaxKind.XmlNameToken)),
XmlString(
Token(SyntaxKind.DoubleQuoteToken),
SyntaxTokenList.Create(XmlTextLiteralToken(staticValueString, staticValueString)),
Token(SyntaxKind.DoubleQuoteToken))).WithTrailingTrivia(ElasticSpace),
XmlAttribute(
XmlName(Nothing, XmlNameToken(DocumentationCommentXmlNames.InstanceAttributeName, SyntaxKind.XmlNameToken)),
XmlString(
Token(SyntaxKind.DoubleQuoteToken),
SyntaxTokenList.Create(XmlTextLiteralToken(instanceValueString, instanceValueString)),
Token(SyntaxKind.DoubleQuoteToken))))
End Function
''' <summary>
''' Creates a syntax node for a name attribute in a xml element within a xml documentation comment.
''' </summary>
''' <param name="parameterName">The value of the name attribute.</param>
Public Shared Function XmlNameAttribute(parameterName As String) As XmlNameAttributeSyntax
Return XmlNameAttribute(XmlName(Nothing, XmlNameToken(DocumentationCommentXmlNames.NameAttributeName, SyntaxKind.XmlNameToken)), Token(SyntaxKind.DoubleQuoteToken), IdentifierName(parameterName), Token(SyntaxKind.DoubleQuoteToken)).WithLeadingTrivia(Whitespace(" "))
End Function
''' <summary>
''' Creates a syntax node for a preliminary element within a xml documentation comment.
''' </summary>
Public Shared Function XmlPreliminaryElement() As XmlEmptyElementSyntax
Return XmlEmptyElement(DocumentationCommentXmlNames.PreliminaryElementName)
End Function
''' <summary>
''' Creates a syntax node for a cref attribute within a xml documentation comment.
''' </summary>
''' <param name="cref">The <see cref="CrefReferenceSyntax"/> used for the xml cref attribute syntax.</param>
Public Shared Function XmlCrefAttribute(cref As CrefReferenceSyntax) As XmlCrefAttributeSyntax
Return XmlCrefAttribute(cref, SyntaxKind.DoubleQuoteToken)
End Function
''' <summary>
''' Creates a syntax node for a cref attribute within a xml documentation comment.
''' </summary>
''' <param name="cref">The <see cref="CrefReferenceSyntax"/> used for the xml cref attribute syntax.</param>
''' <param name="quoteKind">The kind of the quote for the referenced item in the cref attribute.</param>
Public Shared Function XmlCrefAttribute(cref As CrefReferenceSyntax, quoteKind As SyntaxKind) As XmlCrefAttributeSyntax
cref = cref.ReplaceTokens(cref.DescendantTokens(), AddressOf XmlReplaceBracketTokens)
Return XmlCrefAttribute(XmlName(Nothing, XmlNameToken(DocumentationCommentXmlNames.CrefAttributeName, SyntaxKind.XmlNameToken)), Token(quoteKind), cref, Token(quoteKind)).WithLeadingTrivia(Whitespace(" "))
End Function
''' <summary>
''' Creates a remarks element within an xml documentation comment.
''' </summary>
''' <param name="content">A list of xml node syntax that will be the content within the remarks element.</param>
Public Shared Function XmlRemarksElement(ParamArray content As XmlNodeSyntax()) As XmlElementSyntax
Return XmlRemarksElement(List(content))
End Function
''' <summary>
''' Creates a remarks element within an xml documentation comment.
''' </summary>
''' <param name="content">A list of xml node syntax that will be the content within the remarks element.</param>
Public Shared Function XmlRemarksElement(content As SyntaxList(Of XmlNodeSyntax)) As XmlElementSyntax
Return XmlMultiLineElement(DocumentationCommentXmlNames.RemarksElementName, content)
End Function
''' <summary>
''' Creates a returns element within an xml documentation comment.
''' </summary>
''' <param name="content">A list of xml node syntax that will be the content within the returns element.</param>
Public Shared Function XmlReturnsElement(ParamArray content As XmlNodeSyntax()) As XmlElementSyntax
Return XmlReturnsElement(List(content))
End Function
''' <summary>
''' Creates a returns element within an xml documentation comment.
''' </summary>
''' <param name="content">A list of xml node syntax that will be the content within the returns element.</param>
Public Shared Function XmlReturnsElement(content As SyntaxList(Of XmlNodeSyntax)) As XmlElementSyntax
Return XmlMultiLineElement(DocumentationCommentXmlNames.ReturnsElementName, content)
End Function
''' <summary>
''' Creates the syntax representation of an xml value element (e.g. for xml documentation comments).
''' </summary>
''' <param name="content">A list of xml syntax nodes that represents the content of the value element.</param>
Public Shared Function XmlValueElement(ParamArray content As XmlNodeSyntax()) As XmlElementSyntax
Return XmlValueElement(List(content))
End Function
''' <summary>
''' Creates the syntax representation of an xml value element (e.g. for xml documentation comments).
''' </summary>
''' <param name="content">A list of xml syntax nodes that represents the content of the value element.</param>
Public Shared Function XmlValueElement(content As SyntaxList(Of XmlNodeSyntax)) As XmlElementSyntax
Return XmlMultiLineElement(DocumentationCommentXmlNames.ValueElementName, content)
End Function
''' <summary>
''' Creates the syntax representation of an exception element within xml documentation comments.
''' </summary>
''' <param name="cref">Syntax representation of the reference to the exception type.</param>
''' <param name="content">A list of syntax nodes that represents the content of the exception element.</param>
Public Shared Function XmlExceptionElement(cref As CrefReferenceSyntax, ParamArray content As XmlNodeSyntax()) As XmlElementSyntax
Return XmlExceptionElement(cref, List(content))
End Function
''' <summary>
''' Creates the syntax representation of an exception element within xml documentation comments.
''' </summary>
''' <param name="cref">Syntax representation of the reference to the exception type.</param>
''' <param name="content">A list of syntax nodes that represents the content of the exception element.</param>
Public Shared Function XmlExceptionElement(cref As CrefReferenceSyntax, content As SyntaxList(Of XmlNodeSyntax)) As XmlElementSyntax
Dim element As XmlElementSyntax = XmlElement(DocumentationCommentXmlNames.ExceptionElementName, content)
Return element.WithStartTag(element.StartTag.AddAttributes(XmlCrefAttribute(cref)))
End Function
''' <summary>
''' Creates the syntax representation of a permission element within xml documentation comments.
''' </summary>
''' <param name="cref">Syntax representation of the reference to the permission type.</param>
''' <param name="content">A list of syntax nodes that represents the content of the permission element.</param>
Public Shared Function XmlPermissionElement(cref As CrefReferenceSyntax, ParamArray content As XmlNodeSyntax()) As XmlElementSyntax
Return XmlPermissionElement(cref, List(content))
End Function
''' <summary>
''' Creates the syntax representation of a permission element within xml documentation comments.
''' </summary>
''' <param name="cref">Syntax representation of the reference to the permission type.</param>
''' <param name="content">A list of syntax nodes that represents the content of the permission element.</param>
Public Shared Function XmlPermissionElement(cref As CrefReferenceSyntax, content As SyntaxList(Of XmlNodeSyntax)) As XmlElementSyntax
Dim element As XmlElementSyntax = XmlElement(DocumentationCommentXmlNames.PermissionElementName, content)
Return element.WithStartTag(element.StartTag.AddAttributes(XmlCrefAttribute(cref)))
End Function
''' <summary>
''' Creates the syntax representation of an example element within xml documentation comments.
''' </summary>
''' <param name="content">A list of syntax nodes that represents the content of the example element.</param>
Public Shared Function XmlExampleElement(ParamArray content As XmlNodeSyntax()) As XmlElementSyntax
Return XmlExampleElement(List(content))
End Function
''' <summary>
''' Creates the syntax representation of an example element within xml documentation comments.
''' </summary>
''' <param name="content">A list of syntax nodes that represents the content of the example element.</param>
Public Shared Function XmlExampleElement(content As SyntaxList(Of XmlNodeSyntax)) As XmlElementSyntax
Dim element As XmlElementSyntax = XmlElement(DocumentationCommentXmlNames.ExampleElementName, content)
Return element.WithStartTag(element.StartTag)
End Function
''' <summary>
''' Creates the syntax representation of a para element within xml documentation comments.
''' </summary>
''' <param name="content">A list of syntax nodes that represents the content of the para element.</param>
Public Shared Function XmlParaElement(ParamArray content As XmlNodeSyntax()) As XmlElementSyntax
Return XmlParaElement(List(content))
End Function
''' <summary>
''' Creates the syntax representation of a para element within xml documentation comments.
''' </summary>
''' <param name="content">A list of syntax nodes that represents the content of the para element.</param>
Public Shared Function XmlParaElement(content As SyntaxList(Of XmlNodeSyntax)) As XmlElementSyntax
Return XmlElement(DocumentationCommentXmlNames.ParaElementName, content)
End Function
''' <summary>
''' Creates the syntax representation of a param element within xml documentation comments (e.g. for
''' documentation of method parameters).
''' </summary>
''' <param name="parameterName">The name of the parameter.</param>
''' <param name="content">A list of syntax nodes that represents the content of the param element (e.g.
''' the description and meaning of the parameter).</param>
Public Shared Function XmlParamElement(parameterName As String, ParamArray content As XmlNodeSyntax()) As XmlElementSyntax
Return XmlParamElement(parameterName, List(content))
End Function
''' <summary>
''' Creates the syntax representation of a param element within xml documentation comments (e.g. for
''' documentation of method parameters).
''' </summary>
''' <param name="parameterName">The name of the parameter.</param>
''' <param name="content">A list of syntax nodes that represents the content of the param element (e.g.
''' the description and meaning of the parameter).</param>
Public Shared Function XmlParamElement(parameterName As String, content As SyntaxList(Of XmlNodeSyntax)) As XmlElementSyntax
Dim element As XmlElementSyntax = XmlElement(DocumentationCommentXmlNames.ParameterElementName, content)
Return element.WithStartTag(element.StartTag.AddAttributes(XmlNameAttribute(parameterName)))
End Function
''' <summary>
''' Creates the syntax representation of a paramref element within xml documentation comments (e.g. for
''' referencing particular parameters of a method).
''' </summary>
''' <param name="parameterName">The name of the referenced parameter.</param>
Public Shared Function XmlParamRefElement(parameterName As String) As XmlEmptyElementSyntax
Return XmlEmptyElement(DocumentationCommentXmlNames.ParameterReferenceElementName).AddAttributes(XmlNameAttribute(parameterName))
End Function
''' <summary>
''' Creates the syntax representation of a see element within xml documentation comments,
''' that points to the 'null' language keyword.
''' </summary>
Public Shared Function XmlNullKeywordElement() As XmlEmptyElementSyntax
Return XmlKeywordElement("null")
End Function
''' <summary>
''' Creates the syntax representation of a see element within xml documentation comments,
''' that points to a language keyword.
''' </summary>
''' <param name="keyword">The language keyword to which the see element points to.</param>
Private Shared Function XmlKeywordElement(keyword As String) As XmlEmptyElementSyntax
Dim attribute As XmlAttributeSyntax =
XmlAttribute(
XmlName(
Nothing,
XmlTextLiteralToken(DocumentationCommentXmlNames.LangwordAttributeName, DocumentationCommentXmlNames.LangwordAttributeName)),
XmlString(
Token(SyntaxKind.DoubleQuoteToken),
SyntaxTokenList.Create(XmlTextLiteralToken(keyword, keyword)),
Token(SyntaxKind.DoubleQuoteToken)))
Return XmlEmptyElement(DocumentationCommentXmlNames.SeeElementName).AddAttributes(attribute)
End Function
''' <summary>
''' Creates the syntax representation of a placeholder element within xml documentation comments.
''' </summary>
''' <param name="content">A list of syntax nodes that represents the content of the placeholder element.</param>
Public Shared Function XmlPlaceholderElement(ParamArray content As XmlNodeSyntax()) As XmlElementSyntax
Return XmlPlaceholderElement(List(content))
End Function
''' <summary>
''' Creates the syntax representation of a placeholder element within xml documentation comments.
''' </summary>
''' <param name="content">A list of syntax nodes that represents the content of the placeholder element.</param>
Public Shared Function XmlPlaceholderElement(content As SyntaxList(Of XmlNodeSyntax)) As XmlElementSyntax
Return XmlElement(DocumentationCommentXmlNames.PlaceholderElementName, content)
End Function
''' <summary>
''' Creates the syntax representation of a named empty xml element within xml documentation comments.
''' </summary>
''' <param name="localName">The name of the empty xml element.</param>
Public Shared Function XmlEmptyElement(localName As String) As XmlEmptyElementSyntax
Return XmlEmptyElement(XmlName(Nothing, XmlNameToken(localName, SyntaxKind.XmlNameToken)))
End Function
''' <summary>
''' Creates the syntax representation of a named xml element within xml documentation comments.
''' </summary>
''' <param name="localName">The name of the empty xml element.</param>
''' <param name="content">A list of syntax nodes that represents the content of the xml element.</param>
Public Shared Function XmlElement(localName As String, content As SyntaxList(Of XmlNodeSyntax)) As XmlElementSyntax
Return XmlElement(XmlName(Nothing, XmlNameToken(localName, SyntaxKind.XmlNameToken)), content)
End Function
''' <summary>
''' Creates the syntax representation of a named xml element within xml documentation comments.
''' </summary>
''' <param name="name">The name of the empty xml element.</param>
''' <param name="content">A list of syntax nodes that represents the content of the xml element.</param>
Public Shared Function XmlElement(name As XmlNameSyntax, content As SyntaxList(Of XmlNodeSyntax)) As XmlElementSyntax
Return XmlElement(XmlElementStartTag(name), content, XmlElementEndTag(name))
End Function
''' <summary>
''' Creates the syntax representation of an xml element that spans multiple text lines.
''' </summary>
''' <param name="localName">The name of the xml element.</param>
''' <param name="content">A list of syntax nodes that represents the content of the xml multi line element.</param>
Public Shared Function XmlMultiLineElement(localName As String, content As SyntaxList(Of XmlNodeSyntax)) As XmlElementSyntax
Return XmlMultiLineElement(XmlName(Nothing, XmlNameToken(localName, SyntaxKind.XmlNameToken)), content)
End Function
''' <summary>
''' Creates the syntax representation of an xml element that spans multiple text lines.
''' </summary>
''' <param name="name">The name of the xml element.</param>
''' <param name="content">A list of syntax nodes that represents the content of the xml multi line element.</param>
Public Shared Function XmlMultiLineElement(name As XmlNameSyntax, content As SyntaxList(Of XmlNodeSyntax)) As XmlElementSyntax
Return XmlElement(XmlElementStartTag(name), content, XmlElementEndTag(name))
End Function
''' <summary>
''' Creates the syntax representation of an xml text that contains a newline token with a documentation comment
''' exterior trivia at the end (continued documentation comment).
''' </summary>
''' <param name="text">The raw text within the new line.</param>
Public Shared Function XmlNewLine(text As String) As XmlTextSyntax
Return XmlText(XmlTextNewLine(text))
End Function
''' <summary>
''' Creates the syntax representation of an xml newline token with a documentation comment exterior trivia at
''' the end (continued documentation comment).
''' </summary>
''' <param name="text">The raw text within the new line.</param>
Public Shared Function XmlTextNewLine(text As String) As SyntaxToken
Return XmlTextNewLine(text, True)
End Function
''' <summary>
''' Creates a token with kind XmlTextLiteralNewLineToken.
''' </summary>
''' <param name="text">The raw text of the literal.</param>
''' <param name="value">The xml text new line value.</param>
''' <param name="leading">A list of trivia immediately preceding the token.</param>
''' <param name="trailing">A list of trivia immediately following the token.</param>
Public Shared Function XmlTextNewLine(text As String, value As String, leading As SyntaxTriviaList, trailing As SyntaxTriviaList) As SyntaxToken
Return New SyntaxToken(
InternalSyntax.SyntaxFactory.DocumentationCommentLineBreakToken(
text,
value,
leading.Node,
trailing.Node))
End Function
''' <summary>
''' Creates the syntax representation of an xml newline token for xml documentation comments.
''' </summary>
''' <param name="text">The raw text within the new line.</param>
''' <param name="continueXmlDocumentationComment">
''' If set to true, a documentation comment exterior token will be added to the trailing trivia
''' of the new token.</param>
Public Shared Function XmlTextNewLine(text As String, continueXmlDocumentationComment As Boolean) As SyntaxToken
Dim token = New SyntaxToken(
InternalSyntax.SyntaxFactory.DocumentationCommentLineBreakToken(
text,
text,
ElasticMarker.UnderlyingNode,
ElasticMarker.UnderlyingNode))
If continueXmlDocumentationComment Then
token = token.WithTrailingTrivia(token.TrailingTrivia.Add(DocumentationCommentExteriorTrivia("''' ")))
End If
Return token
End Function
''' <summary>
''' Generates the syntax representation of a xml text node (e.g. for xml documentation comments).
''' </summary>
''' <param name="value">The string literal used as the text of the xml text node.</param>
Public Shared Function XmlText(value As String) As XmlTextSyntax
Return XmlText(XmlTextLiteral(value))
End Function
''' <summary>
''' Generates the syntax representation of a xml text node (e.g. for xml documentation comments).
''' </summary>
''' <param name="textTokens">A list of text tokens used as the text of the xml text node.</param>
Public Shared Function XmlText(ParamArray textTokens As SyntaxToken()) As XmlTextSyntax
Return XmlText(TokenList(textTokens))
End Function
''' <summary>
''' Generates the syntax representation of an xml text literal.
''' </summary>
''' <param name="value">The text used within the xml text literal.</param>
Public Shared Function XmlTextLiteral(value As String) As SyntaxToken
' TODO: [RobinSedlaczek] It is no compiler hot path here I think. But the contribution guide
' states to avoid LINQ (https://github.com/dotnet/roslyn/wiki/Contributing-Code). With
' XText we have a reference to System.Xml.Linq. Isn't this rule valid here?
Dim encoded As String = New XText(value).ToString()
Return XmlTextLiteral(encoded, value)
End Function
''' <summary>
''' Generates the syntax representation of an xml text literal.
''' </summary>
''' <param name="text">The raw text of the literal.</param>
''' <param name="value">The text used within the xml text literal.</param>
Public Shared Function XmlTextLiteral(text As String, value As String) As SyntaxToken
Return New SyntaxToken(Syntax.InternalSyntax.SyntaxFactory.XmlTextLiteralToken(text, value, ElasticMarker.UnderlyingNode, ElasticMarker.UnderlyingNode))
End Function
''' <summary>
''' Helper method that replaces less-than and greater-than characters with brackets.
''' </summary>
''' <param name="originalToken">The original token that is to be replaced.</param>
''' <param name="rewrittenToken">The new rewritten token.</param>
''' <returns>Returns the new rewritten token with replaced characters.</returns>
Private Shared Function XmlReplaceBracketTokens(originalToken As SyntaxToken, rewrittenToken As SyntaxToken) As SyntaxToken
If rewrittenToken.IsKind(SyntaxKind.LessThanToken) AndAlso String.Equals("<", rewrittenToken.Text, StringComparison.Ordinal) Then
Return Token(rewrittenToken.LeadingTrivia, SyntaxKind.LessThanToken, rewrittenToken.TrailingTrivia, rewrittenToken.ValueText)
End If
If rewrittenToken.IsKind(SyntaxKind.GreaterThanToken) AndAlso String.Equals(">", rewrittenToken.Text, StringComparison.Ordinal) Then
Return Token(rewrittenToken.LeadingTrivia, SyntaxKind.GreaterThanToken, rewrittenToken.TrailingTrivia, rewrittenToken.ValueText)
End If
Return rewrittenToken
End Function
''' <summary>
''' Determines if two trees are the same, disregarding trivia differences.
''' </summary>
''' <param name="oldTree">The original tree.</param>
''' <param name="newTree">The new tree.</param>
''' <param name="topLevel">
''' True to ignore any differences of nodes inside bodies of methods, operators, constructors and accessors, and field and auto-property initializers,
''' otherwise all nodes and tokens must be equivalent.
''' </param>
Public Shared Function AreEquivalent(oldTree As SyntaxTree, newTree As SyntaxTree, topLevel As Boolean) As Boolean
Return SyntaxEquivalence.AreEquivalent(oldTree, newTree, ignoreChildNode:=Nothing, topLevel:=topLevel)
End Function
''' <summary>
''' Determines if two syntax nodes are the same, disregarding trivia differences.
''' </summary>
''' <param name="oldNode">The old node.</param>
''' <param name="newNode">The new node.</param>
''' <param name="topLevel">
''' True to ignore any differences of nodes inside bodies of methods, operators, constructors and accessors, and field and auto-property initializers,
''' otherwise all nodes and tokens must be equivalent.
''' </param>
Public Shared Function AreEquivalent(oldNode As SyntaxNode, newNode As SyntaxNode, topLevel As Boolean) As Boolean
Return SyntaxEquivalence.AreEquivalent(oldNode, newNode, ignoreChildNode:=Nothing, topLevel:=topLevel)
End Function
''' <summary>
''' Determines if two syntax nodes are the same, disregarding trivia differences.
''' </summary>
''' <param name="oldNode">The old node.</param>
''' <param name="newNode">The new node.</param>
''' <param name="ignoreChildNode">
''' If specified called for every child syntax node (not token) that is visited during the comparison.
''' It it returns true the child is recursively visited, otherwise the child and its subtree is disregarded.
''' </param>
Public Shared Function AreEquivalent(oldNode As SyntaxNode, newNode As SyntaxNode, Optional ignoreChildNode As Func(Of SyntaxKind, Boolean) = Nothing) As Boolean
Return SyntaxEquivalence.AreEquivalent(oldNode, newNode, ignoreChildNode:=ignoreChildNode, topLevel:=False)
End Function
''' <summary>
''' Determines if two syntax tokens are the same, disregarding trivia differences.
''' </summary>
''' <param name="oldToken">The old token.</param>
''' <param name="newToken">The new token.</param>
Public Shared Function AreEquivalent(oldToken As SyntaxToken, newToken As SyntaxToken) As Boolean
Return SyntaxEquivalence.AreEquivalent(oldToken, newToken)
End Function
''' <summary>
''' Determines if two lists of tokens are the same, disregarding trivia differences.
''' </summary>
''' <param name="oldList">The old token list.</param>
''' <param name="newList">The new token list.</param>
Public Shared Function AreEquivalent(oldList As SyntaxTokenList, newList As SyntaxTokenList) As Boolean
Return SyntaxEquivalence.AreEquivalent(oldList, newList)
End Function
''' <summary>
''' Determines if two lists of syntax nodes are the same, disregarding trivia differences.
''' </summary>
''' <param name="oldList">The old list.</param>
''' <param name="newList">The new list.</param>
''' <param name="ignoreChildNode">
''' If specified called for every child syntax node (not token) that is visited during the comparison.
''' It returns true the child is recursively visited, otherwise the child and its subtree is disregarded.
''' </param>