Skip to content

Conversation

@jevanlingen
Copy link
Contributor

@jevanlingen jevanlingen commented Aug 6, 2025

What's changed?

Non-star imports in Kotlin now retain not only the type of the imported object (e.g., a companion object), but also its supertypes. This ensures that full type information is available for the imported member.

What's your motivation?

When analyzing a Kotlin file, type information such as cu.getTypesInUse().getUsedMethods() or cu.getTypesInUse().getVariables() will refer to the method or variable as declared on its actual type. This can be the declaring class, a superclass, or an interface.

In Kotlin, this becomes problematic when importing a member from a companion object that implements an interface. The import itself only carries the type of the companion object, not of its owning class. As a result, the type of the used method and the type of the imported symbol don’t match, making it impossible to correlate the import with the usage.

By including the owning class information on imported members, this allows recipes to match imports against used methods and variables, even when they’re inherited from a supertype.

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Aug 6, 2025
@jevanlingen jevanlingen moved this from In Progress to Backlog in OpenRewrite Aug 6, 2025
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@timtebeek timtebeek marked this pull request as draft August 6, 2025 12:43
github-actions[bot]

This comment was marked as spam.

@jevanlingen jevanlingen moved this from Backlog to In Progress in OpenRewrite Aug 14, 2025
@jevanlingen jevanlingen changed the title Imports from companion objects should have supertype information Imports from companion objects should have owningClass information Aug 14, 2025
@jevanlingen jevanlingen marked this pull request as ready for review August 14, 2025 10:18
@openrewrite openrewrite deleted a comment from timtebeek Aug 14, 2025
@jevanlingen jevanlingen moved this from In Progress to Ready to Review in OpenRewrite Aug 14, 2025
github-actions[bot]

This comment was marked as spam.

github-actions[bot]

This comment was marked as spam.

github-actions[bot]

This comment was marked as spam.

github-actions[bot]

This comment was marked as spam.

Copy link
Contributor

@knutwannheden knutwannheden left a comment

Choose a reason for hiding this comment

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

Nice find!

@jevanlingen jevanlingen merged commit a78e07a into main Aug 20, 2025
2 checks passed
@jevanlingen jevanlingen deleted the supertype-info-missing-companion-object branch August 20, 2025 08:08
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Aug 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants