Fix "fix return type" quickfix for type param return type #1559
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1558
What it does
The old implementation would propose replacing the return type with erasure of the type parameter if the compliance was set pre 1.5. If the compliance was 1.5 or later, it would propose replacing the return type with the type parameter as it appears in the declaration of the method being overridden.
Instead, these are now two separate entries which may be generated:
This entry is only generated if it is valid to use the erasure for the return type. Specifically, if the method declares the type parameters of the method being overriden, and one of type variables has an upper bound that is a parameterized type, then using the type erasure of that variable in place of the variable is not valid, since the type erasure allows a wider range of types. Code example:
This entry now takes into account that the type parameters may not yet be declared on the type. i.e. if the method has no type parameters, the quick fix introduces them, adds the correct bounds to them, and augments the existing parameter types with the type variables using the information from the parent declaration.
This entry also takes into account the fact that the type parameters may have different names in the overriding method than in the original declaration.
How to test
Try out the quickfixes by invoking quickfix (Ctrl+1) in the snippet from the linked issue.
Also check out the snippets from the test cases, which go further in depth.
Author checklist