How to add a PsiComment
Yikes, overlooking something simple I suppose. Trying to add a comment followed by a field. The field adds OK but the comment refuses. Tried several variations on the last line to no effect.
field = factory.createField(CLASSES, classType.createArrayType());
field.getModifierList().setModifierProperty("static", true);
field.getModifierList().setModifierProperty("final", true);
pdb.add(field);
PsiComment comment = factory.createCommentFromText("// yada yada ", null);
pdb.addBefore(comment, field);
Please sign in to leave a comment.
The only idea that comes to my mind is that you probably add the comment to the wrong parent. Use PsiViewer to see the actual structure of PSI.
Yep ;)
This should work:
PsiElement anchor = pdb.add(field);
PsiComment comment = factory.createCommentFromText("// yada yada ", null);
pdb.addBefore(comment, anchor);
That worked! Thanks.