Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Compilers/CSharp/Portable/Syntax/SyntaxReplacer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ private static InvalidOperationException GetItemNotListElementException()
return new InvalidOperationException(CodeAnalysisResources.MissingListItem);
}

private static InvalidOperationException GetTokenNotListElementException()
{
return new InvalidOperationException(CodeAnalysisResources.MissingTokenListItem);
}

private abstract class BaseListEditor : CSharpSyntaxRewriter
{
private readonly TextSpan _elementSpan;
Expand Down Expand Up @@ -504,7 +509,7 @@ public override SyntaxToken VisitToken(SyntaxToken token)
{
if (token == _originalToken)
{
throw GetItemNotListElementException();
throw GetTokenNotListElementException();
}

return base.VisitToken(token);
Expand Down
3 changes: 3 additions & 0 deletions src/Compilers/Core/Portable/CodeAnalysisResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@
<data name="MissingListItem" xml:space="preserve">
<value>The item specified is not the element of a list.</value>
</data>
<data name="MissingTokenListItem" xml:space="preserve">
<value>The specified token must be a direct element of a SyntaxTokenList (such as a modifier in a list of modifiers). The token cannot be an arbitrary token from the syntax tree.</value>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot This is not ok. THis error is also used when a node is not found that needs to be in a list, not just a token. We'll need two errors. Keep the original one, and add a new MissingTokenListItem. Then update SyntaxReplacer.VisitToken to throw the new message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I've kept the original MissingListItem error and added a new MissingTokenListItem error. Updated both C# and VB TokenListEditor.VisitToken methods to use the new error message. Commit: 3b60862 (will be updated in next push)

</data>
<data name="InvalidPublicKey" xml:space="preserve">
<value>Invalid public key.</value>
</data>
Expand Down
17 changes: 14 additions & 3 deletions src/Compilers/Core/Portable/Syntax/SyntaxNodeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,11 @@ public static TRoot InsertNodesAfter<TRoot>(this TRoot root, SyntaxNode nodeInLi
/// </summary>
/// <typeparam name="TRoot">The type of the root node.</typeparam>
/// <param name="root">The root of the tree of nodes.</param>
/// <param name="tokenInList">The token to be replaced; a descendant of the root node and an element of a list member.</param>
/// <param name="tokenInList">The token to be replaced. This must be a direct element of a <see cref="SyntaxTokenList"/>
/// (such as a modifier in a list of modifiers), and a descendant of the root node.
/// If the token is not part of a <see cref="SyntaxTokenList"/>, an <see cref="InvalidOperationException"/> will be thrown.</param>
/// <param name="newTokens">A sequence of tokens to use in the tree in place of the specified token.</param>
/// <exception cref="InvalidOperationException">Thrown when <paramref name="tokenInList"/> is not an element of a <see cref="SyntaxTokenList"/>.</exception>
public static TRoot ReplaceToken<TRoot>(this TRoot root, SyntaxToken tokenInList, IEnumerable<SyntaxToken> newTokens)
where TRoot : SyntaxNode
{
Expand All @@ -135,8 +138,12 @@ public static TRoot ReplaceToken<TRoot>(this TRoot root, SyntaxToken tokenInList
/// </summary>
/// <typeparam name="TRoot">The type of the root node.</typeparam>
/// <param name="root">The root of the tree of nodes.</param>
/// <param name="tokenInList">The token to insert before; a descendant of the root node and an element of a list member.</param>
/// <param name="tokenInList">The token to insert before. This must be a direct element of a <see cref="SyntaxTokenList"/>
/// (such as a modifier in a list of modifiers), and a descendant of the root node. The new tokens will be inserted
/// before this token in that list. If the token is not part of a <see cref="SyntaxTokenList"/>,
/// an <see cref="InvalidOperationException"/> will be thrown.</param>
/// <param name="newTokens">A sequence of tokens to insert into the tree immediately before the specified token.</param>
/// <exception cref="InvalidOperationException">Thrown when <paramref name="tokenInList"/> is not an element of a <see cref="SyntaxTokenList"/>.</exception>
public static TRoot InsertTokensBefore<TRoot>(this TRoot root, SyntaxToken tokenInList, IEnumerable<SyntaxToken> newTokens)
where TRoot : SyntaxNode
{
Expand All @@ -148,8 +155,12 @@ public static TRoot InsertTokensBefore<TRoot>(this TRoot root, SyntaxToken token
/// </summary>
/// <typeparam name="TRoot">The type of the root node.</typeparam>
/// <param name="root">The root of the tree of nodes.</param>
/// <param name="tokenInList">The token to insert after; a descendant of the root node and an element of a list member.</param>
/// <param name="tokenInList">The token to insert after. This must be a direct element of a <see cref="SyntaxTokenList"/>
/// (such as a modifier in a list of modifiers), and a descendant of the root node. The new tokens will be inserted
/// after this token in that list. If the token is not part of a <see cref="SyntaxTokenList"/>,
/// an <see cref="InvalidOperationException"/> will be thrown.</param>
/// <param name="newTokens">A sequence of tokens to insert into the tree immediately after the specified token.</param>
/// <exception cref="InvalidOperationException">Thrown when <paramref name="tokenInList"/> is not an element of a <see cref="SyntaxTokenList"/>.</exception>
public static TRoot InsertTokensAfter<TRoot>(this TRoot root, SyntaxToken tokenInList, IEnumerable<SyntaxToken> newTokens)
where TRoot : SyntaxNode
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading