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

[ BUG ] NestedClasses are not AutoImported #2154

Open
deekshithanand opened this issue Oct 10, 2021 · 3 comments
Open

[ BUG ] NestedClasses are not AutoImported #2154

deekshithanand opened this issue Oct 10, 2021 · 3 comments

Comments

@deekshithanand
Copy link

deekshithanand commented Oct 10, 2021

Nested Clasess are not Imported

When nested classes are referenced within the classfile, a quick fix suggestionto import the nested class is show( to resolve the Nested class symbol). However, the quick fix simply doesnt import the shown fix.

Environment
  • Operating System: Manjaro Linux
  • JDK version: OpenJDK 11
  • Visual Studio Code version:1.61.0
  • Java extension version: 0.82.0
Steps To Reproduce
  1. Create class file like below.
package com.dstyle.demo.resource;

import java.util.Iterator;

public class Example implements Iterable<Nested>{
    public class Nested{}

    @Override
    public Iterator<com.dstyle.demo.resource.Nested> iterator() {
        // TODO Auto-generated method stub
        return null;
    }
}
  1. Now try to resolved the Nested class.

[Please attach a sample project reproducing the error]
Please attach logs
Log File:
ls.log

Current Result

A suggestion to Import nested class is shown, however quick fix doesnt import the nested class

Expected Result

The Nested class should be able to imported

Additional Informations

Gif demonstrating the issue:

simplescreenrecorder-2021-10-10_19 34 19

@fbricon
Copy link
Collaborator

fbricon commented Oct 12, 2021

I can reproduce the issue in Eclipse IDE. Actually, the quickfix is wrong, you should not have to import the Nested class, as it's already inside the current one. The fix should be to change the code to public class Example implements Iterable<Example.Nested>.

Bug was reported upstream (https://bugs.eclipse.org/bugs/show_bug.cgi?id=321464) but incorrectly closed as won't fix (cc @rgrunber @jjohnstn)

@jjohnstn
Copy link

Hi Fred. I reopened the bug and posted a patch for 4.22 M2.

@deekshithanand
Copy link
Author

deekshithanand commented Oct 23, 2021

you should not have to import the Nested class,

Totally agreed @fbricon . Nested class needs to be accessed using parent class. But I see, that if you are referring the nested class/interface outside the class(lets say using a decorator) and compiler still allows to import nested class, the java extension behaves the same way.(Suggests to import the nested class but clicking on it will not import it).

For ex something like below, since nestedclass HystrixclientFallbackfactory class is referenced outside the class, an import scenario might arise. Personally am against this kind of usage, but I have seen people using it, and the language server simply doesnt import it properly at the moment.


 @FeignClient(name = "hello", fallbackFactory = HystrixClientFallbackFactory.class)
protected interface HystrixClient {
	@RequestMapping(method = RequestMethod.GET, value = "/hello")
	Hello iFailSometimes();

@Component
static class HystrixClientFallbackFactory implements FallbackFactory<HystrixClient> {
	@Override
	public HystrixClient create(Throwable cause) {
		return new HystrixClient() {
			@Override
			public Hello iFailSometimes() {
				return new Hello("fallback; reason was: " + cause.getMessage());
			}
		};
	}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants