/
Extensions.cs
181 lines (167 loc) · 10.1 KB
/
Extensions.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
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
// 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.Collections.Immutable;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Microsoft.CodeAnalysis
{
public static class ModelExtensions
{
/// <summary>
/// Gets symbol information about a syntax node.
/// </summary>
/// <param name="semanticModel"></param>
/// <param name="node">The syntax node to get semantic information for.</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the
/// process of obtaining the semantic info.</param>
public static SymbolInfo GetSymbolInfo(this SemanticModel semanticModel, SyntaxNode node, CancellationToken cancellationToken = default(CancellationToken))
{
return semanticModel.GetSymbolInfo(node, cancellationToken);
}
/// <summary>
/// Binds the node in the context of the specified location and get semantic information
/// such as type, symbols and diagnostics. This method is used to get semantic information
/// about an expression that did not actually appear in the source code.
/// </summary>
/// <param name="semanticModel"></param>
/// <param name="position">A character position used to identify a declaration scope and
/// accessibility. This character position must be within the FullSpan of the Root syntax
/// node in this SemanticModel.
/// </param>
/// <param name="expression">A syntax node that represents a parsed expression. This syntax
/// node need not and typically does not appear in the source code referred to SemanticModel
/// instance.</param>
/// <param name="bindingOption">Indicates whether to binding the expression as a full expressions,
/// or as a type or namespace. If SpeculativeBindingOption.BindAsTypeOrNamespace is supplied, then
/// expression should derive from TypeSyntax.</param>
/// <returns>The semantic information for the topmost node of the expression.</returns>
/// <remarks>The passed in expression is interpreted as a stand-alone expression, as if it
/// appeared by itself somewhere within the scope that encloses "position".</remarks>
public static SymbolInfo GetSpeculativeSymbolInfo(this SemanticModel semanticModel, int position, SyntaxNode expression, SpeculativeBindingOption bindingOption)
{
return semanticModel.GetSpeculativeSymbolInfo(position, expression, bindingOption);
}
/// <summary>
/// Gets type information about a syntax node.
/// </summary>
/// <param name="semanticModel"></param>
/// <param name="node">The syntax node to get semantic information for.</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the
/// process of obtaining the semantic info.</param>
public static TypeInfo GetTypeInfo(this SemanticModel semanticModel, SyntaxNode node, CancellationToken cancellationToken = default(CancellationToken))
{
return semanticModel.GetTypeInfo(node, cancellationToken);
}
/// <summary>
/// If "nameSyntax" resolves to an alias name, return the IAliasSymbol corresponding
/// to A. Otherwise return null.
/// </summary>
/// <param name="semanticModel"></param>
/// <param name="nameSyntax">Name to get alias info for.</param>
/// <param name="cancellationToken">A cancellation token that can be used to cancel the
/// process of obtaining the alias information.</param>
public static IAliasSymbol GetAliasInfo(this SemanticModel semanticModel, SyntaxNode nameSyntax, CancellationToken cancellationToken = default(CancellationToken))
{
return semanticModel.GetAliasInfo(nameSyntax, cancellationToken);
}
/// <summary>
/// Binds the name in the context of the specified location and sees if it resolves to an
/// alias name. If it does, return the AliasSymbol corresponding to it. Otherwise, return null.
/// </summary>
/// <param name="semanticModel"></param>
/// <param name="position">A character position used to identify a declaration scope and
/// accessibility. This character position must be within the FullSpan of the Root syntax
/// node in this SemanticModel.
/// </param>
/// <param name="nameSyntax">A syntax node that represents a name. This syntax
/// node need not and typically does not appear in the source code referred to by the
/// SemanticModel instance.</param>
/// <param name="bindingOption">Indicates whether to binding the name as a full expression,
/// or as a type or namespace. If SpeculativeBindingOption.BindAsTypeOrNamespace is supplied, then
/// expression should derive from TypeSyntax.</param>
/// <remarks>The passed in name is interpreted as a stand-alone name, as if it
/// appeared by itself somewhere within the scope that encloses "position".</remarks>
public static IAliasSymbol GetSpeculativeAliasInfo(this SemanticModel semanticModel, int position, SyntaxNode nameSyntax, SpeculativeBindingOption bindingOption)
{
return semanticModel.GetSpeculativeAliasInfo(position, nameSyntax, bindingOption);
}
/// <summary>
/// Binds the node in the context of the specified location and get semantic information
/// such as type, symbols and diagnostics. This method is used to get semantic information
/// about an expression that did not actually appear in the source code.
/// </summary>
/// <param name="semanticModel"></param>
/// <param name="position">A character position used to identify a declaration scope and
/// accessibility. This character position must be within the FullSpan of the Root syntax
/// node in this SemanticModel.
/// </param>
/// <param name="expression">A syntax node that represents a parsed expression. This syntax
/// node need not and typically does not appear in the source code referred to SemanticModel
/// instance.</param>
/// <param name="bindingOption">Indicates whether to binding the expression as a full expressions,
/// or as a type or namespace. If SpeculativeBindingOption.BindAsTypeOrNamespace is supplied, then
/// expression should derive from TypeSyntax.</param>
/// <returns>The semantic information for the topmost node of the expression.</returns>
/// <remarks>The passed in expression is interpreted as a stand-alone expression, as if it
/// appeared by itself somewhere within the scope that encloses "position".</remarks>
public static TypeInfo GetSpeculativeTypeInfo(this SemanticModel semanticModel, int position, SyntaxNode expression, SpeculativeBindingOption bindingOption)
{
return semanticModel.GetSpeculativeTypeInfo(position, expression, bindingOption);
}
/// <summary>
/// Gets the symbol associated with a declaration syntax node.
/// </summary>
/// <param name="semanticModel"></param>
/// <param name="declaration">A syntax node that is a declaration. This can be any type
/// derived from MemberDeclarationSyntax, TypeDeclarationSyntax, EnumDeclarationSyntax,
/// NamespaceDeclarationSyntax, ParameterSyntax, TypeParameterSyntax, or the alias part of a
/// UsingDirectiveSyntax</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The symbol declared by the node or null if the node is not a declaration.</returns>
public static ISymbol GetDeclaredSymbol(this SemanticModel semanticModel, SyntaxNode declaration, CancellationToken cancellationToken = default(CancellationToken))
{
return semanticModel.GetDeclaredSymbolForNode(declaration, cancellationToken);
}
/// <summary>
/// Gets a list of method or indexed property symbols for a syntax node.
/// </summary>
/// <param name="semanticModel"></param>
/// <param name="node">The syntax node to get semantic information for.</param>
/// <param name="cancellationToken">The cancellation token.</param>
public static ImmutableArray<ISymbol> GetMemberGroup(this SemanticModel semanticModel, SyntaxNode node, CancellationToken cancellationToken = default(CancellationToken))
{
return semanticModel.GetMemberGroup(node, cancellationToken);
}
/// <summary>
/// Analyze control-flow within a part of a method body.
/// </summary>
public static ControlFlowAnalysis AnalyzeControlFlow(this SemanticModel semanticModel, SyntaxNode firstStatement, SyntaxNode lastStatement)
{
return semanticModel.AnalyzeControlFlow(firstStatement, lastStatement);
}
/// <summary>
/// Analyze control-flow within a part of a method body.
/// </summary>
public static ControlFlowAnalysis AnalyzeControlFlow(this SemanticModel semanticModel, SyntaxNode statement)
{
return semanticModel.AnalyzeControlFlow(statement);
}
/// <summary>
/// Analyze data-flow within a part of a method body.
/// </summary>
public static DataFlowAnalysis AnalyzeDataFlow(this SemanticModel semanticModel, SyntaxNode firstStatement, SyntaxNode lastStatement)
{
return semanticModel.AnalyzeDataFlow(firstStatement, lastStatement);
}
/// <summary>
/// Analyze data-flow within a part of a method body.
/// </summary>
public static DataFlowAnalysis AnalyzeDataFlow(this SemanticModel semanticModel, SyntaxNode statementOrExpression)
{
return semanticModel.AnalyzeDataFlow(statementOrExpression);
}
}
}