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

Quickfix for return type that's a wildcard doesn't work post 1.4 #1558

Closed
datho7561 opened this issue Jul 29, 2024 · 1 comment · Fixed by #1559
Closed

Quickfix for return type that's a wildcard doesn't work post 1.4 #1558

datho7561 opened this issue Jul 29, 2024 · 1 comment · Fixed by #1559

Comments

@datho7561
Copy link
Contributor

The quickfix to fix the return type in the following code doesn't work.

import java.lang.reflect.AccessibleObject;

public class WeirdAnonymousThingy {
	
	@Override
	public void m() {
		new AccessibleObject() {
			public void getAnnotation(Class annotationClass) {
				
			}
		};
	}
}

It's a particular nasty edge case: this anonymous class inherits a method that has a method-level type parameter with a bound set, and the return type is that type variable. (see the javadoc for AccessibleObject.getAnnotation)

Pre-1.5, the erasure of the type variable is calculated as the value that void gets replaced with. Post 1.5, the type variable is inserted in place of void, which results in invalid code, since the type variable is declared in the override implementation.

I think that ideally this quickfix should provide two options:

  1. Returning a type variable (and properly declaring it)
  2. Returning the erasure of the type variable
@datho7561
Copy link
Contributor Author

I started working on this; doing 1. is pretty easy, doing 2. is a bit more involved.

datho7561 added a commit to datho7561/eclipse.jdt.ui that referenced this issue Jul 30, 2024
The old method would propose the erasure of the type param if the
compliance was set pre 1.5.
If the compliance

Instead, now two quickfixes are always propose:
1. Replace the return type with the erasure
2. Introduce a new type param with the same bounds,
   importing the bounds and adding the type variable for any raw types

Fixes eclipse-jdt#1558

Signed-off-by: David Thompson <[email protected]>
datho7561 added a commit to datho7561/eclipse.jdt.ui that referenced this issue Jul 30, 2024
The old method would propose the erasure of the type param if the
compliance was set pre 1.5.
If the compliance

Instead, now two quickfixes are always propose:
1. Replace the return type with the erasure
2. Introduce a new type param with the same bounds,
   importing the bounds and adding the type variable for any raw types

Fixes eclipse-jdt#1558

Signed-off-by: David Thompson <[email protected]>
datho7561 added a commit to datho7561/eclipse.jdt.ui that referenced this issue Jul 31, 2024
The old method would propose the erasure of the type param if the
compliance was set pre 1.5.
If the compliance

Instead, now two quickfixes are always propose:
1. Replace the return type with the erasure
2. Introduce a new type param with the same bounds,
   importing the bounds and adding the type variable for any raw types

Fixes eclipse-jdt#1558

Signed-off-by: David Thompson <[email protected]>
datho7561 added a commit to datho7561/eclipse.jdt.ui that referenced this issue Jul 31, 2024
The old method would propose the erasure of the type param if the
compliance was set pre 1.5.
If the compliance

Instead, now two quickfixes are always propose:
1. Replace the return type with the erasure
2. Introduce a new type param with the same bounds,
   importing the bounds and adding the type variable for any raw types

Fixes eclipse-jdt#1558

Signed-off-by: David Thompson <[email protected]>
datho7561 added a commit to datho7561/eclipse.jdt.ui that referenced this issue Jul 31, 2024
The old method would propose the erasure of the type param if the
compliance was set pre 1.5.
If the compliance

Instead, now two quickfixes are always propose:
1. Replace the return type with the erasure
2. Introduce a new type param with the same bounds,
   importing the bounds and adding the type variable for any raw types

Fixes eclipse-jdt#1558

Signed-off-by: David Thompson <[email protected]>
datho7561 added a commit to datho7561/eclipse.jdt.ui that referenced this issue Jul 31, 2024
The old method would propose the erasure of the type param if the
compliance was set pre 1.5.
If the compliance

Instead, now two quickfixes are always propose:
1. Replace the return type with the erasure
2. Introduce a new type param with the same bounds,
   importing the bounds and adding the type variable for any raw types

Fixes eclipse-jdt#1558

Signed-off-by: David Thompson <[email protected]>
datho7561 added a commit to datho7561/eclipse.jdt.ui that referenced this issue Jul 31, 2024
The old method would propose the erasure of the type param if the
compliance was set pre 1.5.
If the compliance

Instead, now two quickfixes are always propose:
1. Replace the return type with the erasure
2. Introduce a new type param with the same bounds,
   importing the bounds and adding the type variable for any raw types

Fixes eclipse-jdt#1558

Signed-off-by: David Thompson <[email protected]>
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 a pull request may close this issue.

1 participant