-
Notifications
You must be signed in to change notification settings - Fork 7.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ZOOKEEPER-4880: Generate comments from zookeeper.jute into code. #2206
base: master
Are you sure you want to change the base?
Conversation
f24cad3
to
6365b88
Compare
@kezhuw Could you help me take a look? Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @luozongle01, thank you for your contribution!
Given the fact that jute and all targeting languages support both // and multi-line comments, I suggest we output whatever comments captured in origin sharp. With help of beginLine
, beginColumn
, endLine
and endColumn
of Token
, I think we can reproduce comments in generated code with indentation adjusted.
while (tmpTkn != null) { | ||
String image = tmpTkn.image.trim(); | ||
tmpTkn = tmpTkn.next; | ||
if (image.startsWith("//")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The capture does not shaped well for directly usage. I tasted the following capture, and it captured a complete line comment. This way we can output whatever it captured without post work.
SPECIAL_TOKEN :
{
<SINGLE_LINE_COMMENT: "//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")>
}
See also https://javacc.github.io/javacc/tutorials/token-manager.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for your comment. I will make some further modifications.😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The capture does not shaped well for directly usage. I tasted the following capture, and it captured a complete line comment. This way we can output whatever it captured without post work.
SPECIAL_TOKEN : { <SINGLE_LINE_COMMENT: "//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")> }
See also https://javacc.github.io/javacc/tutorials/token-manager.html
It seems like there's no need to change this now, because I get all the comments,then I use and distinguished them by line numbe. 😂😂
52d4194
to
0631b4f
Compare
Hi, @kezhuw, I made some modifications, thank you for your review last time. I feel much better now than last time. Currently, multi-line comments and single-line comments are supported. I put Here is my testing process.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@luozongle01 Thank you for your work!
It might be late, I am sorry for this, but I think we probably should align on how comments from jute should be formatted in generated sources ? I see two approaches.
- Keep it in origin format.
- Transfer comments from one format to another.
I saw this pr is going on the second approach. I am good to unify the generated comment format. But I think it could be challenge, as we should escape between two formats which could make generated comments strange/inaccurate.
// /**
// * Some dead comments.
// */
//
// Things changed. We are going ..
Currently, the generated comments blindly strip some special strings. I don't think it is a good thing.
I suggest we keep it simple and don't touch comment content, this is also a safe path. If we want javadoc style comments, I think it is ok to convert them manually.
String[] commentArray = commentMulti.split("\n"); | ||
for (String comment : commentArray) { | ||
|
||
comment = comment.replaceAll("//|/\\*\\*|/\\*|\\*\\*/|\\*/", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think people will want to maintain this kind of code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/do/don't/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think people will want to maintain this kind of code.
I'll amend that and I won't touch the comments so they're not needed here.
comment = comment.replaceAll("//|/\\*\\*|/\\*|\\*\\*/|\\*/", "") | ||
.replaceAll("^[* ]+", "").trim(); | ||
|
||
if (!comment.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The generated comments has no empty line which is not good.
@kezhuw Thank you very much for your review. I really didn't consider that 😂😂. I will keep the original format output. |
I prefer to move them above the code. |
Thanks, I thought so too, I'll modify the code. |
0631b4f
to
ae35908
Compare
Hi @kezhuw , I made some changes, could you take a look at it for me? I won't touch the annotation content now.
private static String getComments(String space, List<String> commentList) {
if (commentList == null || commentList.isEmpty()) {
return "";
}
String comments = String.join("", commentList);
StringBuilder formatBuilder = new StringBuilder();
for (String s : comments.split("\r?\n")) {
formatBuilder.append("\n")
.append(space)
.append(s.replaceAll("^[ \t]+", ""));
}
return formatBuilder.append("\n").toString();
} |
Generate comments from zookeeper.jute into code: https://issues.apache.org/jira/browse/ZOOKEEPER-4880
Brief Description
Support generating end-of-line comments and class comments in
zookeeper.jute
into code.How to test this change
zookeeper-jute/target/generated-sources/java/org/apache/zookeeper
andzookeeper-client/zookeeper-client-c/generated
directories before and after the modification, there are no other differences except the comments.2. When the test class has multiple lines of comments, the comments can be generated normally.
3. Testing vector type properties can generate comments normally.
4. Testing class type properties can generate comments normally
5. Testing comments that do not meet expectations will not generate comments and will not affect the generation of normal code.