158 references to DirectiveTriviaSyntax
Microsoft.AspNetCore.App.Analyzers (1)
Infrastructure\VirtualChars\CSharpVirtualCharService.cs (1)
118
if (node is
DirectiveTriviaSyntax
)
Microsoft.CodeAnalysis.CSharp (53)
Compilation\CSharpCompilation.cs (1)
3786
foreach (
var
directive in checksumDirectives)
CSharpExtensions.cs (6)
372
internal static IList<
DirectiveTriviaSyntax
> GetDirectives(this SyntaxNode node, Func<
DirectiveTriviaSyntax
, bool>? filter = null)
380
public static
DirectiveTriviaSyntax
? GetFirstDirective(this SyntaxNode node, Func<
DirectiveTriviaSyntax
, bool>? predicate = null)
388
public static
DirectiveTriviaSyntax
? GetLastDirective(this SyntaxNode node, Func<
DirectiveTriviaSyntax
, bool>? predicate = null)
Syntax\CSharpLineDirectiveMap.cs (3)
14
internal class CSharpLineDirectiveMap : LineDirectiveMap<
DirectiveTriviaSyntax
>
22
protected override bool ShouldAddDirective(
DirectiveTriviaSyntax
directive)
28
protected override LineMappingEntry GetEntry(
DirectiveTriviaSyntax
directiveNode, SourceText sourceText, LineMappingEntry previous)
Syntax\CSharpPragmaWarningStateMap.cs (4)
47
var directives = ArrayBuilder<
DirectiveTriviaSyntax
>.GetInstance();
58
private static void GetAllPragmaWarningDirectives(SyntaxTree syntaxTree, ArrayBuilder<
DirectiveTriviaSyntax
> directiveList)
60
foreach (
var
d in syntaxTree.GetRoot().GetDirectives())
80
private static WarningStateMapEntry[] CreatePragmaWarningStateEntries(ArrayBuilder<
DirectiveTriviaSyntax
> directiveList)
Syntax\CSharpSyntaxNode.cs (13)
222
internal IList<
DirectiveTriviaSyntax
> GetDirectives(Func<
DirectiveTriviaSyntax
, bool>? filter = null)
224
return ((SyntaxNodeOrToken)this).GetDirectives<
DirectiveTriviaSyntax
>(filter);
230
public
DirectiveTriviaSyntax
? GetFirstDirective(Func<
DirectiveTriviaSyntax
, bool>? predicate = null)
238
var
d = node.GetFirstDirective(predicate);
253
var
d = (
DirectiveTriviaSyntax
)tr.GetStructure()!;
270
public
DirectiveTriviaSyntax
? GetLastDirective(Func<
DirectiveTriviaSyntax
, bool>? predicate = null)
278
var
d = node.GetLastDirective(predicate);
293
var
d = (
DirectiveTriviaSyntax
)tr.GetStructure()!;
Syntax\CSharpSyntaxTree.cs (1)
236
foreach (
DirectiveTriviaSyntax
directive in this.GetRoot().GetDirectives(d =>
Syntax\DirectiveTriviaSyntax.cs (21)
67
public
DirectiveTriviaSyntax
? GetNextDirective(Func<
DirectiveTriviaSyntax
, bool>? predicate = null)
77
var
d = (
DirectiveTriviaSyntax
)tr.GetStructure()!;
98
public
DirectiveTriviaSyntax
? GetPreviousDirective(Func<
DirectiveTriviaSyntax
, bool>? predicate = null)
108
var
d = (
DirectiveTriviaSyntax
)tr.GetStructure()!;
129
public List<
DirectiveTriviaSyntax
> GetRelatedDirectives()
131
var list = new List<
DirectiveTriviaSyntax
>();
136
private void GetRelatedDirectives(List<
DirectiveTriviaSyntax
> list)
139
var
p = this.GetPreviousRelatedDirective();
148
var
n = this.GetNextRelatedDirective();
156
private
DirectiveTriviaSyntax
? GetNextRelatedDirective()
158
DirectiveTriviaSyntax
? d = this;
222
private
DirectiveTriviaSyntax
? GetNextPossiblyRelatedDirective()
224
DirectiveTriviaSyntax
? d = this;
256
private
DirectiveTriviaSyntax
? GetPreviousRelatedDirective()
258
DirectiveTriviaSyntax
? d = this;
323
private
DirectiveTriviaSyntax
? GetPreviousPossiblyRelatedDirective()
325
DirectiveTriviaSyntax
? d = this;
Syntax\NullableContextStateMap.cs (1)
141
foreach (
var
d in tree.GetRoot().GetDirectives())
Syntax\SyntaxNodeRemover.cs (3)
145
if (trivia.IsDirective && trivia.GetStructure() is
DirectiveTriviaSyntax
directive)
436
.Select(tr => (
DirectiveTriviaSyntax
)tr.GetStructure()!);
474
private static bool HasRelatedDirectives(
DirectiveTriviaSyntax
directive)
Microsoft.CodeAnalysis.CSharp.CodeStyle (25)
src\Analyzers\CSharp\Analyzers\RemoveUnnecessaryNullableDirective\CSharpRemoveUnnecessaryNullableDirectiveDiagnosticAnalyzer.cs (2)
113
for (
var
directive = root.GetFirstDirective(); directive is not null; directive = directive.GetNextDirective())
196
for (
var
directive = root.GetFirstDirective(); directive is not null; directive = directive.GetNextDirective())
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\EmbeddedLanguages\VirtualChars\CSharpVirtualCharService.cs (1)
118
if (node is
DirectiveTriviaSyntax
)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\BlockSyntaxExtensions.cs (4)
68
var
firstDirective = (
DirectiveTriviaSyntax
)leadingDirectives.First().GetStructure()!;
83
foreach (
var
conditionalDirective in conditionalDirectives)
105
if (!conditionalDirectives.Contains((
DirectiveTriviaSyntax
)closeBraceDirective.GetStructure()!))
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\ContextQuery\SyntaxTreeExtensions.cs (1)
23
var directive = token.GetAncestor<
DirectiveTriviaSyntax
>();
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\DirectiveSyntaxExtensions.cs (10)
17
private static readonly ConditionalWeakTable<SyntaxNode, DirectiveInfo<
DirectiveTriviaSyntax
>> s_rootToDirectiveInfo = new();
29
private static DirectiveInfo<
DirectiveTriviaSyntax
> GetDirectiveInfo(SyntaxNode node, CancellationToken cancellationToken)
34
private static DirectiveInfo<
DirectiveTriviaSyntax
> GetDirectiveInfoForRoot(SyntaxNode root, CancellationToken cancellationToken)
35
=> CodeAnalysis.Shared.Extensions.SyntaxNodeExtensions.GetDirectiveInfoForRoot<
DirectiveTriviaSyntax
>(
38
internal static
DirectiveTriviaSyntax
? GetMatchingDirective(this
DirectiveTriviaSyntax
directive, CancellationToken cancellationToken)
51
public static ImmutableArray<
DirectiveTriviaSyntax
> GetMatchingConditionalDirectives(this
DirectiveTriviaSyntax
directive, CancellationToken cancellationToken)
63
private static bool IsRegionDirective(
DirectiveTriviaSyntax
directive)
66
private static bool IsConditionalDirective(
DirectiveTriviaSyntax
directive)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\ParenthesizedExpressionSyntaxExtensions.cs (1)
261
if (nodeParent is
DirectiveTriviaSyntax
)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\SyntaxNodeExtensions.cs (3)
556
var
match = ((
DirectiveTriviaSyntax
)structure).GetMatchingDirective(cancellationToken);
570
var directives = ((
DirectiveTriviaSyntax
)structure).GetMatchingConditionalDirectives(cancellationToken);
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Formatting\Rules\SuppressFormattingRule.cs (2)
329
var
endDirective = pragmaWarningDirectiveTrivia.GetNextDirective(trivia => IsFormatDirective(trivia, SyntaxKind.RestoreKeyword));
340
private static bool IsFormatDirective(
DirectiveTriviaSyntax
? trivia, SyntaxKind disableOrRestoreKeyword)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Services\SyntaxFacts\CSharpSyntaxFacts.cs (1)
131
=> node is
DirectiveTriviaSyntax
;
Microsoft.CodeAnalysis.CSharp.Features (22)
BraceMatching\CSharpDirectiveTriviaBraceMatcher.cs (6)
18
internal class CSharpDirectiveTriviaBraceMatcher : AbstractDirectiveTriviaBraceMatcher<
DirectiveTriviaSyntax
,
29
protected override ImmutableArray<
DirectiveTriviaSyntax
> GetMatchingConditionalDirectives(
DirectiveTriviaSyntax
directive, CancellationToken cancellationToken)
32
protected override
DirectiveTriviaSyntax
? GetMatchingDirective(
DirectiveTriviaSyntax
directive, CancellationToken cancellationToken)
35
internal override TextSpan GetSpanForTagging(
DirectiveTriviaSyntax
directive)
CodeRefactorings\EnableNullable\EnableNullableCodeRefactoringProvider.cs (4)
26
private static readonly Func<
DirectiveTriviaSyntax
, bool> s_isNullableDirectiveTriviaPredicate =
120
var
firstDirective = root.GetFirstDirective(s_isNullableDirectiveTriviaPredicate);
129
for (
var
directive = firstDirective; directive is not null; directive = directive.GetNextDirective(s_isNullableDirectiveTriviaPredicate))
243
var
firstRelevantDirective = root.GetFirstDirective(static directive => directive.Kind() is SyntaxKind.NullableDirectiveTrivia or SyntaxKind.IfDirectiveTrivia);
Completion\CompletionProviders\SnippetCompletionProvider.cs (1)
126
var directive = leftToken.GetAncestor<
DirectiveTriviaSyntax
>();
ConvertToRawString\ConvertToRawStringHelpers.cs (1)
69
if (node is
DirectiveTriviaSyntax
)
Highlighting\KeywordHighlighters\ConditionalPreprocessorHighlighter.cs (2)
20
internal sealed class ConditionalPreprocessorHighlighter() : AbstractKeywordHighlighter<
DirectiveTriviaSyntax
>
23
DirectiveTriviaSyntax
directive, List<TextSpan> highlights, CancellationToken cancellationToken)
Highlighting\KeywordHighlighters\RegionHighlighter.cs (2)
20
internal class RegionHighlighter : AbstractKeywordHighlighter<
DirectiveTriviaSyntax
>
29
DirectiveTriviaSyntax
directive, List<TextSpan> highlights, CancellationToken cancellationToken)
QuickInfo\CSharpSyntacticQuickInfoProvider.cs (1)
140
if (token.Parent is
DirectiveTriviaSyntax
directiveTrivia)
src\Analyzers\CSharp\Analyzers\RemoveUnnecessaryNullableDirective\CSharpRemoveUnnecessaryNullableDirectiveDiagnosticAnalyzer.cs (2)
113
for (
var
directive = root.GetFirstDirective(); directive is not null; directive = directive.GetNextDirective())
196
for (
var
directive = root.GetFirstDirective(); directive is not null; directive = directive.GetNextDirective())
Structure\Providers\IfDirectiveTriviaStructureProvider.cs (2)
31
var
directive = allRelatedDirectives[i];
39
var
nextDirective = allRelatedDirectives[i + 1];
Structure\Providers\RegionDirectiveStructureProvider.cs (1)
16
private static string GetBannerText(
DirectiveTriviaSyntax
simpleDirective)
Microsoft.CodeAnalysis.CSharp.Syntax.UnitTests (30)
Diagnostics\LineSpanDirectiveTests.cs (2)
463
var directives = tree.GetRoot().DescendantNodesAndSelf(descendIntoTrivia: true).OfType<
DirectiveTriviaSyntax
>();
464
foreach (
var
directive in directives)
LexicalAndXml\PreprocessorTests.cs (5)
130
foreach (
var
dt in directives)
149
foreach (
var
dt in directives)
160
var
dt = directives[idx++];
297
var
dt = directives[0];
301
private void VerifyDirectivePragma(
DirectiveTriviaSyntax
dt, PragmaInfo expected)
Parsing\ScriptParsingTests.cs (1)
9731
private void TestShebang(
DirectiveTriviaSyntax
directive, string expectedSkippedText)
Syntax\SyntaxNodeTests.cs (22)
337
var descendantDirectives = expr.DescendantNodesAndSelf(n => n.ContainsDirectives, descendIntoTrivia: true).OfType<
DirectiveTriviaSyntax
>().ToList();
1378
var
d = tree.GetCompilationUnitRoot().GetFirstDirective();
1390
var
d = tree.GetCompilationUnitRoot().GetLastDirective();
1407
var
d1 = tree.GetCompilationUnitRoot().GetFirstDirective();
1410
var
d2 = d1.GetNextDirective();
1413
var
d3 = d2.GetNextDirective();
1416
var
d4 = d3.GetNextDirective();
1419
var
d5 = d4.GetNextDirective();
1435
var
d1 = tree.GetCompilationUnitRoot().GetLastDirective();
1438
var
d2 = d1.GetPreviousDirective();
1441
var
d3 = d2.GetPreviousDirective();
1444
var
d4 = d3.GetPreviousDirective();
1447
var
d5 = d4.GetPreviousDirective();
1494
var
d = tree.GetCompilationUnitRoot().GetFirstDirective();
1525
var
d = tree.GetCompilationUnitRoot().GetFirstDirective();
1564
var
d = tree.GetCompilationUnitRoot().GetLastDirective();
1595
var
d = tree.GetCompilationUnitRoot().GetFirstDirective();
1629
var
d = tree.GetCompilationUnitRoot().GetFirstDirective();
1663
var
d = tree.GetCompilationUnitRoot().GetLastDirective();
1693
var
d = tree.GetCompilationUnitRoot().GetLastDirective();
1716
var
d = tree.GetCompilationUnitRoot().GetFirstDirective();
1737
var
d = tree.GetCompilationUnitRoot().GetLastDirective();
Microsoft.CodeAnalysis.CSharp.Workspaces (26)
Classification\Worker.cs (1)
254
ClassifyPreprocessorDirective((
DirectiveTriviaSyntax
)trivia.GetStructure()!);
Classification\Worker_Preprocesser.cs (2)
12
private void ClassifyPreprocessorDirective(
DirectiveTriviaSyntax
node)
78
private void ClassifyDirectiveTrivia(
DirectiveTriviaSyntax
node, bool allowComments = true)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\EmbeddedLanguages\VirtualChars\CSharpVirtualCharService.cs (1)
118
if (node is
DirectiveTriviaSyntax
)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\BlockSyntaxExtensions.cs (4)
68
var
firstDirective = (
DirectiveTriviaSyntax
)leadingDirectives.First().GetStructure()!;
83
foreach (
var
conditionalDirective in conditionalDirectives)
105
if (!conditionalDirectives.Contains((
DirectiveTriviaSyntax
)closeBraceDirective.GetStructure()!))
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\ContextQuery\SyntaxTreeExtensions.cs (1)
23
var directive = token.GetAncestor<
DirectiveTriviaSyntax
>();
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\DirectiveSyntaxExtensions.cs (10)
17
private static readonly ConditionalWeakTable<SyntaxNode, DirectiveInfo<
DirectiveTriviaSyntax
>> s_rootToDirectiveInfo = new();
29
private static DirectiveInfo<
DirectiveTriviaSyntax
> GetDirectiveInfo(SyntaxNode node, CancellationToken cancellationToken)
34
private static DirectiveInfo<
DirectiveTriviaSyntax
> GetDirectiveInfoForRoot(SyntaxNode root, CancellationToken cancellationToken)
35
=> CodeAnalysis.Shared.Extensions.SyntaxNodeExtensions.GetDirectiveInfoForRoot<
DirectiveTriviaSyntax
>(
38
internal static
DirectiveTriviaSyntax
? GetMatchingDirective(this
DirectiveTriviaSyntax
directive, CancellationToken cancellationToken)
51
public static ImmutableArray<
DirectiveTriviaSyntax
> GetMatchingConditionalDirectives(this
DirectiveTriviaSyntax
directive, CancellationToken cancellationToken)
63
private static bool IsRegionDirective(
DirectiveTriviaSyntax
directive)
66
private static bool IsConditionalDirective(
DirectiveTriviaSyntax
directive)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\ParenthesizedExpressionSyntaxExtensions.cs (1)
261
if (nodeParent is
DirectiveTriviaSyntax
)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Extensions\SyntaxNodeExtensions.cs (3)
556
var
match = ((
DirectiveTriviaSyntax
)structure).GetMatchingDirective(cancellationToken);
570
var directives = ((
DirectiveTriviaSyntax
)structure).GetMatchingConditionalDirectives(cancellationToken);
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Formatting\Rules\SuppressFormattingRule.cs (2)
329
var
endDirective = pragmaWarningDirectiveTrivia.GetNextDirective(trivia => IsFormatDirective(trivia, SyntaxKind.RestoreKeyword));
340
private static bool IsFormatDirective(
DirectiveTriviaSyntax
? trivia, SyntaxKind disableOrRestoreKeyword)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Services\SyntaxFacts\CSharpSyntaxFacts.cs (1)
131
=> node is
DirectiveTriviaSyntax
;
Microsoft.VisualStudio.LanguageServices.CSharp (1)
LanguageService\CSharpHelpContextService.cs (1)
345
var directive = token.GetAncestor<
DirectiveTriviaSyntax
>();