Skip to content

SONARJAVA-5984 Support Module Import Declarations#5403

Merged
tomasz-tylenda-sonarsource merged 6 commits intomasterfrom
tt/import-module
Feb 2, 2026
Merged

SONARJAVA-5984 Support Module Import Declarations#5403
tomasz-tylenda-sonarsource merged 6 commits intomasterfrom
tt/import-module

Conversation

@tomasz-tylenda-sonarsource
Copy link
Contributor

No description provided.

@hashicorp-vault-sonar-prod
Copy link

hashicorp-vault-sonar-prod bot commented Jan 26, 2026

SONARJAVA-5984

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking good, I just have a couple of suggestions

}

@Override
public List<Tree> children() {

Choose a reason for hiding this comment

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

Should we add the module token to the list of children?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

boolean isModuleImport = org.eclipse.jdt.core.dom.Modifier.isModule(e2.getModifiers());

// "on demand" means `import pkg.*;`
if (e2.isOnDemand() && !isModuleImport) {

Choose a reason for hiding this comment

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

Is it possible to mix an on-demand import and a module import? I am not sure the JLS allows this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe this is not allowed: https://docs.oracle.com/javase/specs/jls/se25/html/jls-7.html#jls-7.5 On demend imports exist only in the context of type and static imports.

Choose a reason for hiding this comment

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

Ok, because we have coverage, I will not question this one too much but it looks little weird to me

…portTree.java

Co-authored-by: Dorian Burihabwa <75226315+dorian-burihabwa-sonarsource@users.noreply.github.com>
);
t.binding = e2.resolveBinding();

if (!isModuleImport) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we want to skip resolution of IModuleBinding when it is a module ? Asking it because we don't skip resolution of IPackageBinding when isOnDemand && !isModuleImport

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My understanding is that it does not make sense for a module. In fact, when the condition is removed, we are getting type cast exception in jdt.

Co-authored-by: rombirli <56340680+rombirli@users.noreply.github.com>
boolean isModuleImport = org.eclipse.jdt.core.dom.Modifier.isModule(e2.getModifiers());

// "on demand" means `import pkg.*;`
if (e2.isOnDemand() && !isModuleImport) {

Choose a reason for hiding this comment

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

Ok, because we have coverage, I will not question this one too much but it looks little weird to me

@sonarqube-next
Copy link

sonarqube-next bot commented Feb 2, 2026

Copy link
Contributor

@rombirli rombirli left a comment

Choose a reason for hiding this comment

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

LGTM

@tomasz-tylenda-sonarsource tomasz-tylenda-sonarsource merged commit 213daaf into master Feb 2, 2026
34 of 35 checks passed
@tomasz-tylenda-sonarsource tomasz-tylenda-sonarsource deleted the tt/import-module branch February 2, 2026 15:28
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.

3 participants