Skip to content

SONARJAVA-7295 Decouple the frontend AST from Eclipse JDT core - #6472

Merged
aurelien-coet-sonarsource merged 1 commit into
masterfrom
ac/implementation-agnostic-frontend
Nov 4, 2026
Merged

aurelien-coet-sonarsource merged 1 commit into
masterfrom
ac/implementation-agnostic-frontend

Conversation

@aurelien-coet-sonarsource

@aurelien-coet-sonarsource aurelien-coet-sonarsource commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary by Gitar

  • Decoupled frontend AST from JDT:
    • AST nodes store Symbol and Type values set during JParser conversion instead of ECJ IBinding references
    • JavaTree.CompilationUnitTreeImpl now holds the semantic model, undefined types, and environment cleaner via setSemanticModel
  • Symbol resolution:
    • Added JSema helpers such as symbolOrUnknown and typeOrUnknown to map bindings to API symbols at parse time
  • Tests:
    • Added AstSemanticValuesTest verifying AST classes carry no ECJ dependencies

This will update automatically on new commits.

@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title Decouple the frontend AST from Eclipse JDT core SONARJAVA-7295 Decouple the frontend AST from Eclipse JDT core Nov 3, 2026
@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

SONARJAVA-7295

@aurelien-coet-sonarsource

Copy link
Copy Markdown
Contributor Author

/pvf

@hashicorp-vault-sonar-prod

Copy link
Copy Markdown
Contributor

📊 Performance Validation complete
🆕 0 new · 🗑️ 0 lost issues
View dashboard

Projects with unexpected PVF results:

  • crate

@aurelien-coet-sonarsource
aurelien-coet-sonarsource marked this pull request as ready for review November 4, 2026 08:02
@aurelien-coet-sonarsource
aurelien-coet-sonarsource force-pushed the ac/implementation-agnostic-frontend branch from edf0ae1 to 8519170 Compare November 4, 2026 12:37

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this private symbol field + setter + default assignation to unknown is repeated everywhere, is it planned to refactor it in a future PR?

@rombirli rombirli Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?

@rombirli

rombirli commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

LGTM with 2 NIT

@aurelien-coet-sonarsource
aurelien-coet-sonarsource force-pushed the ac/implementation-agnostic-frontend branch from 8519170 to 408ad0d Compare November 4, 2026 14:51
@gitar-bot

gitar-bot Bot commented Nov 4, 2026

Copy link
Copy Markdown
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 Symbol and Type values resolved during JParser conversion instead of ECJ IBinding references. JavaTree.CompilationUnitTreeImpl now holds the semantic model via setSemanticModel, and JSema gains symbolOrUnknown and typeOrUnknown helpers. No issues found.

Verification Rules 1/1 met Repos 3 inspected · PRs 1 inspected

Functional validation No results

Rules 1 passed 2 not applicable

✅ Repository license compliance

Broader impact Repos 3 inspected PRs 1 inspected
Cross-repo 3 repositories inspected 0 open impacts

SonarSource/sonar-java-symbolic-execution Inspected
SonarSource/sonarlint-intellij Inspected
SonarSource/sonarqube Inspected

Cross-PR 1 PR inspected 0 open impacts

PR 6437: SONARJAVA-7236 Score AST and semantic mismatches against ECJ Inspected

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@sonarqube-next

sonarqube-next Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

@aurelien-coet-sonarsource
aurelien-coet-sonarsource merged commit 4696630 into master Nov 4, 2026
18 checks passed
@aurelien-coet-sonarsource
aurelien-coet-sonarsource deleted the ac/implementation-agnostic-frontend branch November 4, 2026 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants