Class SyntaxTree
The parsed representation of a source document.
Inheritance
System.Object
SyntaxTree
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Assembly: cs.temp.dll.dll
Syntax
public abstract class SyntaxTree
Properties
Encoding
The text encoding of the source document.
Declaration
public abstract Encoding? Encoding { get; }
Property Value
Type |
Description |
System.Nullable<Encoding> |
|
FilePath
The path of the source document file.
Declaration
public abstract string FilePath { get; }
Property Value
Type |
Description |
System.String |
|
HasCompilationUnitRoot
Returns true if this syntax tree has a root with SyntaxKind "CompilationUnit".
Declaration
public abstract bool HasCompilationUnitRoot { get; }
Property Value
Type |
Description |
System.Boolean |
|
Length
The length of the text of the syntax tree.
Declaration
public abstract int Length { get; }
Property Value
Type |
Description |
System.Int32 |
|
Options
The options used by the parser to produce the syntax tree.
Declaration
public ParseOptions Options { get; }
Property Value
Methods
GetChangedSpans(SyntaxTree)
Returns a list of the changed regions between this tree and the specified tree. The list is conservative for
performance reasons. It may return larger regions than what has actually changed.
Declaration
public abstract IList<TextSpan> GetChangedSpans(SyntaxTree syntaxTree)
Parameters
Returns
Type |
Description |
IList<TextSpan> |
|
GetChanges(SyntaxTree)
Gets a list of text changes that when applied to the old tree produce this tree.
Declaration
public abstract IList<TextChange> GetChanges(SyntaxTree oldTree)
Parameters
Type |
Name |
Description |
SyntaxTree |
oldTree |
The old tree.
|
Returns
Type |
Description |
IList<TextChange> |
|
GetDiagnostics(CancellationToken)
Gets a list of all the diagnostics in the syntax tree.
This method does not filter diagnostics based on #pragmas and compiler options
like nowarn, warnaserror etc.
Declaration
public abstract IEnumerable<Diagnostic> GetDiagnostics(CancellationToken cancellationToken = null)
Parameters
Type |
Name |
Description |
CancellationToken |
cancellationToken |
|
Returns
GetDiagnostics(SyntaxNode)
Gets a list of all the diagnostics in the sub tree that has the specified node as its root.
This method does not filter diagnostics based on #pragmas and compiler options
like nowarn, warnaserror etc.
Declaration
public abstract IEnumerable<Diagnostic> GetDiagnostics(SyntaxNode node)
Parameters
Returns
GetDiagnostics(SyntaxNodeOrToken)
Gets a list of all the diagnostics in either the sub tree that has the specified node as its root or
associated with the token and its related trivia.
This method does not filter diagnostics based on #pragmas and compiler options
like nowarn, warnaserror etc.
Declaration
public abstract IEnumerable<Diagnostic> GetDiagnostics(SyntaxNodeOrToken nodeOrToken)
Parameters
Returns
GetDiagnostics(SyntaxToken)
Gets a list of all the diagnostics associated with the token and any related trivia.
This method does not filter diagnostics based on #pragmas and compiler options
like nowarn, warnaserror etc.
Declaration
public abstract IEnumerable<Diagnostic> GetDiagnostics(SyntaxToken token)
Parameters
Returns
GetDiagnostics(SyntaxTrivia)
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.
Declaration
public abstract IEnumerable<Diagnostic> GetDiagnostics(SyntaxTrivia trivia)
Parameters
Returns
GetLineSpan(TextSpan, CancellationToken)
Gets the location in terms of path, line and column for a given span.
Declaration
public abstract FileLinePositionSpan GetLineSpan(TextSpan span, CancellationToken cancellationToken = null)
Parameters
Type |
Name |
Description |
TextSpan |
span |
Span within the tree.
|
CancellationToken |
cancellationToken |
Cancellation token.
|
Returns
GetLocation(TextSpan)
Gets a location for the specified text span.
Declaration
public abstract Location GetLocation(TextSpan span)
Parameters
Type |
Name |
Description |
TextSpan |
span |
|
Returns
GetReference(SyntaxNode)
Gets a SyntaxReference for a specified syntax node. SyntaxReferences can be used to
regain access to a syntax node without keeping the entire tree and source text in
memory.
Declaration
public abstract SyntaxReference GetReference(SyntaxNode node)
Parameters
Returns
GetRoot(CancellationToken)
Gets the root node of the syntax tree, causing computation if necessary.
Declaration
public SyntaxNode GetRoot(CancellationToken cancellationToken = null)
Parameters
Type |
Name |
Description |
CancellationToken |
cancellationToken |
|
Returns
GetRootAsync(CancellationToken)
Gets the root node of the syntax tree asynchronously.
Declaration
public Task<SyntaxNode> GetRootAsync(CancellationToken cancellationToken = null)
Parameters
Type |
Name |
Description |
CancellationToken |
cancellationToken |
|
Returns
GetText(CancellationToken)
Gets the text of the source document.
Declaration
public abstract SourceText GetText(CancellationToken cancellationToken = null)
Parameters
Type |
Name |
Description |
CancellationToken |
cancellationToken |
|
Returns
Type |
Description |
SourceText |
|
GetTextAsync(CancellationToken)
Gets the text of the source document asynchronously.
Declaration
public virtual Task<SourceText> GetTextAsync(CancellationToken cancellationToken = null)
Parameters
Type |
Name |
Description |
CancellationToken |
cancellationToken |
|
Returns
Type |
Description |
Task<SourceText> |
|
IsEquivalentTo(SyntaxTree, Boolean)
Determines if two trees are the same, disregarding trivia differences.
Declaration
public abstract bool IsEquivalentTo(SyntaxTree tree, bool topLevel = false)
Parameters
Type |
Name |
Description |
SyntaxTree |
tree |
The tree to compare against.
|
System.Boolean |
topLevel |
If true then the trees are equivalent if the contained nodes and tokens declaring
metadata visible symbolic information are equivalent, ignoring any differences of nodes inside method bodies
or initializer expressions, otherwise all nodes and tokens must be equivalent.
|
Returns
Type |
Description |
System.Boolean |
|
ToString()
Returns a System.String that represents the entire source text of this SyntaxTree.
Declaration
public override string ToString()
Returns
Type |
Description |
System.String |
|
Overrides
System.Object.ToString()
TryGetRoot(out SyntaxNode)
Gets the root of the syntax tree if it is available.
Declaration
public bool TryGetRoot(out SyntaxNode root)
Parameters
Returns
Type |
Description |
System.Boolean |
|
TryGetText(out Nullable<SourceText>)
Gets the syntax tree's text if it is available.
Declaration
public abstract bool TryGetText(out SourceText? text)
Parameters
Type |
Name |
Description |
System.Nullable<SourceText> |
text |
|
Returns
Type |
Description |
System.Boolean |
|
WithChangedText(SourceText)
Create a new syntax tree based off this tree using a new source text.
If the new source text is a minor change from the current source text an incremental
parse will occur reusing most of the current syntax tree internal data. Otherwise, a
full parse will occur using the new source text.
Declaration
public abstract SyntaxTree WithChangedText(SourceText newText)
Parameters
Type |
Name |
Description |
SourceText |
newText |
|
Returns
WithFilePath(String)
Returns a new tree whose FilePath is the specified node and other properties are copied from the current tree.
Declaration
public abstract SyntaxTree WithFilePath(string path)
Parameters
Type |
Name |
Description |
System.String |
path |
|
Returns
WithRootAndOptions(SyntaxNode, ParseOptions)
Returns a new tree whose root and options are as specified and other properties are copied from the current tree.
Declaration
public abstract SyntaxTree WithRootAndOptions(SyntaxNode root, ParseOptions options)
Parameters
Returns