Skip to content

SONARJAVA-5978 Support Compact Source Files#5397

Merged
tomasz-tylenda-sonarsource merged 6 commits intomasterfrom
tt/compact-source-files
Feb 2, 2026
Merged

SONARJAVA-5978 Support Compact Source Files#5397
tomasz-tylenda-sonarsource merged 6 commits intomasterfrom
tt/compact-source-files

Conversation

@tomasz-tylenda-sonarsource
Copy link
Contributor

No description provided.

@hashicorp-vault-sonar-prod
Copy link

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

SONARJAVA-5978

@tomasz-tylenda-sonarsource tomasz-tylenda-sonarsource changed the base branch from master to tt-jdt-1.8 January 23, 2026 14:16
@tomasz-tylenda-sonarsource tomasz-tylenda-sonarsource changed the base branch from tt-jdt-1.8 to tt/jdt-1.8 January 23, 2026 14:17
@tomasz-tylenda-sonarsource tomasz-tylenda-sonarsource changed the base branch from tt/jdt-1.8 to master January 23, 2026 14:17
@tomasz-tylenda-sonarsource tomasz-tylenda-sonarsource force-pushed the tt/compact-source-files branch 7 times, most recently from 1fcda73 to d0ee95d Compare January 29, 2026 17:12
@tomasz-tylenda-sonarsource tomasz-tylenda-sonarsource marked this pull request as ready for review January 29, 2026 17:41
@tomasz-tylenda-sonarsource tomasz-tylenda-sonarsource force-pushed the tt/compact-source-files branch 2 times, most recently from df8c9db to 127ad59 Compare January 30, 2026 10:26
public ITypeBinding typeBinding;

public ClassTreeImpl(Kind kind, SyntaxToken openBraceToken, List<Tree> members, SyntaxToken closeBraceToken) {
public ClassTreeImpl(Kind kind, List<Tree> members) {

Choose a reason for hiding this comment

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

How about introducing a new constructor with nullable arguments? It might help us reducing the amount of call sites to change and keeping the fields brace fields final. WDYT?

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.

ClassTreeImpl clazz = (ClassTreeImpl) cu.types().get(0);
assertThat(clazz).isNotNull();
assertThat(clazz.kind()).isEqualTo(Tree.Kind.IMPLICIT_CLASS);
assertThat(clazz.members()).hasSize(3);

Choose a reason for hiding this comment

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

Should we explicitly test that the 3 members are a method, a variable and a type?

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.


@Test
void compact_source() {
JavaFilesCache javaFilesCache = new JavaFilesCache();

Choose a reason for hiding this comment

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

TIL about JavaFilesCache

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack.

boolean isAnonymous = tree.simpleName() == null;
if (!isAnonymous) {
// Exclude anonymous classes other than implicit classed of compact source files.
boolean isExcluded = tree.simpleName() == null && !tree.is(Kind.IMPLICIT_CLASS);

Choose a reason for hiding this comment

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

No need to address this but I wonder in how many places we infer a class is anonymous from it simpleName is null rather than using a more explicit Kind

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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, let's try and see if we can avoid modifying the existing constructor of ClassTreeImpl

@sonarqube-next
Copy link

sonarqube-next bot commented Feb 2, 2026

@tomasz-tylenda-sonarsource tomasz-tylenda-sonarsource merged commit f305228 into master Feb 2, 2026
16 checks passed
@tomasz-tylenda-sonarsource tomasz-tylenda-sonarsource deleted the tt/compact-source-files branch February 2, 2026 16:30
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