Force PsiElement reparsing Follow
Hi
Is there an OpenAPI way to force IDEA to reparse a PsiElement, e.g. a PsiMethod? My search efforts to answer this question have been unsuccessful.
The reason I'm asking is that after adding a PsiDocComment to a PsiMethod, method.getDocComment() still returns null until the file gets modified through typing a character or something like that.
Looking forward to any hints on this!
etienne
Please sign in to leave a comment.
method.getManager().getCodeStyleManager().reformat(method) will cause the reparsing you need (as well as reformatting the method).
--Dave Griffith
Thanks, Dave. I'm already doing the reformat on the method but it's not having any effect since the method does not know of the javadoc, yet. Even after applying the reformat, the method does not know of the javadoc, as can be reproduced with the code below:
Only after manually "touching" the class does the method learn about its javadoc.
Any help on how I can force the method to learn about the javadoc would be much appreciated. Or maybe there is a better way to add the method javadoc without running into the problem described above.
etienne
This sounds like a bug. You should file a request on it. The only reason
you might want to reparse psi is a document change.
Hello etienne,
I think the way you're adding the javadoc is not quite correct. I've experienced
this myself already as well. You should not add the javadoc to the class, but to
the method instead. This is a little simplified example that works for me:
public void createMethodWithDoc(PsiClass clazz, String name, String type, String
doc) throws IncorrectOperationException
{
final PsiManager mgr = clazz.getManager();
final PsiElementFactory ef = mgr.getElementFactory();
final PsiMethod psiMethod = ef.createMethodFromText(
"public " + type + " get" + name + "() {\n" + "// ... \n" +
"}", null);
PsiElement element = clazz.add(psiMethod);
element.addBefore(ef.createDocCommentFromText(
"/** " + doc + "\n"
+ "*/\n", element), element.getFirstChild());
mgr.getCodeStyleManager().reformat(element);
}
HTH,
Sascha
Thanks for the hint, Sascha.
It now works fine!
etienne
Hi Mike
Thanks. I just did:
http://www.jetbrains.net/jira/browse/IDEA-6828
etienne