简体   繁体   English

在Eclipse中静态导入

[英]Static import in eclipse

Is there a way to easily import the following builder() method in eclipse? 有没有一种方法可以轻松地在eclipse中导入以下builder()方法?

public class SomeClass {

    public static class SomeClassBuilder {
         public static SomeClassBuilder builder() { ... }

         public SomeClass build() { ... }
    }

    public static void someMethod() { ... }
}

SomeClass someClass = SomeClass.SomeClassBuilder.builder().build();
SomeClass.someMethod();

With IntelliJ you just have to move the cursor on builder() and use the static import shortcut in order to add builder() to the list of static imports. 使用IntelliJ,您只需将光标移动到builder()上并使用静态导入快捷方式,即可将builder()添加到静态导入列表中。 Eclipse seems to be able to static import someMethod() but not builder(). Eclipse似乎能够静态导入someMethod(),但不能静态导入builder()。

On my windows machine I have to select "SomeClass.SomeClassBuilder.builder()", mouse right click, 'y' (copy qualified name), ctrl-v, position the cursor on builder() and ctrl-shift-m: a lot of work. 在我的Windows计算机上,我必须选择“ SomeClass.SomeClassBuilder.builder()”,鼠标右键单击“ y”(复制限定名称),按ctrl-v,将光标置于builder()和ctrl-shift-m上:工作繁重。

Is there any other way to do that? 还有其他方法吗? Any plugin maybe? 可能有插件吗? Thanks 谢谢

That doesn´t work and I don´t know a way to make it happen, but what could make your life a little easier is to add SomeClassBuilder to the Content Assist Favoriters in the Preference menu "Java -> Editor -> Content Assist -> Favorites". 这doesn't工作,我不知道怎样做到这一点,但什么可以让你的生活变得更轻松是添加SomeClassBuilder到内容的偏好菜单的“Java协助Favoriters - >编辑- >内容辅助- >收藏夹”。 After that your builder() method appears on the content assist. 之后,您的builder()方法将出现在内容助手上。 (And the content assist adds the static import for builder() ) (并且内容辅助功能为builder()添加了静态导入)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM