Пример #1
0
        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 (FileSpan.File.IsRootFile || includeNonRootFile)
            {
                sb.Append(Text);
            }

            if (MacroReference == null && trailing)
            {
                foreach (var trivia in TrailingTrivia)
                {
                    trivia.WriteTo(sb, true, true, includeNonRootFile, ignoreMacroReferences);
                }
            }
        }
Пример #2
0
        internal SyntaxToken(SyntaxKind kind, SyntaxKind contextualKind,
                             bool isMissing, SourceRange sourceRange, SourceFileSpan 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;
        }
Пример #3
0
 public SyntaxToken WithOriginalMacroReference(MacroReference macroReference, bool isFirstTokenInMacroExpansion)
 {
     return(new SyntaxToken(Kind, ContextualKind, IsMissing, SourceRange, FileSpan, Text, Value, LeadingTrivia, TrailingTrivia, Diagnostics, macroReference, isFirstTokenInMacroExpansion));
 }