Include source file path in failed ParseResult when parsing via SourceRoot #4786#4874
Include source file path in failed ParseResult when parsing via SourceRoot #4786#4874jlerbsc merged 2 commits intojavaparser:masterfrom
Conversation
javaparser-core/src/main/java/com/github/javaparser/utils/SourceRoot.java
Outdated
Show resolved
Hide resolved
javaparser-core/src/main/java/com/github/javaparser/utils/SourceRoot.java
Outdated
Show resolved
Hide resolved
javaparser-core-testing/src/test/java/com/github/javaparser/issues/Issue4786Test.java
Outdated
Show resolved
Hide resolved
javaparser-core-testing/src/test/java/com/github/javaparser/issues/Issue4786Test.java
Outdated
Show resolved
Hide resolved
javaparser-core-testing/src/test/java/com/github/javaparser/issues/Issue4786Test.java
Outdated
Show resolved
Hide resolved
javaparser-core-testing/src/test/java/com/github/javaparser/issues/Issue4786Test.java
Outdated
Show resolved
Hide resolved
javaparser-core-testing/src/test/java/com/github/javaparser/issues/Issue4786Test.java
Outdated
Show resolved
Hide resolved
javaparser-core/src/main/java/com/github/javaparser/utils/SourceRoot.java
Show resolved
Hide resolved
|
I am waiting for you to make the other changes before committing your work. |
d95b3b7 to
0fc6bf6
Compare
Thank you very much for your guidance! |
|
Can you squash your commits to make it more readable? Thank you. |
0fc6bf6 to
9642c1f
Compare
Thanks for the reminder! I’ve already squashed all the commits into one commit. |
|
Now what happens if parsing fails? The issue mainly concerned cases where parsing failed, because in the other case the path is already available via cu.getStorage().getPath(). |
In my first attempt I added a test resource whose content was a single backslash-u ("\u"). The goal was to deterministically trigger a scanner failure so that ParseResult would be unsuccessful and result() would be empty (as issue #4786 ). This let me verify that getSourcePath is present on failed parses. Based on your feedback, I removed the custom “\u” fixture and now use an existing Java file under the utils test resources to trigger the failure. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4874 +/- ##
===============================================
+ Coverage 58.330% 58.333% +0.003%
Complexity 2535 2535
===============================================
Files 677 677
Lines 39038 39041 +3
Branches 7088 7089 +1
===============================================
+ Hits 22771 22774 +3
Misses 13368 13368
Partials 2899 2899
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
64f317d to
cb4a02e
Compare
- SourceRoot populates sourcePath for file-based parsing paths - ParseResult adds getSourcePath(); toString includes the path on failure for better diagnostics - Tests: SourceRootTest : getSourcePathTest and sourcePathToStringTest - Formatting: run spotless to satisfy CI.
cb4a02e to
1fafe96
Compare
|
On second thought, I wonder if it wouldn't be better to set the source path in the JavaParser class at the point where methods take a file or path as a parameter. |
|
Why did you close this PR? Just make sure to squash your commits and isolate improvements to other classes in a specific commit. |
|
The method that defines character encoding is deprecated because the input character encoding must be a configuration option so you can use the method that does not define the encoding. |
…rser by changing the method in SourceRoot.tryToParse.
|
Thank you for your contribution. |
Thank you for your guidance. I’ve learned a lot from this task. |











Fixes #4786.
Problem: Failed parses from SourceRoot.tryToParse() don’t indicate which file failed (ParseResult has Problems but no file path).
Change: ParseResult now carries an internal sourcePath set by SourceRoot; on failures, ParseResult.toString() includes “for ”. Successful parses still set CompilationUnit storage as before.
Tests: Added issues/Issue4786Test to reproduce the “file content is only ‘\u’” failure and assert diagnostics include the absolute file path.
Compatibility: Backward compatible.