在Intellij中的自动静态导入
在以下代码中,我使用class名称导入Intellij Idea 2022 Community Edition中的静态方法,
BDDMockito.given(employeeRepository.findByEmail(employee.getEmail()))
.willReturn(Optional.empty());
BDDMockito.given(employeeRepository.save(employee)).willReturn(employee);
是否有任何方法或键盘快捷键可以删除类名称并使用类似的静态导入:
import static org.mockito.BDDMockito.given;
given(employeeRepository.findByEmail(employee.getEmail()))
.willReturn(Optional.empty());
given(employeeRepository.save(employee)).willReturn(employee);
我搜索了lot lot并阅读Intellij文章,但无法找到任何解决方案。任何Intellij专家都可以在这里帮助我吗?
In below piece of code I have used Class name to import static methods in IntelliJ IDEA 2022 Community Edition
BDDMockito.given(employeeRepository.findByEmail(employee.getEmail()))
.willReturn(Optional.empty());
BDDMockito.given(employeeRepository.save(employee)).willReturn(employee);
Is there any way or keyboard shortcut that can remove the class name and use static import like this:
import static org.mockito.BDDMockito.given;
given(employeeRepository.findByEmail(employee.getEmail()))
.willReturn(Optional.empty());
given(employeeRepository.save(employee)).willReturn(employee);
I googled lot and read IntelliJ articles but could not find any solution. Any IntelliJ expert can help me here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将Caret放在方法名称上,按“ alt+Enter”,然后选择“添加静态导入...”
You may put caret on method name, press "Alt+Enter" and select "Add static import for ..."
您可以将IDE配置为使用
*
自动导入静态功能/var。这是这样做的方法:
设置 - >编辑 - >代码样式 - > Java->导入(TAB)
它将导致
*
导入,您可能不希望此效果。但是我不知道其他任何方式。这种方法的好处是,这些功能将用于自动完成,这使您的生活更轻松:)
You can configure your IDE to automatically import static functions/vars from specific packages with
*
.This is the way to do it:
Settings -> Editor -> Code Style -> Java -> Imports (tab)
It will result in a
*
import though and you may not want this effect. But I do not know of any other way.The good thing about this method is that the functions will be available for auto completion and that makes your life easier :)