Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeUtils#isAssignable() improvements #4696

Merged
merged 11 commits into from
Nov 21, 2024

Conversation

knutwannheden
Copy link
Contributor

@knutwannheden knutwannheden commented Nov 21, 2024

TypeUtils#isAssignable() is used by many different recipes. One complexity that up until now hadn't been considered is that the assignability check when also considering the call-site variance. For example, checking if java.util.List<String> can be assigned to <T extends java.util.Collection<String>> depends a lot on where that <T> is declared (e.g. as the parameter or return type of a method or the type of a local variable). The API new allows the caller to provide an additional TypePosition parameter to indicate this.

We need to consider the "position" when performing the assignability check. I.e. check if a parameterized type compared against a generic type variable is used in a context where the generic type parameter is bound by the parameterized type or not.
@knutwannheden knutwannheden changed the title type utils assignable position TypeUtils#isAssignable() improvements Nov 21, 2024
@knutwannheden knutwannheden merged commit 01813e3 into main Nov 21, 2024
2 checks passed
@knutwannheden knutwannheden deleted the type-utils-assignable-position branch November 21, 2024 14:14
MBoegers pushed a commit to MBoegers/rewrite that referenced this pull request Dec 18, 2024
* Add `TypeUtils` tests for primitives

* Correct `TypeUtils#isAssignableTo()` for primitive array types

* New `TypeUtils#isAssignableTo()` API

We need to consider the "position" when performing the assignability check. I.e. check if a parameterized type compared against a generic type variable is used in a context where the generic type parameter is bound by the parameterized type or not.

* Implement new API

* Remove one more `stream()` call

* Update Javadoc visitors to use `TypeUtils#isAssignableTo()` correctly

* Correction

* Corrections

* Corrections

* More Javadoc fixes

* Add missing `@MinimumJava11` annotation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

1 participant