Synchronizing editor/repository after psi changes

My plugin does some code modifications (in effect converting from a custom logging solution to log4j).
It more or less works, but there is a little issue:
I call replace() on a PsiMethodCallExpression. After that the file is marked red in the editor, though it still compiles fine.
When loading the project for the next time I get this exception:

2005-02-17 13:32:38,156 ERROR - impl.RepositoryElementsManager - Error synchronizing psi and repository in file: C:\Stephen\idea-sandbox\projects\logtest\src\ repositoryElementType: FIELD psiParent: PsiClass:Baa
java.lang.ArrayIndexOutOfBoundsException: 0

I guess I am missing something very basic here, like having to call some kind of commmit/update/synchronize method?!

Comment actions Permalink

Call CodeStyleManager.reformat() on the replaced expression. Here's the code from InspectionGadgets that does what you're describing.

It probably all has to be wrapped as a write action (not sure, as the inspection API handles all that for me), but otherwise the above should just work.

--Dave Griffith

Comment actions Permalink

Thanks a lot Dave, that did the trick (and I am feeling a little less stupid, because the solution does not seem obvious to me).

And sorry for posting in the wrong forum - I noticed too late that this should be in the OpenAPI forum. Hope my post will just get ignored there.


Please sign in to leave a comment.