Eclipse优化导入以包含静态导入 [英] Eclipse Optimize Imports to Include Static Imports

查看:95
本文介绍了Eclipse优化导入以包含静态导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有可以让Eclipse自动寻找静态导入?例如,现在我终于升级到了Junit 4,我想可以写:

Is there anyway to get Eclipse to automatically look for static imports? For example, now that I've finally upgraded to Junit 4, I'd like to be able to write:

assertEquals(expectedValue, actualValue);

hit Ctrl + Shift + < > O 并添加Eclipse:

hit Ctrl + Shift + O and have Eclipse add:

import static org.junit.Assert.assertEquals;

也许我要求太多。

推荐答案

我使用的是Eclipse Europa,它也有喜欢的偏好部分:

I'm using Eclipse Europa, which also has the Favorite preference section:


>首选项> Java>编辑器>内容辅助>收藏夹

Window > Preferences > Java > Editor > Content Assist > Favorites

在我的,我有以下条目(添加时,使用新建类型并省略。* ):

In mine, I have the following entries (when adding, use "New Type" and omit the .*):

org.hamcrest.Matchers.*
org.hamcrest.CoreMatchers.*
org.junit.*
org.junit.Assert.*
org.junit.Assume.*
org.junit.matchers.JUnitMatchers.*

除了第三个静态导入之外,所有这些都是。通过将这些作为收藏夹,如果我输入 assertT 并点击 Ctrl + 空格 ,Eclipse提供 assertThat 作为建议,如果我选择它,它将添加适当的静态导入到文件。

All but the third of those are static imports. By having those as favorites, if I type "assertT" and hit Ctrl+Space, Eclipse offers up assertThat as a suggestion, and if I pick it, it will add the proper static import to the file.

这篇关于Eclipse优化导入以包含静态导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆