Add new property to java class

Answered

How can i add a new field property on a java class?  I have a PsiClass and i want to add a new property :

CompositeDisposable compositeDisposable = new CompositeDisposable();

I have read the documentation but i cant find something usefull of how to modify a class and add properties or methods.

0
4 comments

Theodosios,

You can try using GenerateMembersUtil to insert members at the specific offset.

0
Avatar
Permanently deleted user

Thx for the fast reply. How i can find the offset of the other properties? I want to add my new property in the beggining and not where the cursor is.

0

It's not about the position of cursor but in general position in the file that you have to specify manually.

You should find the proper location on your own, i.e. finding the beginning of your class body. 

0
Avatar
Permanently deleted user

Thank you a lot again for the answer. I made it work. I can use GenerateMembersUtil also to generate methods inside a class?

0

Please sign in to leave a comment.