Skip to content

Don't shorten types when a superclass is outside the file - #3124

Open
kalayciburak wants to merge 1 commit into
diffplug:mainfrom
kalayciburak:fix/inherited-member-type-shortening
Open

kalayciburak wants to merge 1 commit into
diffplug:mainfrom
kalayciburak:fix/inherited-member-type-shortening

Conversation

@kalayciburak

Copy link
Copy Markdown
Contributor

Summary

shortenFullyQualifiedTypes shortened external.Type inside class Child extends Base when Base lives in another file. The simple name then resolves to an inherited member type, and the file no longer compiles.

The step has no classpath, so a supertype that is not in this file can contribute member types it cannot see. References inside that type stay qualified. A supertype declared in the same file is still visible: only a name that matches a declared type is left alone, and other names are still shortened. java.lang.Object does not count, because it has no member types.

Fixes #3117

Test plan

  • ./gradlew :testlib:test --tests com.diffplug.spotless.java.ShortenFullyQualifiedTypesStepTest — 36 tests, including the cross-file case that failed before the change
  • ./gradlew :lib:spotlessJavaCheck :testlib:spotlessJavaCheck

shortenFullyQualifiedTypes runs without a classpath. A superclass in
another file can declare a member type, so shortening a qualified name
inside the subclass can resolve to that member instead. Leave those
references qualified. A superclass declared in the same file is still
visible, and unrelated names there are still shortened.

Fixes diffplug#3117
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

This branch has not been deployed

No deployments
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.

shortenFullyQualifiedTypes can change type resolution for inherited nested types

1 participant