Repository navigation
SONARJAVA-7300 Decouple the Sonar Java frontend from Eclipse JDT core - #6485
aurelien-coet-sonarsource wants to merge 8 commits into
Conversation
d50bf37 to
80b9ad3
Compare
|
/pvf |
|
📊 Performance Validation complete |
c0370cd to
b88c5c0
Compare
b88c5c0 to
c4b1cf5
Compare
|
/pvf |
|
📊 Performance Validation complete |
58bc4a9 to
d4d7696
Compare
|
/pvf |
|
📊 Performance Validation complete |
cba5e05 to
7e1aebc
Compare
c979713 to
5170c8d
Compare
|
/pvf |
|
Projects with unexpected PVF results:
|
|
📊 Performance Validation complete Projects with unexpected PVF results:
|
leonardo-pilastri-sonarsource
left a comment
There was a problem hiding this comment.
Overall it looks good to me, there are some minor things that I pointed out.
This PR might be the right place to improve some of the naming and connections that we have in this layer of the frontend, but I don't want to start piling things to do here.
So the following is just FYI, and you can simply tackle the comments on the code
A couple of things that kind of bother me are:
- we call parser what is actually an AST converter
- we get an instance of the parser through an object called JParserConfig
- the JParserConfig has a "parse" method that needs to be implemented
- the parse method requires a callback parameter called "action", and returns void, instead of returning compilation units 😠
- JParserConfig is still bound to jdt, as the modes implementations rely on jdt ASTParser
The PR still does a great job at setting a building block for the future, and I understand that you tried to just keep the existing code while abstracting away the jdt parser, I'm good with that, but I think it's worth keeping in mind where we could still improve in making classes more readable and with fewer responsibilities
| import java.util.Optional; | ||
| import java.util.Set; | ||
| import javax.annotation.Nullable; | ||
|
|
There was a problem hiding this comment.
We can revert this changes
| /** | ||
| * Returns an annotation element's default value, or null if it has none. | ||
| * Values use the same representation as {@link SymbolMetadata.AnnotationValue#value()}: | ||
| * constants, type symbols, variable symbols, annotation instances, or arrays of these values. | ||
| */ | ||
| @Nullable | ||
| default Object annotationElementDefaultValue() { | ||
| return null; | ||
| } |
There was a problem hiding this comment.
We should add a small changelog note in the API changes docs
There was a problem hiding this comment.
| @Override | ||
| public JParser astParser() { | ||
| return new JDTParser(jdtParser()); | ||
| } | ||
|
|
||
| ASTParser jdtParser() { | ||
| ASTParser astParser = ASTParser.newParser(AST.getJLSLatest()); |
There was a problem hiding this comment.
I think this is the perfect occasion to also improve on how we name things around here.
I feel like what is currently called JDTParser on our side, is actually an AST converter, more than a parser, as the parsing happens inside org.eclipse.jdt.core.dom.ASTParser that we call in a couple of lines, and then 99.9% of our JDTParser is moving information from an AST to the other.
There was a problem hiding this comment.
Feel free to ignore this one for now if it's changing too many things
There was a problem hiding this comment.
I have opened another PR on top of this one to try and improve this, as well as simplify the parser interface.
| } | ||
|
|
||
| public abstract void parse(Iterable<? extends InputFile> inputFiles, BooleanSupplier isCanceled, | ||
| void parse(Iterable<? extends InputFile> inputFiles, BooleanSupplier isCanceled, |
There was a problem hiding this comment.
Not mandatory, but we could easily take the chance to remove this <? extends InputFile> and just have
| void parse(Iterable<? extends InputFile> inputFiles, BooleanSupplier isCanceled, | |
| void parse(Iterable<InputFile> inputFiles, BooleanSupplier isCanceled, |
It requires a few changes here and there but it's a fairly small and mechanical change, basically the only reason we have this is so that when processin GeneratedFiles with Jasper, we can at some point do
GeneratedFile generatedFile = generatedJavaFiles.get(smapFile.getGeneratedFile());
if (generatedFile != null) {instead of
var file = generatedJavaFiles.get(smapFile.getGeneratedFile());
if (file instanceof GeneratedFile generatedFile) {
generatedFile.addSmap(smapFile);
}
That's it... we can talk about his
| enum Mode { | ||
| BATCH, | ||
| FILE_BY_FILE; |
There was a problem hiding this comment.
Currently there is no contract that enforces a JParserConfig implementation to provide two different implementation based on the selected Mode. This different mode batch/file_by_file is something kind of specific to ECJ at the moment, I think tree-sitter for instance does now have such modes, even if we could manually (and partially) implement them.
That being said, our frontend is somewhat bound to this definition currently, so I think we can keep this separation of modes, but then we should enforce a different implementation for the 2 of them.
There was a problem hiding this comment.
On a second thought, I don't want to slow down this PR for this reason, for now it's ok to have this implementation.
There was a problem hiding this comment.
I agree. As you mention, our current implementation is pretty tightly bound to that model, but I'd also like to try to improve this in #6503.
5170c8d to
88ce48c
Compare
Use semantic interfaces for shared operations and expose annotation element defaults through MethodSymbol. Extract neutral nullability data while retaining JUtils and JSymbolMetadataNullabilityHelper.
Move JDT parsing and semantic implementations into org.sonar.java.jdt. Use the existing semantic and diagnostic API contracts directly, retain parser and shared utility contracts, and create environment cleanup callbacks in the JDT parser.
67336c9 to
b308c9c
Compare
Code Review ✅ Approved 🟡 Medium risk 7 closed / 7 findingsMoving Java parsing and semantic handling behind backend-neutral contracts could introduce AST or symbol-resolution regressions in analysis. Decouples the Sonar Java frontend from Eclipse JDT core behind backend-neutral contracts, with JDT isolation verified by tests. Resolved issues include the ✅ 7 closed✅ Bug: directSuperTypes now adds java.lang.Object for interfaces and arrays
✅ Quality: Unused MapBuilder import left after switching to Map.of
✅ Cross-Repo: SE repo test helper no longer compiles: JParser/JParserConfig API moved
✅ Cross-PR: Source-path type resolution from #6308 dropped by the new JDT layout
✅ Cross-PR: Release-API JDK resolution from #6459 lost or uncompilable after refactor
...and 2 more closed from earlier reviews Verification Rules 1/1 met Knowledge 🔎 2 PRs 4 inspectedFunctional validation No results Rules 1 passed 3 not applicable
Knowledge 🔎 2 informed a finding
Broader impact PRs 4 inspectedCross-PR 4 PRs inspected 0 open impacts
Auto-approval Not enabledFor more verification details, comment OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
|




Summary by Gitar
Symbol.MethodSymbol.annotationElementDefaultValue()as semantic API typesWRAPPER_TO_PRIMITIVEandPRIMITIVE_TO_WRAPPERpublic immutable maps inJUtilsFrontendApiTestand replaced it withJdtClassesLayoutTestandClassLayoutTestUtilsto check the JDT layoutorg.sonar.java.jdtbehind backend-neutral contractsJParserConfig.Modedispatch toJDTParserConfig, with batch mode falling back to file-by-file parsing on errorsThis will update automatically on new commits.