From a9177f61fe2a4abce8d15435cf5118ee6e1fe454 Mon Sep 17 00:00:00 2001 From: shalousun Date: Tue, 30 Jan 2024 03:10:00 +0800 Subject: [PATCH] Fix the bug that does not allow the use of permits as field names. (#202) --- src/grammar/lexer.flex | 8 ++++- .../com/thoughtworks/qdox/PermitsTest.java | 35 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/thoughtworks/qdox/PermitsTest.java diff --git a/src/grammar/lexer.flex b/src/grammar/lexer.flex index e2fca0a3..a17a69eb 100644 --- a/src/grammar/lexer.flex +++ b/src/grammar/lexer.flex @@ -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; } @@ -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); diff --git a/src/test/java/com/thoughtworks/qdox/PermitsTest.java b/src/test/java/com/thoughtworks/qdox/PermitsTest.java new file mode 100644 index 00000000..4384fb99 --- /dev/null +++ b/src/test/java/com/thoughtworks/qdox/PermitsTest.java @@ -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) ); + } +}