protected internal override void WriteTo(StringBuilder sb, bool leading, bool trailing, bool includeNonRootFile, bool ignoreMacroReferences) { if (!ignoreMacroReferences && MacroReference != null && !IsFirstTokenInMacroExpansion) { return; } if ((ignoreMacroReferences || MacroReference == null) && leading) { foreach (var trivia in LeadingTrivia) { trivia.WriteTo(sb, true, true, includeNonRootFile, ignoreMacroReferences); } } if (!ignoreMacroReferences && MacroReference != null) { MacroReference.WriteTo(sb, leading, trailing, includeNonRootFile, ignoreMacroReferences); } else if (Span.IsInRootFile || includeNonRootFile) { sb.Append(Text); } if (MacroReference == null && trailing) { foreach (var trivia in TrailingTrivia) { trivia.WriteTo(sb, true, true, includeNonRootFile, ignoreMacroReferences); } } }
internal SyntaxToken(SyntaxKind kind, SyntaxKind contextualKind, bool isMissing, SourceRange sourceRange, TextSpan span, string text, object value, IEnumerable <SyntaxNode> leadingTrivia, IEnumerable <SyntaxNode> trailingTrivia, IEnumerable <Diagnostic> diagnostics, MacroReference macroReference, bool isFirstTokenInMacroExpansion) : base(kind, text, span, diagnostics) { ContextualKind = contextualKind; IsMissing = isMissing; SourceRange = sourceRange; Value = value; LeadingTrivia = leadingTrivia.ToImmutableArray(); foreach (var triviaNode in LeadingTrivia) { ((SyntaxNodeBase)triviaNode).Parent = this; } TrailingTrivia = trailingTrivia.ToImmutableArray(); foreach (var triviaNode in TrailingTrivia) { ((SyntaxNodeBase)triviaNode).Parent = this; } FullSourceRange = ComputeFullSpan(sourceRange, LeadingTrivia, TrailingTrivia); ContainsDiagnostics = Diagnostics.Any() || LeadingTrivia.Any(x => x.ContainsDiagnostics) || TrailingTrivia.Any(x => x.ContainsDiagnostics); ContainsDirectives = LeadingTrivia.OfType <DirectiveTriviaSyntax>().Any() || TrailingTrivia.OfType <DirectiveTriviaSyntax>().Any(); MacroReference = macroReference; IsFirstTokenInMacroExpansion = isFirstTokenInMacroExpansion; }
public SyntaxToken WithOriginalMacroReference(MacroReference macroReference, bool isFirstTokenInMacroExpansion) { return(new SyntaxToken(Kind, ContextualKind, IsMissing, SourceRange, Span, Text, Value, LeadingTrivia, TrailingTrivia, Diagnostics, macroReference, isFirstTokenInMacroExpansion)); }