Change the modifier of PsiMethod

Answered

How i can change the modifier of existing method?

PsiModifierList modifierLists = psiMethod.getModifierList();
modifierLists.setModifierProperty(PsiModifier.PRIVATE, true);

I can retrieve it but i can not set it back to the method (setter doesnt exist) .

0
2 comments

Theodosios,

First of all, you can use a util method to make it shorter:

PsiUtil.setModifierProperty(psiMethod, PsiModifier.PRIVATE, true);

Can you also explain, what do you mean by setter doesn't exist?

0
Avatar
Permanently deleted user

Thank you it worked. 
I wanted to do something like this: 

psiMethod.setModifierList(modifierList);

But it worked the way you told me. 

0

Please sign in to leave a comment.