-
Notifications
You must be signed in to change notification settings - Fork 4k
/
AnnotationExtensions.cs
75 lines (69 loc) · 3.13 KB
/
AnnotationExtensions.cs
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
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis
{
public static class AnnotationExtensions
{
/// <summary>
/// Creates a new node identical to this node with the specified annotations attached.
/// </summary>
/// <param name="node">Original node.</param>
/// <param name="annotations">Annotations to be added to the new node.</param>
public static TNode WithAdditionalAnnotations<TNode>(this TNode node, params SyntaxAnnotation[] annotations)
where TNode : SyntaxNode
{
return (TNode)node.WithAdditionalAnnotationsInternal(annotations);
}
/// <summary>
/// Creates a new node identical to this node with the specified annotations attached.
/// </summary>
/// <param name="node">Original node.</param>
/// <param name="annotations">Annotations to be added to the new node.</param>
public static TNode WithAdditionalAnnotations<TNode>(this TNode node, IEnumerable<SyntaxAnnotation> annotations)
where TNode : SyntaxNode
{
return (TNode)node.WithAdditionalAnnotationsInternal(annotations);
}
/// <summary>
/// Creates a new node identical to this node with the specified annotations removed.
/// </summary>
/// <param name="node">Original node.</param>
/// <param name="annotations">Annotations to be removed from the new node.</param>
public static TNode WithoutAnnotations<TNode>(this TNode node, params SyntaxAnnotation[] annotations)
where TNode : SyntaxNode
{
return (TNode)node.GetNodeWithoutAnnotations(annotations);
}
/// <summary>
/// Creates a new node identical to this node with the specified annotations removed.
/// </summary>
/// <param name="node">Original node.</param>
/// <param name="annotations">Annotations to be removed from the new node.</param>
public static TNode WithoutAnnotations<TNode>(this TNode node, IEnumerable<SyntaxAnnotation> annotations)
where TNode : SyntaxNode
{
return (TNode)node.GetNodeWithoutAnnotations(annotations);
}
/// <summary>
/// Creates a new node identical to this node with the annotations of the specified kind removed.
/// </summary>
/// <param name="node">Original node.</param>
/// <param name="annotationKind">The kind of annotation to remove.</param>
public static TNode WithoutAnnotations<TNode>(this TNode node, string annotationKind)
where TNode : SyntaxNode
{
if (node.HasAnnotations(annotationKind))
{
return node.WithoutAnnotations<TNode>(node.GetAnnotations(annotationKind).ToArray());
}
else
{
return node;
}
}
}
}