Repository navigation
SONARJAVA-7295 Decouple the frontend AST from Eclipse JDT core - #6472
Conversation
|
/pvf |
|
📊 Performance Validation complete Projects with unexpected PVF results:
|
edf0ae1 to
8519170
Compare
There was a problem hiding this comment.
This file is quite big and it's migration is not complete in this PR (usages of ITypeBinding, IMethodBinding...), it might be easier to migrate this file in it's own PR. It could be good as well to split this 3k LoC file to a "parser" module containing small java files (<300LoC) to make it more maintainable.
There was a problem hiding this comment.
This file corresponds to the implementation of parsing with ECJ, so it is expected that it contains references to IBinding and other ECJ specific types.
Yes, the goal in this PR is only to remove ECJ types from AST nodes in the Sonar Java API. Another PR is planned to move JParser and other ECJ specific J* classes behind implementation agnostic interfaces and into a dedicated package.
| private List<AnnotationTree> annotations; | ||
|
|
||
| public IBinding binding; | ||
| private Symbol symbol = Symbol.UNKNOWN_SYMBOL; |
There was a problem hiding this comment.
this private symbol field + setter + default assignation to unknown is repeated everywhere, is it planned to refactor it in a future PR?
There was a problem hiding this comment.
I could propose you the following design to avoid these duplications
Resolvable<T extends Resolvable> is the shared contract for things that can be unresolved. unknown() returns T and has no default.
Type and Symbol each close that parameter on themselves. Type and Symbol subclasses supply a default: unknown() returns ___ .UNKNOWN.
ResolvableContainer<T extends Resolvable> holds the repeated symbol state. It provides the symbol field, the setter, and symbol(). AbstractTypedTree, TypePatternTreeImpl, TypeParameterTreeImpl, and the other trees only implement ResolvableContainer and use those defaults.
classDiagram
class Resolvable~T~ {
<<interface>>
+unknown() T
}
class Type {
<<interface>>
+unknown() Type
}
class Symbol {
<<interface>>
}
class ResolvableContainer~T~ {
<<interface>>
+T symbol
+setSymbol(T) void
+symbol() T
}
Resolvable~T~ <|-- Type
Resolvable~T~ <|-- Symbol
ResolvableContainer~T~ <|.. AbstractTypedTree
ResolvableContainer~T~ <|.. TypePatternTreeImpl
ResolvableContainer~T~ <|.. TypeParameterTreeImpl
note for Type "unknown() returns Type.UNKNOWN"
note for ResolvableContainer~T~ "T extends Resolvable"
There was a problem hiding this comment.
I don't think we could share the default between instances through an interface, as interfaces cannot hold fields ? In the end, I think we would still need to implement the setSymbol and symbol methods for each instance, so this feels a bit "over-engineered". WDYT ?
|
LGTM with 2 NIT |
8519170 to
408ad0d
Compare
Code Review ✅ Approved🟡 Medium risk · Replacing AST-held JDT bindings with eagerly stored symbols and types could alter semantic resolution, affecting Java analysis results across many constructs. Decouples the frontend AST from Eclipse JDT core by having AST nodes store Verification Rules 1/1 met Repos 3 inspected · PRs 1 inspectedFunctional validation No results Rules 1 passed 2 not applicable
Broader impact Repos 3 inspected PRs 1 inspectedCross-repo 3 repositories inspected 0 open impacts
Cross-PR 1 PR 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
SymbolandTypevalues set duringJParserconversion instead of ECJIBindingreferencesJavaTree.CompilationUnitTreeImplnow holds the semantic model, undefined types, and environment cleaner viasetSemanticModelJSemahelpers such assymbolOrUnknownandtypeOrUnknownto map bindings to API symbols at parse timeAstSemanticValuesTestverifying AST classes carry no ECJ dependenciesThis will update automatically on new commits.