The error is a bit more strange nowadays, since the first method of a class includes the comment before it if the constant declarations (above) are present as below:
package com.acme.qdox;
import static org.junit.Assert.assertEquals;
import java.io.StringReader;
import org.junit.Test;
import com.thoughtworks.qdox.JavaDocBuilder;
import com.thoughtworks.qdox.model.JavaClass;
public class TestQDoxBug131 {
@Test
public void commentsBeforeMethodShouldNotAppearInSourceCode() throws Exception {
String sourceCode = "package com.acme.qdox;\n" +
"\n" +
"public class QDoxBugClass {\n" +
" final public static String C1 = \"C1\", C2 = \"C2\";\n" +
" final public static String[] ALL =
{ C1, C2 }
; \n" +
" /*\n" +
" Comment\n" +
" */\n" +
" public void method()
{\n" +
" System.out.println(\"This should not contain the comment\");\n" +
" }
\n" +
"}\n" +
"";
JavaDocBuilder builder = new JavaDocBuilder();
builder.addSource(new StringReader(sourceCode));
JavaClass aClass = builder.getClassByName("com.acme.qdox.QDoxBugClass");
assertEquals("\n System.out.println(\"This should not contain the comment\");\n ",
aClass.getMethods()[0].getSourceCode());
}
}
I'm unable to reproduce a parsing error with the attached file.