Not able to specifically traverse through the syntax tree?

Jerric Lyns John

I'm trying to implement a Diagnostic Analyzer for Collection initializer and its corresponding Code Fix provider.

Wrong Code:

var sampleList= new List<string>();
sampleList.Add("");
sampleList.Add("");

After CodeFix:

var sampleList= new List<string>(){"", ""};

But I'm stuck at this problem that once I get a node for LocalDeclarationStatement, I'm not aware if there exists a way to get the very next adjacent node from the parent.

Syntax Tree

In the above Picture I require both the ExpressionStatement after analyzing the LocalDeclarationStatement

REQUIREMENT for analyzer

  1. Identify the LocalDeclarationStatement, a collection that is already initialized but doesnt contain CollectionInitializerExpression
  2. Find if the very next line has an Expression statement that is using Add method on the same collection

REQUIREMENT for Code fix

  1. Provide Collection initializer syntax for the adjacent Expression statements that are using Add method on the collection
  2. All other intermitten usage of Add method on the collection has to be avoided.
Jason Malinowski

You can do something like:

var declarationStatement = ...;
var block = (BlockSyntax)declarationStatement.Parent;
var index = block.Statements.IndexOf(declarationStatement);
var nextStatement = block.Statements[index + 1];

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to traverse typed abstract syntax tree in OCaml compiler

From Dev

How do I traverse through model relationships in laravel with dot syntax

From Dev

Traverse through JSON tree and manipulate its data/structure

From Dev

What makes JSON or YAML syntax able to be sent "through the wire"?

From Dev

Traverse the tree with Capybara

From Dev

how to traverse this tree?

From Dev

Traverse tree in a functional way

From Dev

Haskell Tree Traverse Confused

From Dev

How to traverse a Huffman tree?

From Dev

Haskell Tree Traverse Confused

From Dev

Not able to understand the syntax href =\"\

From Dev

Newly added element can't traverse up through its ancestors in the DOM tree using jQuery API closest(), returning "undefined"

From Dev

How to Traverse an NLTK Tree object?

From Dev

Traverse a tree represented by its edges

From Dev

Use foldl to traverse a Tree in Haskell

From Dev

Traverse an expression tree and extract parameters

From Dev

Number Of Ways To Traverse a Binary Tree

From Dev

arangodb traverse tree including edges

From Dev

Traverse recursive json tree and merge

From Dev

Use foldl to traverse a Tree in Haskell

From Dev

arangodb traverse tree including edges

From Dev

Traverse recursive json tree and merge

From Dev

Iterate over and traverse DOM tree

From Dev

Traverse a Spaghetti Stack and reverse to a tree

From Dev

not able to loop through an object

From Dev

Why I'm able to traverse these folders?

From Dev

For Each Function, to loop through specifically named worksheets

From Dev

Go, Golang : traverse through struct

From Dev

traverse through elements returned by getElementsByClassName

Related Related

HotTag

Archive