QDox

ParseException for private static String[] allConstants = {C1,C2,C3};

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.8
  • Component/s: Parser
  • Labels:
    None
  • Number of attachments :
    3

Description

The following file:
class T {
final public static String C1="C1",C2="C2";
final public static String[] ALL = {C1,C2};
}
is not parsed properly:
com.thoughtworks.qdox.parser.ParseException: syntax error @[3,42] in file:T.java

  1. Qdox-131.patch
    14/Jan/09 12:34 PM
    2 kB
    Robert Scholte
  2. T.java
    18/Oct/07 8:37 AM
    0.1 kB
    alex322
  3. TestQDoxBug131.java
    27/Dec/08 4:44 PM
    1 kB
    Daniel Brolund

Activity

Hide
Dennis Lundberg added a comment -

I'm unable to reproduce a parsing error with the attached file.

Show
Dennis Lundberg added a comment - I'm unable to reproduce a parsing error with the attached file.
Hide
Daniel Brolund added a comment -

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());

}
}

Show
Daniel Brolund added a comment - 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()); } }
Hide
Daniel Brolund added a comment -

Testfile for bug described

Show
Daniel Brolund added a comment - Testfile for bug described
Hide
Daniel Brolund added a comment -

I attached file TestQDoxBug131.java since the code got whitespace-trimmed.

Show
Daniel Brolund added a comment - I attached file TestQDoxBug131.java since the code got whitespace-trimmed.
Hide
Robert Scholte added a comment -

The javadoc isn't clear in what to expect when calling getSourceCode(). In this case it's the code between the method-brackets. I don't know if it's valid to expect the comments to be filtered out. Bug or feature-request?

Show
Robert Scholte added a comment - The javadoc isn't clear in what to expect when calling getSourceCode(). In this case it's the code between the method-brackets. I don't know if it's valid to expect the comments to be filtered out. Bug or feature-request?
Hide
Daniel Brolund added a comment -

Hi Robert,

The example is a bit cluttered but if you run the attached test and check the difference between the expected and the actual in an IDE I think it will be clearer what I mean.

This bug is that the comments BEFORE the method is included in the source of the method, but only for the first method of a class, and only if there is a declaration like C1 or ALL as above.

(The comments within a method should, as you state, be returned as part of the source code for that method.)

Cheers
Daniel

Show
Daniel Brolund added a comment - Hi Robert, The example is a bit cluttered but if you run the attached test and check the difference between the expected and the actual in an IDE I think it will be clearer what I mean. This bug is that the comments BEFORE the method is included in the source of the method, but only for the first method of a class, and only if there is a declaration like C1 or ALL as above. (The comments within a method should, as you state, be returned as part of the source code for that method.) Cheers Daniel
Hide
Robert Scholte added a comment -

Hi Daniel,

thanks for explaining, the problem is clear to me. And it's not that hard to spot the cause of this problem. There's no trigger to start a new codeBody (or end the old one). It's a lexer-problem and should be solvable. Maybe I'll have another look next week.

Show
Robert Scholte added a comment - Hi Daniel, thanks for explaining, the problem is clear to me. And it's not that hard to spot the cause of this problem. There's no trigger to start a new codeBody (or end the old one). It's a lexer-problem and should be solvable. Maybe I'll have another look next week.
Hide
Robert Scholte added a comment -

patch attached with a test and the fix. Now when starting a new codeblock, it'll be reset first.

Show
Robert Scholte added a comment - patch attached with a test and the fix. Now when starting a new codeblock, it'll be reset first.
Hide
Daniel Brolund added a comment -

Great! Any chance of knowing when it is in a build/release on the maven site?

Show
Daniel Brolund added a comment - Great! Any chance of knowing when it is in a build/release on the maven site?
Hide
Robert Scholte added a comment -

patch applied

Show
Robert Scholte added a comment - patch applied

People

  • Assignee:
    Unassigned
    Reporter:
    alex322
Vote (4)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: