Skip to content

Commit

Permalink
Rename SyntaxNode.GetChildren to GetChild
Browse files Browse the repository at this point in the history
  • Loading branch information
xoofx committed Jan 25, 2022
1 parent 014e186 commit 2ea2d1c
Show file tree
Hide file tree
Showing 22 changed files with 50 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/Tomlyn.Tests/SyntaxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions src/Tomlyn/Model/SyntaxToModelTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Tomlyn/Syntax/ArrayItemSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tomlyn/Syntax/ArraySyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Tomlyn/Syntax/BareKeySyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tomlyn/Syntax/BooleanValueSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tomlyn/Syntax/DateTimeValueSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tomlyn/Syntax/DocumentSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tomlyn/Syntax/DottedKeyItemSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tomlyn/Syntax/FloatValueSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tomlyn/Syntax/InlineTableItemSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tomlyn/Syntax/InlineTableSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Tomlyn/Syntax/IntegerValueSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tomlyn/Syntax/KeySyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Tomlyn/Syntax/KeyValueSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Tomlyn/Syntax/StringValueSyntax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions src/Tomlyn/Syntax/SyntaxList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down Expand Up @@ -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];
}
Expand All @@ -72,7 +72,7 @@ protected override SyntaxNode GetChildrenImpl(int index)
/// Removes a node at the specified index.
/// </summary>
/// <param name="index">Index of the node to remove</param>
public void RemoveChildrenAt(int index)
public void RemoveChildAt(int index)
{
var node = Children[index];
Children.RemoveAt(index);
Expand All @@ -83,7 +83,7 @@ public void RemoveChildrenAt(int index)
/// Removes the specified node instance.
/// </summary>
/// <param name="node">Node instance to remove</param>
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");
Expand Down
25 changes: 13 additions & 12 deletions src/Tomlyn/Syntax/SyntaxNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -34,30 +35,30 @@ protected SyntaxNode(SyntaxKind kind)
public List<SyntaxTrivia>? TrailingTrivia { get; set; }

/// <summary>
/// Gets the number of children
/// Gets the number of children.
/// </summary>
public abstract int ChildrenCount { get; }

/// <summary>
/// Gets a children at the specified index.
/// Gets a child at the specified index.
/// </summary>
/// <param name="index">Index of the children</param>
/// <returns>A children at the specified index</returns>
public SyntaxNode? GetChildren(int index)
/// <param name="index">Index of the child</param>
/// <returns>A child at the specified index</returns>
public SyntaxNode? GetChild(int index)
{
if (index < 0) throw ThrowHelper.GetIndexNegativeArgumentOutOfRangeException();
if (index > ChildrenCount) throw ThrowHelper.GetIndexArgumentOutOfRangeException(ChildrenCount);
return GetChildrenImpl(index);
return GetChildImpl(index);
}

/// <summary>
/// Gets a children at the specified index.
/// Gets a child at the specified index.
/// </summary>
/// <param name="index">Index of the children</param>
/// <returns>A children at the specified index</returns>
/// <param name="index">Index of the child</param>
/// <returns>A child at the specified index</returns>
/// <remarks>The index is safe to use</remarks>
protected abstract SyntaxNode? GetChildrenImpl(int index);

protected abstract SyntaxNode? GetChildImpl(int index);
public override string ToString()
{
var writer = new StringWriter();
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tomlyn/Syntax/SyntaxToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Tomlyn/Syntax/SyntaxValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Tomlyn/Syntax/SyntaxVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion src/Tomlyn/Syntax/TableSyntaxBase.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 2ea2d1c

Please sign in to comment.