How to copy PSI tree without reparsing with PsiElementFactory

I want to convert part of a PSI tree, but not modify its children. (Specifically
I don't want to lose userData.)

I see that InspectionGadgets quick fixes use PsiElementFactory with getText()
to re-create statements by converting them to text and re-parsing them, for
example when converting foreach statement to for statement.

It seems that there must be a better way - could I copy() the children I
want to re-use?

Thanks,
-Keith


3 comments
Comment actions Permalink

Quite right, PsiElement.copy() should probably be used apart from situations
when certain modification is easier to be done on text rather PSI structures.
-


Maxim Shafirov
http://www.jetbrains.com
"Develop with pleasure!"

I want to convert part of a PSI tree, but not modify its children.
(Specifically I don't want to lose userData.)

I see that InspectionGadgets quick fixes use PsiElementFactory with
getText() to re-create statements by converting them to text and
re-parsing them, for example when converting foreach statement to for
statement.

It seems that there must be a better way - could I copy() the children
I want to re-use?

Thanks,
-Keith



0
Comment actions Permalink


Ya know, this is the sort of thing we actually could use documentation for...

--Dave Griffith

0
Comment actions Permalink

I think we all want more OpenAPI Javadoc. I was thinking about something
that I think would help us all in that regard. A special web form could be
put up (maybe one of us plugin developers could make it, to make it easy
for JB). Us plugin developers could ask questions by posting with the form.

Then, JB developers would be given access to the list of questions. They
would be shown a form where they can post an answer to the question. However,
the only fields in the answer form would be "build #" and "classes / members"
which would be something like "3330" and "CodeStyleManager.suggestUniqueVariableName,"
respectively. Such a response would mean "Documentation for this is provided
in suggestUniqueVariableName Javadoc as of build 3330."

I feel that this might encourage JB developers to write Javadoc instead of
answering questions on the forums and only helping the few people who read
it.

This is kind of a silly proposal. JetBrains, what could we do to encourage
you to write Javadoc for OpenAPI?

Another idea I have is to write an IDEA plugin. It augments Quick Javadoc
with buttons "View comments" and "Add comment" which would access some website
(hosted by JB or a community member) which had some web service set up for
such functionality.

This kind of thing is used on PHP and MySQL documentation pages and it can
be helpful. However I think signal to noise would be better in PSI API than
MySQL because we have so few developers and you can't have questions about
PSI API without knowing something about it.

Ya know, this is the sort of thing we actually could use documentation
for...

--Dave Griffith




0

Please sign in to leave a comment.