[forge-issues] [JBoss JIRA] (ROASTER-26) Can't add comment in the method body
Jeremie Bresson (JIRA)
issues at jboss.org
Thu Sep 17 00:39:00 EDT 2015
[ https://issues.jboss.org/browse/ROASTER-26?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13109718#comment-13109718 ]
Jeremie Bresson commented on ROASTER-26:
----------------------------------------
If you do:
{code:java}
String stub = "public class Stub {\n //a comment\n public String method() {\n //a comment \n return \"Hello World!\"; \n } }";
JavaClassSource javaClassSource = Roaster.parse(JavaClassSource.class, stub);
System.out.println(javaClassSource.toString());
{code}
The comments are present...
My investigations show that the comment are not directly part of the AST. You can get them in the CompilationUnit:
{code:java}
unit.getCommentList();
{code}
And for each node:
{code:java}
unit.firstLeadingCommentIndex(ASTNode);
unit.lastTrailingCommentIndex(ASTNode);
{code}
In the setBody() use-case (code snippet in the issue), the comment are lost when the AST is copied (in org.jboss.forge.roaster.model.impl.MethodImpl.setBody(String)):
{code:java}
block = (Block) ASTNode.copySubtree(method.getAST(), block);
method.setBody(block);
{code}
I am not sure how this should be handled.
> Can't add comment in the method body
> ------------------------------------
>
> Key: ROASTER-26
> URL: https://issues.jboss.org/browse/ROASTER-26
> Project: Roaster
> Issue Type: Bug
> Components: JDT
> Affects Versions: 2.7.0.Final
> Reporter: Nicolas Challut
> Fix For: 2.x Future
>
>
> If you try to add a comment in a method body, the comment won't be print. Comment are detected like a miswritten code
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
More information about the forge-issues
mailing list