Enum problems(2): Adding PsiDocComment to enum PsiClass fails

Hi,

I'm using Intellij 6.0.4 (build 6148). When adding a PsiDocComment to an enum (PsiClass) the docComment field in the PsiClass stays null and the text gets messed up:

Given the following enum class definition:

package p1.p2;

enum Test {
}

Executing the following code where "psiClass" defines the enum above:

PsiElementFactory factory = psiClass.getManager().getElementFactory();
PsiDocComment comment = factory.createDocCommentFromText("/** some text here **/", null);
psiClass.addBefore(comment, psiClass.getFirstChild());

psiClass.getFirstChild() references "PsiModifierList:"
the docComment field in the psiClass stays null.
the parent of the PsiDocComment object suddenly is "PsiMethod:m" which is weird because no method void m(); was defined. Doing a getAllMethods on the PsiClass shows 24 methods, none of them being void m();

The text also gets mangled and is now:

package p1.p2;

enum Test {
; /** some text here **/
}

instead of:

package p1.p2;

/** some text here **/
enum Test {
}

Is this a bug in IntelliJ or am I doing something wrong here? This code works perfectly for interfaces, classes, ethods and fields.

Thanks in advance,

Raymond Brandon

4 comments
Comment actions Permalink

You should refer to doc comment returned by addBefore(), the element you created from factory remains nonphysical, i.e. it is not attached to psiClass.

0
Comment actions Permalink

Hi Eugene,

The addBefore method returns the PsiDocComment that was added. When verifying that it's parent actuall contains the newly added DocComment, it fails:

anchor = destination.addBefore(psiDocComment, firstChild);
anchor.getParent() references the Enum class which is correct.

But, ((PsiDocComment)anchor.getParent()).getDocComment() == null

In addition, although the DocComment says that it is linked to the ModifierList, the DocComment text is still shown inside the enum:

enum Test {
; /** some text here **/
}

Can you give me some more information on what I'm doing wrong and how it should work according to you?

Thanks,

Raymond

0
Comment actions Permalink

Can I please get some help on this one?

It's been posted already two months ago and still no answer...

Thanks

Raymond

0
Comment actions Permalink

For those who are still search for a solution just use the ASTNode instead of PsiElement:

psiClass.getNode().addChild(comment.getNode(), psiClass.getFirstChild().getNode());

instead of your code:

psiClass.addBefore(comment, psiClass.getFirstChild());

Thanks,
Sergey.

0

Please sign in to leave a comment.