The PsiExpressionList class, as I understand it, keeps a list of PSI expressions. How am I using PsiExpressionList incorrectly?
I am trying to keep track of a set of statements that I will replace with a for loop that has those same statements inside its code block (codeBlock) by eventually calling toReplace.replace(forLoop); after I have built up my toReplace list as well as the codeBlock for the for loop and put it into forLoop.
I am able to insert expressionStatement (which is a PsiExpressionStatement) into the code block just fine using my helper method insertExpressionIntoCodeBlock, but when I try to insert expressionStatement to the PsiExpressionList toReplace using the built-in add function, it fails.
// List of lines of code to replace
PsiExpressionList toReplace = new PsiExpressionListImpl();
// Insert the expression statement (line) into the code block
PsiElement codeBlock = factory.createCodeBlock();
// Add the expression statement (line) to the list of replace-ables
From the last line in this code snippet (line 101 in my code -- ConvertElementToCollection.java), I am getting a couple of errors including an Illegal argument exception. I have attached my stack trace, as well as photos of the debugger info for toReplace and expressionStatement right before the crash.