-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix TextBlockLiteralExpr in LexicalDifferenceCalculator #3937
Fix TextBlockLiteralExpr in LexicalDifferenceCalculator #3937
Conversation
I'm not sure if this is the right solution. I need to take the time to look into this problem. |
This made me quite confident some '\n' has been lost in the process. |
The pretty printer and LPP do not work the same way at all. I have no doubt that it is necessary to add a line break but it is more the solution raises some questions. I need to dig a little deeper into the subject. |
Since the parser is not very restrictive on text blocks and the definition of element syntax in the LPP does not categorize text block delimiters, your proposal can be accepted. However, you should simplify your unit test and avoid referring to your project. Thanks. |
...e-testing/src/test/java/com/github/javaparser/printer/lexicalpreservation/Issue3936Test.java
Outdated
Show resolved
Hide resolved
@@ -290,9 +290,9 @@ private void calculatedSyntaxModelForNode(CsmElement csm, Node node, List<CsmEle | |||
} else if ((csm instanceof CsmString) && (node instanceof TextBlockLiteralExpr)) { | |||
// FIXME: csm should be CsmTextBlock -- See also #2677 | |||
if (change instanceof PropertyChange) { | |||
elements.add(new CsmToken(GeneratedJavaParserConstants.TEXT_BLOCK_LITERAL, "\"\"\"" + ((PropertyChange) change).getNewValue() + "\"\"\"")); | |||
elements.add(new CsmToken(GeneratedJavaParserConstants.TEXT_BLOCK_LITERAL, "\"\"\"\n" + ((PropertyChange) change).getNewValue() + "\"\"\"")); | |||
} else { |
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.
To set the most appropriate eof character, you can probably use Node.getLineEndingStyle().toString().
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.
This is not a matter of style, it is a matter of Java specification Just like prettyPrinter adds a \n
.
On a system where EOL is '\r', Node.getLineEndingStyle().toString()
would break TextBlockLiteralExpr
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.
This is similar to CsmTextBlock.prettyPrint(Node, SourcePrinter)
not relying on printer.println()
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.
https://docs.oracle.com/en/java/javase/14/docs/specs/text-blocks-jls.html
Reading https://www.vojtechruzicka.com/java-text-blocks/ makes me feel I overlooked part of the spec
Line terminators are normalized to the ASCII LF character, as follows:
1. An ASCII CR character followed by an ASCII LF character is translated to an ASCII LF character.
2. An ASCII CR character is translated to an ASCII LF character.
I'm less comfortable with dynamic EOL in this case, but you're the boss.
Should I do the same in CsmTextBlock.prettyPrint(Node, SourcePrinter)
?
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.
// Note that values within TextBlocks ALWAYS have the \n line ending, per https://openjdk.java.net/jeps/378#1--Line-terminators
(CsmTextBlock
author also felt '\n' were preferable)
Suggested fix for #3936.