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
Enhanced EOL support #2685
Enhanced EOL support #2685
Conversation
…`Utils.EOL` as deprecated
… which line ending was found during parsing -- this is then used during the lexical preservation csmtoken insertion/diffing to ensure that the "new" newlines are of the same type as the parent....
…r one isn't set or it is a meta-value e.g. EMPTY or NONE
…ystem's line ending
…t should be unescaped line separators, but the lookup returns escaped line separators; deprecated isSpaceOrTab and added isWhitespaceButNotEndOfLine as a replacement;
…pace within the grammar (e.g. non-breaking spaces and tab characters)
javaparser-core/src/main/java/com/github/javaparser/JavaParser.java
Outdated
Show resolved
Hide resolved
javaparser-core/src/main/java/com/github/javaparser/JavaParser.java
Outdated
Show resolved
Hide resolved
javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmElement.java
Outdated
Show resolved
Hide resolved
javaparser-core-testing/src/test/java/com/github/javaparser/utils/TestUtils.java
Outdated
Show resolved
Hide resolved
javaparser-core/src/main/java/com/github/javaparser/JavaParser.java
Outdated
Show resolved
Hide resolved
javaparser-core/src/main/java/com/github/javaparser/ast/Node.java
Outdated
Show resolved
Hide resolved
Random informational remark: the textblock feature of Java 12 or 13 or so is very explicit about the kind of eols it wants. Be careful not to break it :-) |
It would be a shame if our test suite wasn't able to highlight any regression like this ;) But yes -- Just had a read through the JEP and found this: https://openjdk.java.net/jeps/378#1--Line-terminators
|
...arser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmTextBlock.java
Outdated
Show resolved
Hide resolved
Hmm... as far as I can tell, there is no reason for the tests to fail on appveyor (consistently) but then pass on all other places... As far as I can see, the "expected" and "actual" sections are identical, but there's no information if there are line separator differences... I'll push a revised test in a moment.
|
…arser into issue_2647_eol
…r by character). If it is important for you to define the line endings used, provide a LineEnding as a second parameter else use TestUtils#readResourceUsingSystemEol
…ovides more descriptive output from the test's utility method
…`input` meaning that it checks out the code using the repo's line endings not the system's line endings this was discovered / came up as a problem in javaparser#2685 where javaparser started to respect the line endings of test resources instead of reading line-by-line and inserting the system's line endings
Oh dear, I should have followed up on this passing thought for just a couple of minutes... cursory searching turned up many results about this...
https://help.appveyor.com/discussions/problems/1119-allow-changing-git-autocrlf-setting
https://gitlab.freedesktop.org/mesa/mesa/commit/9e5e3a8ead5321a6abc0add8f6e59e50052f9698 Adding this to the appveyor.yml has the tests passing :) init:
# Setup autocrlf -- by default, appveyor uses autocrlf input
# ... This affects tests which expect resource files to have the systems's line separator.
- git config --global core.autocrlf true https://ci.appveyor.com/project/ftomassetti/javaparser/builds/33067787 |
Yeeeeessss, but the tests passed before, and shouldn't need an AppVeyor change. Can you reason why this PR broke all those tests in the first place? One place to look for is files with test content. Those have some kind of EOL, and tests probably depend on that, or better: expect certain EOLs to be in there. That means AppVeyor was doing the right thing - leave the EOLs alone. Note that the AppVeyor build exists for only one thing: check EOL behaviour on Windows! |
I was notified that I was mentioned here or so? I don't see anything? Or was it a notification of a new commit maybe? |
Basically appveyor checked out the code using the repo's line endings. That meant that the files all have \n endings instead of \r\n. Once this PR started to respect the file's ACTUAL line endings (e.g. within lexical preservation tests), it broke the tests. Setting autocrlf to true causes appveyor to checkout the code using the host's line separator again 😄. |
From chat:
|
… caller wants the actual line separator "as-is" and without any additional escaping; added human-readable "descriptions" to the LineEnding enums; progress on LineEndingProcessingProvider.java -- now functional and tests passing;
…ost's line separator
…to retaining them
…to retaining them
…to retaining them
Well done @MysterAitch ! This is a fundamental improvement! |
Fixes #2647
This PR adds an enum to represent different types of end-of-line / line-separator characters.
It also adds a utility method which allows you to "detect" which style of line-separator a given string uses.
This is incorporated into the parsing process by reading in the content of the given provider and adding this as a data field within the top-most node.
This is then used as part of the CSM and pretty printer where new added nodes will reflect this (defaulting to the system's eol character if it is unknown/ambiguous e.g. it is a single line or there are mixed endings).
Reading in the provider content and then creating a brand new
StringProvider
using this string is a bit "hacky" and I'm sure there must be a better way to do it, I just don't know what it is -- comments and suggestions welcomed!