Class AstNode
- Namespace
- ICSharpCode.Decompiler.CSharp.Syntax
- Assembly
- ICSharpCode.Decompiler.dll
public abstract class AstNode : AbstractAnnotatable, IAnnotatable, IFreezable, INode, ICloneable
- Inheritance
-
AstNode
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
AstNode()
protected AstNode()
Fields
AstNodeFlagsUsedBits
protected const int AstNodeFlagsUsedBits = 10
Field Value
Null
public static readonly AstNode Null
Field Value
flags
protected uint flags
Field Value
Properties
Ancestors
Gets the ancestors of this node (excluding this node itself)
public IEnumerable<AstNode> Ancestors { get; }
Property Value
AncestorsAndSelf
Gets the ancestors of this node (including this node itself)
public IEnumerable<AstNode> AncestorsAndSelf { get; }
Property Value
Children
public IEnumerable<AstNode> Children { get; }
Property Value
Descendants
Gets all descendants of this node (excluding this node itself) in pre-order.
public IEnumerable<AstNode> Descendants { get; }
Property Value
DescendantsAndSelf
Gets all descendants of this node (including this node itself) in pre-order.
public IEnumerable<AstNode> DescendantsAndSelf { get; }
Property Value
EndLocation
public virtual TextLocation EndLocation { get; }
Property Value
FirstChild
public AstNode? FirstChild { get; }
Property Value
HasChildren
public bool HasChildren { get; }
Property Value
IsFrozen
Gets if this instance is frozen. Frozen instances are immutable and thus thread-safe.
public bool IsFrozen { get; }
Property Value
IsNull
public virtual bool IsNull { get; }
Property Value
LastChild
public AstNode? LastChild { get; }
Property Value
NextSibling
public AstNode? NextSibling { get; }
Property Value
NodeType
public abstract NodeType NodeType { get; }
Property Value
Parent
public AstNode? Parent { get; }
Property Value
PrevSibling
public AstNode? PrevSibling { get; }
Property Value
Role
public Role Role { get; set; }
Property Value
StartLocation
public virtual TextLocation StartLocation { get; }
Property Value
Methods
AcceptVisitor(IAstVisitor)
public abstract void AcceptVisitor(IAstVisitor visitor)
Parameters
visitor
IAstVisitor
AcceptVisitor<T>(IAstVisitor<T>)
public abstract T AcceptVisitor<T>(IAstVisitor<T> visitor)
Parameters
visitor
IAstVisitor<T>
Returns
- T
Type Parameters
T
AcceptVisitor<T, S>(IAstVisitor<T, S>, T)
public abstract S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
Parameters
visitor
IAstVisitor<T, S>data
T
Returns
- S
Type Parameters
T
S
AddAnnotation(object)
public override void AddAnnotation(object annotation)
Parameters
annotation
object
AddChildWithExistingRole(AstNode?)
public void AddChildWithExistingRole(AstNode? child)
Parameters
child
AstNode
AddChild<T>(T, Role<T>)
public void AddChild<T>(T child, Role<T> role) where T : AstNode
Parameters
child
Trole
Role<T>
Type Parameters
T
Clone()
Clones the whole subtree starting at this AST node.
public AstNode Clone()
Returns
Remarks
Annotations are copied over to the new nodes; and any annotations implementing ICloneable will be cloned.
Contains(TextLocation)
Returns true, if the given coordinates are in the node.
public bool Contains(TextLocation location)
Parameters
location
TextLocation
Returns
- bool
True, if location is between StartLocation and EndLocation (exclusive); otherwise, false.
Contains(int, int)
Returns true, if the given coordinates (line, column) are in the node.
public bool Contains(int line, int column)
Parameters
Returns
- bool
True, if the given coordinates are between StartLocation and EndLocation (exclusive); otherwise, false.
DescendantNodes(Func<AstNode, bool>?)
public IEnumerable<AstNode> DescendantNodes(Func<AstNode, bool>? descendIntoChildren = null)
Parameters
Returns
DescendantNodesAndSelf(Func<AstNode, bool>?)
public IEnumerable<AstNode> DescendantNodesAndSelf(Func<AstNode, bool>? descendIntoChildren = null)
Parameters
Returns
DoMatch(AstNode?, Match)
protected abstract bool DoMatch(AstNode? other, Match match)
Parameters
Returns
Freeze()
Freezes this instance.
public void Freeze()
GetAdjacentNodeAt(TextLocation, Predicate<AstNode>?)
Gets the node specified by pred at location. This is useful for getting a specific node from the tree. For example searching the current method declaration. (End inclusive)
public AstNode? GetAdjacentNodeAt(TextLocation location, Predicate<AstNode>? pred = null)
Parameters
location
TextLocationpred
Predicate<AstNode>
Returns
GetAdjacentNodeAt(int, int, Predicate<AstNode>?)
Gets the node specified by pred at the location line, column. This is useful for getting a specific node from the tree. For example searching the current method declaration. (End inclusive)
public AstNode? GetAdjacentNodeAt(int line, int column, Predicate<AstNode>? pred = null)
Parameters
Returns
GetAdjacentNodeAt<T>(TextLocation)
Gets the node specified by T at location. This is useful for getting a specific node from the tree. For example searching the current method declaration. (End inclusive)
public T? GetAdjacentNodeAt<T>(TextLocation location) where T : AstNode
Parameters
location
TextLocation
Returns
- T
Type Parameters
T
GetAdjacentNodeAt<T>(int, int)
Gets the node specified by T at the location line, column. This is useful for getting a specific node from the tree. For example searching the current method declaration. (End inclusive)
public T? GetAdjacentNodeAt<T>(int line, int column) where T : AstNode
Parameters
Returns
- T
Type Parameters
T
GetCSharpNodeBefore(AstNode)
public AstNode? GetCSharpNodeBefore(AstNode node)
Parameters
node
AstNode
Returns
GetChildByRole<T>(Role<T>)
Gets the first child with the specified role. Returns the role's null object if the child is not found.
public T GetChildByRole<T>(Role<T> role) where T : AstNode?
Parameters
role
Role<T>
Returns
- T
Type Parameters
T
GetChildrenByRole<T>(Role<T>)
public AstNodeCollection<T> GetChildrenByRole<T>(Role<T> role) where T : AstNode
Parameters
role
Role<T>
Returns
Type Parameters
T
GetNextNode()
public AstNode? GetNextNode()
Returns
GetNextNode(Func<AstNode, bool>)
Gets the next node which fullfills a given predicate
public AstNode? GetNextNode(Func<AstNode, bool> pred)
Parameters
Returns
- AstNode
The next node.
GetNextSibling(Func<AstNode, bool>)
Gets the next sibling which fullfills a given predicate
public AstNode? GetNextSibling(Func<AstNode, bool> pred)
Parameters
Returns
- AstNode
The next node.
GetNodeAt(TextLocation, Predicate<AstNode>?)
Gets the node specified by pred at location. This is useful for getting a specific node from the tree. For example searching the current method declaration. (End exclusive)
public AstNode? GetNodeAt(TextLocation location, Predicate<AstNode>? pred = null)
Parameters
location
TextLocationpred
Predicate<AstNode>
Returns
GetNodeAt(int, int, Predicate<AstNode>?)
Gets the node specified by T at the location line, column. This is useful for getting a specific node from the tree. For example searching the current method declaration. (End exclusive)
public AstNode? GetNodeAt(int line, int column, Predicate<AstNode>? pred = null)
Parameters
Returns
GetNodeAt<T>(TextLocation)
Gets the node specified by T at location. This is useful for getting a specific node from the tree. For example searching the current method declaration. (End exclusive)
public T? GetNodeAt<T>(TextLocation location) where T : AstNode
Parameters
location
TextLocation
Returns
- T
Type Parameters
T
GetNodeAt<T>(int, int)
Gets the node specified by T at the location line, column. This is useful for getting a specific node from the tree. For example searching the current method declaration. (End exclusive)
public T? GetNodeAt<T>(int line, int column) where T : AstNode
Parameters
Returns
- T
Type Parameters
T
GetNodeContaining(TextLocation, TextLocation)
Gets the node that fully contains the range from startLocation to endLocation.
public AstNode GetNodeContaining(TextLocation startLocation, TextLocation endLocation)
Parameters
startLocation
TextLocationendLocation
TextLocation
Returns
GetNodesBetween(TextLocation, TextLocation)
Returns the root nodes of all subtrees that are fully contained between start
and end
(inclusive).
public IEnumerable<AstNode> GetNodesBetween(TextLocation start, TextLocation end)
Parameters
start
TextLocationend
TextLocation
Returns
GetNodesBetween(int, int, int, int)
Returns the root nodes of all subtrees that are fully contained in the specified region.
public IEnumerable<AstNode> GetNodesBetween(int startLine, int startColumn, int endLine, int endColumn)
Parameters
Returns
GetParent(Func<AstNode, bool>?)
public AstNode? GetParent(Func<AstNode, bool>? pred)
Parameters
Returns
GetParent<T>()
public T? GetParent<T>() where T : AstNode
Returns
- T
Type Parameters
T
GetPrevNode()
public AstNode? GetPrevNode()
Returns
GetPrevNode(Func<AstNode, bool>)
Gets the previous node which fullfills a given predicate
public AstNode? GetPrevNode(Func<AstNode, bool> pred)
Parameters
Returns
- AstNode
The next node.
GetPrevSibling(Func<AstNode, bool>)
Gets the next sibling which fullfills a given predicate
public AstNode? GetPrevSibling(Func<AstNode, bool> pred)
Parameters
Returns
- AstNode
The next node.
InsertChildAfter<T>(AstNode?, T, Role<T>)
public void InsertChildAfter<T>(AstNode? prevSibling, T child, Role<T> role) where T : AstNode
Parameters
Type Parameters
T
InsertChildBefore<T>(AstNode?, T, Role<T>)
public void InsertChildBefore<T>(AstNode? nextSibling, T child, Role<T> role) where T : AstNode
Parameters
Type Parameters
T
IsInside(TextLocation)
Returns true, if the given coordinates are in the node.
public bool IsInside(TextLocation location)
Parameters
location
TextLocation
Returns
- bool
True, if location is between StartLocation and EndLocation (inclusive); otherwise, false.
IsInside(int, int)
Returns true, if the given coordinates (line, column) are in the node.
public bool IsInside(int line, int column)
Parameters
Returns
- bool
True, if the given coordinates are between StartLocation and EndLocation (inclusive); otherwise, false.
MatchString(string?, string?)
protected static bool MatchString(string? pattern, string? text)
Parameters
Returns
Remove()
Removes this node from its parent.
public void Remove()
ReplaceWith(AstNode?)
Replaces this node with the new node.
public void ReplaceWith(AstNode? newNode)
Parameters
newNode
AstNode
ReplaceWith(Func<AstNode, AstNode?>)
public AstNode? ReplaceWith(Func<AstNode, AstNode?> replaceFunction)
Parameters
Returns
SetChildByRole<T>(Role<T>, T)
protected void SetChildByRole<T>(Role<T> role, T newChild) where T : AstNode
Parameters
role
Role<T>newChild
T
Type Parameters
T
ThrowIfFrozen()
protected void ThrowIfFrozen()
ToString()
public override sealed string ToString()
Returns
ToString(CSharpFormattingOptions?)
Gets the node as formatted C# output.
public virtual string ToString(CSharpFormattingOptions? formattingOptions)
Parameters
formattingOptions
CSharpFormattingOptionsFormatting options.
Returns
Operators
implicit operator AstNode?(Pattern?)
public static implicit operator AstNode?(Pattern? pattern)
Parameters
pattern
Pattern