Skip to content

Commit

Permalink
Fix the bug that does not allow the use of permits as field names. (#202
Browse files Browse the repository at this point in the history
)
  • Loading branch information
shalousun authored Jan 29, 2024
1 parent 54b0534 commit a9177f6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/grammar/lexer.flex
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ JavadocEnd = "*"+ "/"
"new" { return Parser.NEW; }
"sealed" { return Parser.SEALED; }
"non-sealed" { return Parser.NON_SEALED; }
"permits" { return Parser.PERMITS; }

"[" { nestingDepth++; return Parser.SQUAREOPEN; }
"]" { nestingDepth--; return Parser.SQUARECLOSE; }
Expand Down Expand Up @@ -315,6 +314,13 @@ JavadocEnd = "*"+ "/"
pushState(NAME);
return Parser.RECORD;
}
"permits" / {WhiteSpace}+ {Id} {
markAnnotatedElementLine();
classDepth++;
braceMode = TYPE;
pushState(NAME);
return Parser.PERMITS;
}
"@" {
markAnnotatedElementLine();
pushState(ATANNOTATION);
Expand Down
35 changes: 35 additions & 0 deletions src/test/java/com/thoughtworks/qdox/PermitsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.thoughtworks.qdox;

import org.junit.jupiter.api.Test;

import java.io.StringReader;

/**
*
* @author shalousun
*/
public class PermitsTest {
@Test
public void permitsAsTypeAndIdentifiers() {
String source = "public class MyPermits {\n" +
"\n" +
" private Object permits;\n" +
"\n" +
" public MyPermits(){}\n" +
"\n" +
" public MyPermits(Object permits) {\n" +
" this.permits = permits;\n" +
" }\n" +
"\n" +
" public Object getPermits() {\n" +
" return permits;\n" +
" }\n" +
"\n" +
" public void setPermits(Object permits) {\n" +
" this.permits = permits;\n" +
" }\n" +
"}";
JavaProjectBuilder javaDocBuilder = new JavaProjectBuilder();
javaDocBuilder.addSource( new StringReader(source) );
}
}

0 comments on commit a9177f6

Please sign in to comment.