Martinho0330 / javaparser

Automatically exported from code.google.com/p/javaparser
0 stars 0 forks source link

Some comments before pacakge declaration miss #46

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a Java like this:
/*
 * Comment 1
 */

/*
 * Comment 2
 */

/*
 * Comment 3
 */

package net.perfectbug.test;

public class Test {

}
2. Parse it with JavaParser.
3. Use CompilationUnit.toString() to get the parsed source code.

What is the expected output? What do you see instead?
Expected:
All comments should be print.
Observation:
Not comments are print.
And CompilationUnit.comments only contains comment 3. It doesn't contains 
neither comment 1 nor comment 2.

What version of the product are you using? On what operating system?
1.0.8 on Windows XP.

Please provide any additional information below.

Original issue reported on code.google.com by longhua1...@gmail.com on 28 Jun 2011 at 10:26

GoogleCodeExporter commented 9 years ago
The bug is probably in ASTParserTokenManager at line 68,69
only the last comment in special token is added into comments.
This is what I tried to fix (replace line 68-69):
                Token firstToken = null;
                while (special != null) {
                    firstToken = special;
                    special = special.specialToken;
                }
                while (firstToken != null) {
                    BlockComment comment = new BlockComment(firstToken
                            .beginLine, firstToken.beginColumn, firstToken.endLine, firstToken.endColumn, firstToken.image.substring(2, firstToken.image.length()-2));
                    comments.add(comment);
                    firstToken = firstToken.next;
                }

Original comment by lylypp6...@gmail.com on 26 Nov 2014 at 8:31