Javadoc regarding PsiElementFactory's factory methods?

Is there documentation available that details PsiElementFactory's factory methods?
All I have to work with is method names, and I'm having to work out what they do through experimentation.

Any answers appreciated thanks.

Comment actions Permalink

Hi Lucas,

Would you mind sharing your use case perhaps?

As a general overview;
You can access an instance of PsiElementFactory via JavaPsiFacade.getElementFactory(project)
Jetbrains recommend constructing PsiElements from a string, rather than creating PsiElements explicitly yourself.

For instance if you wanting to create a method, you can use

    PsiMethod fooMethod = elementFactory.createMethodFromText("public void foo() { }", psiClass)

Note, it is important to ensure that you have write access when doing this though


Comment actions Permalink

That's right, I've been able to do that.
My use case is that I'm trying to recreate a PsiElement tree from the names of the original PsiElements.

The problem that I have, is that I was creating a Field object and a TypeElement object seperately, before realising that the createField method creates a TypeElement under itself automatically. It would be helpful to have a reference to look at so I had an idea of what each 'create' method did.

Comment actions Permalink

I definitely agreed with you, example usages of a lot of different APIs would be great! Unfortunately I don't think there are the resources available for that just yet
In the mean time I've found that the best thing to do is to simply search Github and see who else is making use of the method you're wanting to learn about :)

On the plus side, if you do find out things which may benefit others, feel free to write up some quick examples which could be added to the confluence documents,
such contributions are always welcome! :)


Please sign in to leave a comment.