deleteing adding PsiElements

Hi

Working with PSI, I want to take a PsiStatement that I get from the current PsiFile and move it somewhere else within that file.

What happens if I append that 'source' statement to some other 'target' statement? Is the 'source' statement automatically removed from the original position in the tree or do I have to make a copy of the original statement, delete the original statement, and then add the copy at the new location?

Or, in other words, is this okay to do without any intermediate copying to move an element from one place to another:

PsiElement srcElement = file.findElementAt(offset);
targetElement.replace(srcElement);

If this is okay, will it still work if srcElement is a (nested) child of targetElement?

Thanks in advance for any clarifications.

--Etienne

1 comment

I think it would be best to copy and delete the old one.

etienne wrote:

Hi

Working with PSI, I want to take a PsiStatement that I get from the current PsiFile and move it somewhere else within that file.

What happens if I append that 'source' statement to some other 'target' statement? Is the 'source' statement automatically removed from the original position in the tree or do I have to make a copy of the original statement, delete the original statement, and then add the copy at the new location?

Or, in other words, is this okay to do without any intermediate copying to move an element from one place to another:

PsiElement srcElement = file.findElementAt(offset);
targetElement.replace(srcElement);

If this is okay, will it still work if srcElement is a (nested) child of targetElement?

Thanks in advance for any clarifications.

--Etienne

0

Please sign in to leave a comment.