tests: reproduce absence of comment in the AST of CtCaseExpression
I was trying to reproduce https://github.com/INRIA/spoon/issues/4727 and I came across another possible bug in the Spoon model builder. It seems that when comments are added to CtCaseExpressions, they are not parsed and stored in the model. Is this a bug or does Spoon has some configuration that I need to enable to include comments in the model? Note that I already set one in my knowledge - launcher.getEnvironment().setCommentEnabled(true);.
This doesn't look specific to case expressions or am I missing something? It seems like the comment isn't attached to the CtLiteral, but I didn't really figure out yet how the JDTCommentBuilder works (or is supposed to work). Adding a
@Override
public <T> void visitCtLiteral(CtLiteral<T> e) {
e.addComment(comment);
}
to this visitor https://github.com/INRIA/spoon/blob/2fff4c50266f79bc06b961e3b01ca6c6e0fcc1ab/src/main/java/spoon/support/compiler/jdt/JDTCommentBuilder.java#L215 seems to do the trick, however I'm not sure if that's an appropriate fix at all (and it prints the comment in front of the literal, but that might be rather a printer issue - I don't now).
This doesn't look specific to case expressions or am I missing something?
I observed it only for literals inside CtCaseExpression, so I did not want to generalise it. The fix you have proposed seems to intimate that this is a general problem for CtLiterals.
however I'm not sure if that's an appropriate fix at all (and it prints the comment in front of the literal, but that might be rather a printer issue - I don't now).
Let's fix the AST in this PR and then we can focus on printing comments.
EDIT:
I tried your fix. There is a very weird side-effect in this test. I will investigate this later.
@SirYwell Can you have a look again? I added your suggested fix which fixes the AST parsing.
Thanks @algomaster99