From 2ea2d1cc20e49aea0eb8c224ce69113e066e8006 Mon Sep 17 00:00:00 2001 From: Alexandre Mutel Date: Tue, 25 Jan 2022 06:09:54 +0100 Subject: [PATCH] Rename SyntaxNode.GetChildren to GetChild --- src/Tomlyn.Tests/SyntaxTests.cs | 4 ++-- src/Tomlyn/Model/SyntaxToModelTransform.cs | 12 +++++------ src/Tomlyn/Syntax/ArrayItemSyntax.cs | 2 +- src/Tomlyn/Syntax/ArraySyntax.cs | 2 +- src/Tomlyn/Syntax/BareKeySyntax.cs | 2 +- src/Tomlyn/Syntax/BooleanValueSyntax.cs | 2 +- src/Tomlyn/Syntax/DateTimeValueSyntax.cs | 2 +- src/Tomlyn/Syntax/DocumentSyntax.cs | 2 +- src/Tomlyn/Syntax/DottedKeyItemSyntax.cs | 2 +- src/Tomlyn/Syntax/FloatValueSyntax.cs | 2 +- src/Tomlyn/Syntax/InlineTableItemSyntax.cs | 2 +- src/Tomlyn/Syntax/InlineTableSyntax.cs | 2 +- src/Tomlyn/Syntax/IntegerValueSyntax.cs | 2 +- src/Tomlyn/Syntax/KeySyntax.cs | 2 +- src/Tomlyn/Syntax/KeyValueSyntax.cs | 2 +- src/Tomlyn/Syntax/StringValueSyntax.cs | 2 +- src/Tomlyn/Syntax/SyntaxList.cs | 12 +++++------ src/Tomlyn/Syntax/SyntaxNode.cs | 25 +++++++++++----------- src/Tomlyn/Syntax/SyntaxToken.cs | 2 +- src/Tomlyn/Syntax/SyntaxValidator.cs | 4 ++-- src/Tomlyn/Syntax/SyntaxVisitor.cs | 2 +- src/Tomlyn/Syntax/TableSyntaxBase.cs | 6 +++++- 22 files changed, 50 insertions(+), 45 deletions(-) diff --git a/src/Tomlyn.Tests/SyntaxTests.cs b/src/Tomlyn.Tests/SyntaxTests.cs index 47e6ecb..bc089e0 100644 --- a/src/Tomlyn.Tests/SyntaxTests.cs +++ b/src/Tomlyn.Tests/SyntaxTests.cs @@ -40,10 +40,10 @@ public void TestDocument() table.AddLeadingComment("This is a comment"); table.AddLeadingTriviaNewLine(); - var firstElement = table.Items.GetChildren(0); + var firstElement = table.Items.GetChild(0); firstElement.AddTrailingComment("This is an item comment"); - var secondElement = table.Items.GetChildren(2); + var secondElement = table.Items.GetChild(2); secondElement.AddLeadingTriviaNewLine(); secondElement.AddLeadingComment("This is a comment in a middle of a table"); secondElement.AddLeadingTriviaNewLine(); diff --git a/src/Tomlyn/Model/SyntaxToModelTransform.cs b/src/Tomlyn/Model/SyntaxToModelTransform.cs index 7c9246b..72abd5c 100644 --- a/src/Tomlyn/Model/SyntaxToModelTransform.cs +++ b/src/Tomlyn/Model/SyntaxToModelTransform.cs @@ -154,7 +154,7 @@ private bool TryFollowKeyPath(KeySyntax key, SyntaxKind kind, out string name) { return false; } - var nextItem = items.GetChildren(i); + var nextItem = items.GetChild(i); item = nextItem!; name = GetStringFromBasic(nextItem!.Key!) ?? string.Empty; } @@ -290,7 +290,7 @@ public override void Visit(ArraySyntax array) var items = array.Items; for (int i = 0; i < items.ChildrenCount; i++) { - var item = items.GetChildren(i)!; + var item = items.GetChild(i)!; item.Accept(this); // Make sure that we can convert the item to the destination value @@ -438,8 +438,8 @@ public override void Visit(InlineTableSyntax inlineTable) metadata.LeadingTrivia = trivias; } - var lastChildren = keyValue.Value?.GetChildren(keyValue.Value.ChildrenCount - 1); - trivias = ConvertTrivias(lastChildren?.TrailingTrivia); + var lastChild = keyValue.Value?.GetChild(keyValue.Value.ChildrenCount - 1); + trivias = ConvertTrivias(lastChild?.TrailingTrivia); if (trivias != null && trivias.Count > 0) { metadata ??= new TomlPropertyMetadata(); @@ -463,8 +463,8 @@ public override void Visit(InlineTableSyntax inlineTable) metadata.LeadingTrivia = trivias; } - var lastChildren = tableSyntax.CloseBracket; - trivias = ConvertTrivias(lastChildren?.TrailingTrivia); + var lastChild = tableSyntax.CloseBracket; + trivias = ConvertTrivias(lastChild?.TrailingTrivia); if (trivias != null && trivias.Count > 0) { metadata ??= new TomlPropertyMetadata(); diff --git a/src/Tomlyn/Syntax/ArrayItemSyntax.cs b/src/Tomlyn/Syntax/ArrayItemSyntax.cs index 83e81ea..f28b5e8 100644 --- a/src/Tomlyn/Syntax/ArrayItemSyntax.cs +++ b/src/Tomlyn/Syntax/ArrayItemSyntax.cs @@ -43,7 +43,7 @@ public override void Accept(SyntaxVisitor visitor) public override int ChildrenCount => 2; - protected override SyntaxNode? GetChildrenImpl(int index) + protected override SyntaxNode? GetChildImpl(int index) { return index == 0 ? (SyntaxNode?)Value : Comma; } diff --git a/src/Tomlyn/Syntax/ArraySyntax.cs b/src/Tomlyn/Syntax/ArraySyntax.cs index a0cd574..be23f02 100644 --- a/src/Tomlyn/Syntax/ArraySyntax.cs +++ b/src/Tomlyn/Syntax/ArraySyntax.cs @@ -93,7 +93,7 @@ public override void Accept(SyntaxVisitor visitor) public override int ChildrenCount => 3; - protected override SyntaxNode? GetChildrenImpl(int index) + protected override SyntaxNode? GetChildImpl(int index) { switch (index) { diff --git a/src/Tomlyn/Syntax/BareKeySyntax.cs b/src/Tomlyn/Syntax/BareKeySyntax.cs index f5a5d81..2dd3afc 100644 --- a/src/Tomlyn/Syntax/BareKeySyntax.cs +++ b/src/Tomlyn/Syntax/BareKeySyntax.cs @@ -46,7 +46,7 @@ public override void Accept(SyntaxVisitor visitor) visitor.Visit(this); } - protected override SyntaxNode? GetChildrenImpl(int index) + protected override SyntaxNode? GetChildImpl(int index) { return Key; } diff --git a/src/Tomlyn/Syntax/BooleanValueSyntax.cs b/src/Tomlyn/Syntax/BooleanValueSyntax.cs index 7856153..68d5eed 100644 --- a/src/Tomlyn/Syntax/BooleanValueSyntax.cs +++ b/src/Tomlyn/Syntax/BooleanValueSyntax.cs @@ -54,7 +54,7 @@ public override void Accept(SyntaxVisitor visitor) public override int ChildrenCount => 1; - protected override SyntaxNode? GetChildrenImpl(int index) + protected override SyntaxNode? GetChildImpl(int index) { return Token; } diff --git a/src/Tomlyn/Syntax/DateTimeValueSyntax.cs b/src/Tomlyn/Syntax/DateTimeValueSyntax.cs index bff9ae7..591b889 100644 --- a/src/Tomlyn/Syntax/DateTimeValueSyntax.cs +++ b/src/Tomlyn/Syntax/DateTimeValueSyntax.cs @@ -42,7 +42,7 @@ public override void Accept(SyntaxVisitor visitor) visitor.Visit(this); } - protected override SyntaxNode? GetChildrenImpl(int index) + protected override SyntaxNode? GetChildImpl(int index) { return Token; } diff --git a/src/Tomlyn/Syntax/DocumentSyntax.cs b/src/Tomlyn/Syntax/DocumentSyntax.cs index 5625fc1..295fbac 100644 --- a/src/Tomlyn/Syntax/DocumentSyntax.cs +++ b/src/Tomlyn/Syntax/DocumentSyntax.cs @@ -45,7 +45,7 @@ public override void Accept(SyntaxVisitor visitor) public override int ChildrenCount => 2; - protected override SyntaxNode GetChildrenImpl(int index) + protected override SyntaxNode GetChildImpl(int index) { return index == 0 ? (SyntaxNode)KeyValues : Tables; } diff --git a/src/Tomlyn/Syntax/DottedKeyItemSyntax.cs b/src/Tomlyn/Syntax/DottedKeyItemSyntax.cs index 2489701..7289c68 100644 --- a/src/Tomlyn/Syntax/DottedKeyItemSyntax.cs +++ b/src/Tomlyn/Syntax/DottedKeyItemSyntax.cs @@ -56,7 +56,7 @@ public override void Accept(SyntaxVisitor visitor) public override int ChildrenCount => 2; - protected override SyntaxNode? GetChildrenImpl(int index) + protected override SyntaxNode? GetChildImpl(int index) { return index == 0 ? (SyntaxNode?)Dot : Key; } diff --git a/src/Tomlyn/Syntax/FloatValueSyntax.cs b/src/Tomlyn/Syntax/FloatValueSyntax.cs index a49d39f..9936b92 100644 --- a/src/Tomlyn/Syntax/FloatValueSyntax.cs +++ b/src/Tomlyn/Syntax/FloatValueSyntax.cs @@ -69,7 +69,7 @@ public override void Accept(SyntaxVisitor visitor) public override int ChildrenCount => 1; - protected override SyntaxNode? GetChildrenImpl(int index) + protected override SyntaxNode? GetChildImpl(int index) { return Token; } diff --git a/src/Tomlyn/Syntax/InlineTableItemSyntax.cs b/src/Tomlyn/Syntax/InlineTableItemSyntax.cs index 7891cef..b844b32 100644 --- a/src/Tomlyn/Syntax/InlineTableItemSyntax.cs +++ b/src/Tomlyn/Syntax/InlineTableItemSyntax.cs @@ -54,7 +54,7 @@ public override void Accept(SyntaxVisitor visitor) public override int ChildrenCount => 2; - protected override SyntaxNode? GetChildrenImpl(int index) + protected override SyntaxNode? GetChildImpl(int index) { return index == 0 ? (SyntaxNode?)KeyValue : Comma; } diff --git a/src/Tomlyn/Syntax/InlineTableSyntax.cs b/src/Tomlyn/Syntax/InlineTableSyntax.cs index 28d58bd..852dc6b 100644 --- a/src/Tomlyn/Syntax/InlineTableSyntax.cs +++ b/src/Tomlyn/Syntax/InlineTableSyntax.cs @@ -71,7 +71,7 @@ public override void Accept(SyntaxVisitor visitor) public override int ChildrenCount => 3; - protected override SyntaxNode? GetChildrenImpl(int index) + protected override SyntaxNode? GetChildImpl(int index) { switch (index) { diff --git a/src/Tomlyn/Syntax/IntegerValueSyntax.cs b/src/Tomlyn/Syntax/IntegerValueSyntax.cs index 2533f52..2565181 100644 --- a/src/Tomlyn/Syntax/IntegerValueSyntax.cs +++ b/src/Tomlyn/Syntax/IntegerValueSyntax.cs @@ -49,7 +49,7 @@ public override void Accept(SyntaxVisitor visitor) } public override int ChildrenCount => 1; - protected override SyntaxNode? GetChildrenImpl(int index) + protected override SyntaxNode? GetChildImpl(int index) { return Token; } diff --git a/src/Tomlyn/Syntax/KeySyntax.cs b/src/Tomlyn/Syntax/KeySyntax.cs index 68f23b2..b43286e 100644 --- a/src/Tomlyn/Syntax/KeySyntax.cs +++ b/src/Tomlyn/Syntax/KeySyntax.cs @@ -63,7 +63,7 @@ public override void Accept(SyntaxVisitor visitor) public override int ChildrenCount => 2; - protected override SyntaxNode? GetChildrenImpl(int index) + protected override SyntaxNode? GetChildImpl(int index) { if (index == 0) return Key; return DotKeys; diff --git a/src/Tomlyn/Syntax/KeyValueSyntax.cs b/src/Tomlyn/Syntax/KeyValueSyntax.cs index ac65c98..a23442e 100644 --- a/src/Tomlyn/Syntax/KeyValueSyntax.cs +++ b/src/Tomlyn/Syntax/KeyValueSyntax.cs @@ -97,7 +97,7 @@ public override void Accept(SyntaxVisitor visitor) visitor.Visit(this); } - protected override SyntaxNode? GetChildrenImpl(int index) + protected override SyntaxNode? GetChildImpl(int index) { switch (index) { diff --git a/src/Tomlyn/Syntax/StringValueSyntax.cs b/src/Tomlyn/Syntax/StringValueSyntax.cs index f181d14..2fce596 100644 --- a/src/Tomlyn/Syntax/StringValueSyntax.cs +++ b/src/Tomlyn/Syntax/StringValueSyntax.cs @@ -52,7 +52,7 @@ public override void Accept(SyntaxVisitor visitor) public override int ChildrenCount => 1; - protected override SyntaxNode? GetChildrenImpl(int index) + protected override SyntaxNode? GetChildImpl(int index) { return Token; } diff --git a/src/Tomlyn/Syntax/SyntaxList.cs b/src/Tomlyn/Syntax/SyntaxList.cs index 4814fcc..e739946 100644 --- a/src/Tomlyn/Syntax/SyntaxList.cs +++ b/src/Tomlyn/Syntax/SyntaxList.cs @@ -22,7 +22,7 @@ internal SyntaxList() : base(SyntaxKind.List) public sealed override int ChildrenCount => Children.Count; - protected override SyntaxNode GetChildrenImpl(int index) + protected override SyntaxNode GetChildImpl(int index) { return Children[index]; } @@ -58,12 +58,12 @@ public void Add(TSyntaxNode node) node.Parent = this; } - public new TSyntaxNode? GetChildren(int index) + public new TSyntaxNode? GetChild(int index) { - return (TSyntaxNode?)base.GetChildren(index); + return (TSyntaxNode?)base.GetChild(index); } - protected override SyntaxNode GetChildrenImpl(int index) + protected override SyntaxNode GetChildImpl(int index) { return Children[index]; } @@ -72,7 +72,7 @@ protected override SyntaxNode GetChildrenImpl(int index) /// Removes a node at the specified index. /// /// Index of the node to remove - public void RemoveChildrenAt(int index) + public void RemoveChildAt(int index) { var node = Children[index]; Children.RemoveAt(index); @@ -83,7 +83,7 @@ public void RemoveChildrenAt(int index) /// Removes the specified node instance. /// /// Node instance to remove - public void RemoveChildren(TSyntaxNode node) + public void RemoveChild(TSyntaxNode node) { if (node == null) throw new ArgumentNullException(nameof(node)); if (node.Parent != this) throw new InvalidOperationException("The node is not part of this list"); diff --git a/src/Tomlyn/Syntax/SyntaxNode.cs b/src/Tomlyn/Syntax/SyntaxNode.cs index eb5e52f..1a22d20 100644 --- a/src/Tomlyn/Syntax/SyntaxNode.cs +++ b/src/Tomlyn/Syntax/SyntaxNode.cs @@ -3,6 +3,7 @@ // See license.txt file in the project root for full license information. using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using Tomlyn.Helpers; @@ -34,30 +35,30 @@ protected SyntaxNode(SyntaxKind kind) public List? TrailingTrivia { get; set; } /// - /// Gets the number of children + /// Gets the number of children. /// public abstract int ChildrenCount { get; } /// - /// Gets a children at the specified index. + /// Gets a child at the specified index. /// - /// Index of the children - /// A children at the specified index - public SyntaxNode? GetChildren(int index) + /// Index of the child + /// A child at the specified index + public SyntaxNode? GetChild(int index) { if (index < 0) throw ThrowHelper.GetIndexNegativeArgumentOutOfRangeException(); if (index > ChildrenCount) throw ThrowHelper.GetIndexArgumentOutOfRangeException(ChildrenCount); - return GetChildrenImpl(index); + return GetChildImpl(index); } /// - /// Gets a children at the specified index. + /// Gets a child at the specified index. /// - /// Index of the children - /// A children at the specified index + /// Index of the child + /// A child at the specified index /// The index is safe to use - protected abstract SyntaxNode? GetChildrenImpl(int index); - + protected abstract SyntaxNode? GetChildImpl(int index); + public override string ToString() { var writer = new StringWriter(); @@ -87,7 +88,7 @@ private void WriteToInternal(TextWriter writer) int count = ChildrenCount; for (int i = 0; i < count; i++) { - var child = GetChildren(i); + var child = GetChild(i); if (child == null) continue; child.WriteToInternal(writer); } diff --git a/src/Tomlyn/Syntax/SyntaxToken.cs b/src/Tomlyn/Syntax/SyntaxToken.cs index 5f1d20f..76e2ed0 100644 --- a/src/Tomlyn/Syntax/SyntaxToken.cs +++ b/src/Tomlyn/Syntax/SyntaxToken.cs @@ -43,7 +43,7 @@ public override void Accept(SyntaxVisitor visitor) public override int ChildrenCount => 0; - protected override SyntaxNode? GetChildrenImpl(int index) + protected override SyntaxNode? GetChildImpl(int index) { return null; } diff --git a/src/Tomlyn/Syntax/SyntaxValidator.cs b/src/Tomlyn/Syntax/SyntaxValidator.cs index 4aab723..994ec41 100644 --- a/src/Tomlyn/Syntax/SyntaxValidator.cs +++ b/src/Tomlyn/Syntax/SyntaxValidator.cs @@ -229,7 +229,7 @@ private bool KeyNameToObjectPath(KeySyntax key, ObjectKind kind, bool fromDotted for (int i = 0; i < items.ChildrenCount; i++) { AddObjectPath(key, kind, true, fromDottedKeys); - var dotItem = GetStringFromBasic(items.GetChildren(i)!.Key!)!; + var dotItem = GetStringFromBasic(items.GetChild(i)!.Key!)!; if (string.IsNullOrWhiteSpace(dotItem)) return false; _currentPath.Add(dotItem); } @@ -313,7 +313,7 @@ public override void Visit(ArraySyntax array) SyntaxKind firstKind = default; for(int i = 0; i < items.ChildrenCount; i++) { - var item = items.GetChildren(i)!; + var item = items.GetChild(i)!; var value = item.Value!; if (i == 0) { diff --git a/src/Tomlyn/Syntax/SyntaxVisitor.cs b/src/Tomlyn/Syntax/SyntaxVisitor.cs index 56b2580..e387593 100644 --- a/src/Tomlyn/Syntax/SyntaxVisitor.cs +++ b/src/Tomlyn/Syntax/SyntaxVisitor.cs @@ -94,7 +94,7 @@ public virtual void DefaultVisit(SyntaxNode? node) for (int i = 0; i < node.ChildrenCount; i++) { - var child = node.GetChildren(i); + var child = node.GetChild(i); if (child != null) { child.Accept(this); diff --git a/src/Tomlyn/Syntax/TableSyntaxBase.cs b/src/Tomlyn/Syntax/TableSyntaxBase.cs index 5a3746d..2ddbc40 100644 --- a/src/Tomlyn/Syntax/TableSyntaxBase.cs +++ b/src/Tomlyn/Syntax/TableSyntaxBase.cs @@ -1,6 +1,10 @@ // Copyright (c) Alexandre Mutel. All rights reserved. // Licensed under the BSD-Clause 2 license. // See license.txt file in the project root for full license information. + +using Tomlyn.Helpers; +using Tomlyn.Model; + namespace Tomlyn.Syntax { /// @@ -65,7 +69,7 @@ public SyntaxToken? EndOfLineToken internal abstract TokenKind CloseTokenKind { get; } - protected override SyntaxNode? GetChildrenImpl(int index) + protected override SyntaxNode? GetChildImpl(int index) { switch (index) {