Skip to content

Commit

Permalink
paul-hammant#90 Seems QDox 2.0.1 has issue parsing parameter names na…
Browse files Browse the repository at this point in the history
…med "record"
  • Loading branch information
rfscholte committed Jul 24, 2022
1 parent 89461e6 commit c887457
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/grammar/lexer.flex
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ JavadocEnd = "*"+ "/"
<ANNOTATIONNOARG> {
{WhiteSpace} { popState(); }
}
<YYINITIAL, ANNOTATIONNOARG, ANNOTATIONTYPE, ENUM, NAME, RECORD, TYPE> {
<YYINITIAL, ANNOTATIONNOARG, ANNOTATIONTYPE, ENUM, NAME, TYPE> {
"." { return Parser.DOT; }
"..." { return Parser.DOTDOTDOT; }
"," { return Parser.COMMA; }
Expand All @@ -265,7 +265,6 @@ JavadocEnd = "*"+ "/"
"implements" { return Parser.IMPLEMENTS; }
"super" { return Parser.SUPER; }
"new" { return Parser.NEW; }
"record" { return Parser.RECORD; }
"sealed" { return Parser.SEALED; }
"non-sealed" { return Parser.NON_SEALED; }
"permits" { return Parser.PERMITS; }
Expand Down Expand Up @@ -309,6 +308,13 @@ JavadocEnd = "*"+ "/"
pushState(NAME);
return Parser.ENUM;
}
"record" / {WhiteSpace}* {Id} {
markAnnotatedElementLine();
classDepth++;
braceMode = CODEBLOCK;
pushState(NAME);
return Parser.RECORD;
}
"@" {
markAnnotatedElementLine();
pushState(ATANNOTATION);
Expand Down Expand Up @@ -430,7 +436,7 @@ JavadocEnd = "*"+ "/"
}
}
}
<ENUM, RECORD, TYPE> {
<ENUM, TYPE> {
"default" { return Parser.DEFAULT; }
}
<ANNOTATIONTYPE> {
Expand All @@ -441,7 +447,7 @@ JavadocEnd = "*"+ "/"
{Id} / {WhiteSpace}* [;{(] { resetAnnotatedElementLine(); popState(); return Parser.IDENTIFIER; }
{Id} { popState(); return Parser.IDENTIFIER; }
}
<YYINITIAL, ANNOTATIONNOARG, ANNOTATIONTYPE, ENUM, MODULE, RECORD, TYPE> {
<YYINITIAL, ANNOTATIONNOARG, ANNOTATIONTYPE, ENUM, MODULE, TYPE> {
{Id} { return Parser.IDENTIFIER;
}
}
Expand Down Expand Up @@ -657,12 +663,12 @@ JavadocEnd = "*"+ "/"
}
}

<ASSIGNMENT, YYINITIAL, CODEBLOCK, PARENBLOCK, ENUM, ANNOTATIONTYPE, RECORD, TYPE> {
<ASSIGNMENT, YYINITIAL, CODEBLOCK, PARENBLOCK, ENUM, ANNOTATIONTYPE, TYPE> {
"\"" { if (appendingToCodeBody) { codeBody.append('"'); } pushState(STRING); }
\' { if (appendingToCodeBody) { codeBody.append('\''); } pushState(CHAR); }
}

<ASSIGNMENT, YYINITIAL, CODEBLOCK, PARENBLOCK, ENUM, ANNOTATIONTYPE, ANNOTATION, ATANNOTATION, ARGUMENTS, RECORD, TYPE, NAME, MODULE > {
<ASSIGNMENT, YYINITIAL, CODEBLOCK, PARENBLOCK, ENUM, ANNOTATIONTYPE, ANNOTATION, ATANNOTATION, ARGUMENTS, TYPE, NAME, MODULE > {
"//" { if (appendingToCodeBody) { codeBody.append("//"); } pushState(SINGLELINECOMMENT); }
"/*" { if (appendingToCodeBody) { codeBody.append("/*"); } pushState(MULTILINECOMMENT); }
"/**/" { if (appendingToCodeBody) { codeBody.append("/**/"); } }
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/com/thoughtworks/qdox/RecordsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,30 @@ public void withAnnotatedParameters() {
+ " @GreaterThanZero double width) { }";
builder.addSource( new StringReader(source) );
}

@Test
public void withAnnotation() {
String source = "@Deprecated\n"
+ "record Line(int lenght) { }";
builder.addSource( new StringReader(source) );
}


@Test
public void recordAsTypeAndIdentifiers() {
String source = "package record.record.record;\n"
+ "\n"
+ "public class record\n"
+ "{\n"
+ " private Object record;\n"
+ " \n"
+ " public record() {\n"
+ " }\n"
+ " \n"
+ " private Object record(Object record) {\n"
+ " return record;\n"
+ " }\n"
+ "}";
builder.addSource( new StringReader(source) );
}
}

0 comments on commit c887457

Please sign in to comment.