Ejemplo n.º 1
0
        /// <summary>
        /// Gets the syntax node represented the structure of this trivia, if any. The HasStructure property can be used to
        /// determine if this trivia has structure.
        /// </summary>
        /// <returns>
        /// A CSharpSyntaxNode derived from StructuredTriviaSyntax, with the structured view of this trivia node.
        /// If this trivia node does not have structure, returns null.
        /// </returns>
        /// <remarks>
        /// Some types of trivia have structure that can be accessed as additional syntax nodes.
        /// These forms of trivia include:
        ///   directives, where the structure describes the structure of the directive.
        ///   documentation comments, where the structure describes the XML structure of the comment.
        ///   skipped tokens, where the structure describes the tokens that were skipped by the parser.
        /// </remarks>

        public override SyntaxNode GetStructure(Microsoft.CodeAnalysis.SyntaxTrivia trivia)
        {
            if (trivia.HasStructure)
            {
                var parent = trivia.Token.Parent;
                if (parent != null)
                {
                    SyntaxNode structure;
                    var        structsInParent = structuresTable.GetOrCreateValue(parent);
                    lock (structsInParent)
                    {
                        if (!structsInParent.TryGetValue(trivia, out structure))
                        {
                            structure = CSharp.Syntax.StructuredTriviaSyntax.Create(trivia);
                            structsInParent.Add(trivia, structure);
                        }
                    }

                    return(structure);
                }
                else
                {
                    return(CSharp.Syntax.StructuredTriviaSyntax.Create(trivia));
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the syntax node represented the structure of this trivia, if any. The HasStructure property can be used to
        /// determine if this trivia has structure.
        /// </summary>
        ///
        /// <returns>
        /// A CSharpSyntaxNode derived from StructuredTriviaSyntax, with the structured view of this trivia node.
        /// If this trivia node does not have structure, returns null.
        /// </returns>
        ///
        /// <remarks>
        /// Some types of trivia have structure that can be accessed as additional syntax nodes.
        /// These forms of trivia include:
        ///   directives, where the structure describes the structure of the directive.
        ///   documentation comments, where the structure describes the XML structure of the comment.
        ///   skipped tokens, where the structure describes the tokens that were skipped by the parser.
        /// </remarks>

        public override SyntaxNode GetStructure(Microsoft.CodeAnalysis.SyntaxTrivia trivia)
        {
            if (trivia.HasStructure)
            {
                var parent = trivia.Token.Parent;
                if (parent != null)
                {
                    DebuggerUtilities.CallBeforeAcquiringLock();                     //see method comment

                    SyntaxNode structure;
                    var        structsInParent = structuresTable.GetOrCreateValue(parent);
                    lock (structsInParent)
                    {
                        if (!structsInParent.TryGetValue(trivia, out structure))
                        {
                            structure = CSharp.Syntax.StructuredTriviaSyntax.Create(trivia);
                            structsInParent.Add(trivia, structure);
                        }
                    }

                    return(structure);
                }
                else
                {
                    return(CSharp.Syntax.StructuredTriviaSyntax.Create(trivia));
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        public override void VisitTrivia(Microsoft.CodeAnalysis.SyntaxTrivia trivia)
        {
            var indents = new String(' ', tabs * tabWidth);

            if (_configurationOptions.DisplayFormattedOutput)
            {
                Messages.AppendLine(string.Format("Trivia:{0}{1}:>{2}<", indents,
                                                  _configurationOptions.DisplayNodeKind ? trivia.Kind().ToString() : "",
                                                  _configurationOptions.DisplayNodeValue ? trivia.ToString() : ""));
            }
            else
            {
                Messages.AppendLine(string.Format("Trivia:{0}:>{1}<",
                                                  _configurationOptions.DisplayNodeKind ? trivia.Kind().ToString() : "",
                                                  _configurationOptions.DisplayNodeValue ? trivia.ToString() : ""));
            }

            // Call base to visit children

            base.VisitTrivia(trivia);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Gets a list of all the diagnostics associated with the trivia.
 /// This method does not filter diagnostics based on #pragmas and compiler options
 /// like nowarn, warnaserror etc.
 /// </summary>
 public abstract IEnumerable <Diagnostic> GetDiagnostics(SyntaxTrivia trivia);
Ejemplo n.º 5
0
 /// <summary>
 /// Creates a new tree of nodes with new trivia inserted after the specified trivia.
 /// </summary>
 /// <typeparam name="TRoot">The type of the root node.</typeparam>
 /// <param name="root">The root of the tree of nodes.</param>
 /// <param name="trivia">The trivia to insert after; a descendant of the root node.</param>
 /// <param name="newTrivia">A sequence of trivia to insert into the tree immediately after the specified trivia.</param>
 public static TRoot InsertTriviaAfter <TRoot>(this TRoot root, SyntaxTrivia trivia, IEnumerable <SyntaxTrivia> newTrivia)
     where TRoot : SyntaxNode
 {
     return((TRoot)root.InsertTriviaInListCore(trivia, newTrivia, insertBefore: false));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Creates a new tree of nodes with the specified trivia replaced with new trivia.
 /// </summary>
 /// <typeparam name="TRoot">The type of the root node.</typeparam>
 /// <param name="root">The root node of the tree of nodes.</param>
 /// <param name="trivia">The trivia to be replaced.</param>
 /// <param name="newTrivia">The new trivia to use in the new tree in place of the old trivia.</param>
 public static TRoot ReplaceTrivia <TRoot>(this TRoot root, SyntaxTrivia trivia, SyntaxTrivia newTrivia)
     where TRoot : SyntaxNode
 {
     return((TRoot)root.ReplaceCore <SyntaxNode>(trivia: new[] { trivia }, computeReplacementTrivia: (o, r) => newTrivia));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Creates a new tree of nodes with the specified old trivia replaced with new trivia.
 /// </summary>
 /// <typeparam name="TRoot">The type of the root node.</typeparam>
 /// <param name="root">The root of the tree of nodes.</param>
 /// <param name="oldTrivia">The trivia to be replaced; a descendant of the root node.</param>
 /// <param name="newTrivia">A sequence of trivia to use in the tree in place of the specified trivia.</param>
 public static TRoot ReplaceTrivia <TRoot>(this TRoot root, SyntaxTrivia oldTrivia, IEnumerable <SyntaxTrivia> newTrivia)
     where TRoot : SyntaxNode
 {
     return((TRoot)root.ReplaceTriviaInListCore(oldTrivia, newTrivia));
 }
Ejemplo n.º 8
0
 public abstract SyntaxNode GetStructure(SyntaxTrivia parentTrivia);
Ejemplo n.º 9
0
 public SourceLocation(SyntaxTrivia trivia)
     : this(trivia.SyntaxTree, trivia.Span)
 {
 }
Ejemplo n.º 10
0
 protected internal abstract SyntaxNode InsertTriviaInListCore(SyntaxTrivia originalTrivia, IEnumerable <SyntaxTrivia> newTrivia, bool insertBefore);
Ejemplo n.º 11
0
 protected internal abstract SyntaxNode ReplaceTriviaInListCore(SyntaxTrivia originalTrivia, IEnumerable <SyntaxTrivia> newTrivia);