Eclipse的隐藏功能

97

好的,这可能是一个简单的问题,但每个人使用这些工具的方式都不同。那么,有哪些在这个集成开发环境中最好的时间节省工具呢?

汤姆

73个回答

14

目前还没有提到最好的方法。点击类或方法名称,然后按Ctrl+T键。

您将获得快速类型层次结构。对于类名,您将看到整个类层次结构。对于方法名,您将获得显示超类和子类的层次结构,其中该方法的实现与抽象提及或不提及该方法的类有所区别。

当您处于抽象方法声明位置并且想快速查看其实现位置时,此功能非常重要。


哈,我正想添加这个 - 当处理使用接口的代码库时非常有用! - Darren Greaves
在类中按F4键,它会在选项卡中列出层次结构。 - Ravisha

13

F3一直是我最喜欢的快捷键,可以打开所选项的定义。

Ctrl+Shift+R有一个有趣的功能,在搜索时只需要使用类名中的大写驼峰字母(比如输入CWAR将显示ClassWithAReallyLongName的结果)。

Alt+Shift+W > Package Explorer在浏览大型项目时可以更轻松地浏览。


1
那个驼峰命名法的技巧在编写代码时也适用。在编辑器中键入CWAR,然后按CTRL-Space,它将扩展为ClassWithAReallyLongName。如果还没有,我将把它作为一个单独的提示添加进去。 - Darren Greaves
驼峰命名法技巧同样适用于Ctrl+Shift+T对话框,我发现它非常有用,如果我知道它们的名称,我就不再导航到类了。这也是那些让你的伙伴在配对时惊叹“哇!你是怎么做到的?”的技巧之一。 - banjollity
刚才我在想是否有一种快捷方式可以让包资源管理器上来,而不必点击最小化的图标。谢谢这个 :-) - guyumu
F3的替代方法:按住Control键并单击类、函数或变量,即可跳转到其声明。这也适用于Javadoc @link标签;当您将光标悬停在可点击元素上时,它们会被下划线标记。 - cthulhu

10

异常断点

Eclipse允许你根据异常发生的位置设置断点。
你可以通过调试窗口中的"j!" alt text http://help.eclipse.org/stable/topic/org.eclipse.jdt.doc.user/images/org.eclipse.jdt.debug.ui/elcl16/exc_catch.png图标访问此选项。

alt text http://blogs.bytecode.com.au/glen/2007/04/06/images/2007/AddExceptionWindow.png

官方帮助主题"添加Java异常断点"对此进行了更多说明。

  • 未捕获的异常选项是为了在未捕获的位置抛出与断点相同类型的异常时暂停执行。
  • 已捕获的异常选项是为了在捕获的位置抛出与断点相同类型的异常时暂停执行。
  • 不要忘记异常断点挂起此异常的子类
    当遇到异常类型的子类时暂停执行。
    例如,如果为RuntimeException配置了异常断点以在子类上挂起,则也会因NullPointerException而触发。

alt文本 http://help.eclipse.org/stable/topic/org.eclipse.jdt.doc.user/reference/breakpoints/images/ref-breakpoint_suspendsubclass.PNG

这是一个链接到图片的HTML标记。

10

一种非键盘快捷方式是在“团队”->“同步”视图中使用提交集来组织您的更改,然后再进行提交。

将一个变更集设置为默认值,您所做的所有文件更改都将放入该集合中,这样就可以很容易地查看您在修复特定缺陷/功能和测试等过程中所做的更改以及其他更改。


10

CTRL+SPACE,无论何时何地都可以使用。

生成getter和setter方法。

使用字段创建构造函数

提取方法...

重构->重命名

CTRL+O快速查看大纲。CTRL+O+CTRL+O查看继承的大纲。

F4显示类型层次结构

打开调用层次结构以显示方法被调用的位置。

CTRL+SHIFT+T打开Java类型

CTRL+SHIFT+R打开任何资源。

ALT +左或右向前或向后浏览文档中的编辑位置(轻松导航)

如果您知道要执行很多方法,请覆盖/实现方法(否则,对于一次选择,CTRL+SPACE更好)。

重构->提取接口

重构->上移

重构->下移

CTRL+SHIFT+O组织导入(当输入Map等一般类名时,按CTRL+SPACE,然后选择适当的类将直接为您导入它)。

CTRL+SHIFT+F格式化(尽管Eclipse内置的格式化器对长行代码有点愚蠢)

编辑:哦,是的,还有一些调试:

F5:逐步进入(显示细节!)

F6:步骤(跳过这一部分...)

F7:跳出(我认为我关心这个方法,但事实证明我不关心,让我走吧!)

F8:恢复(直到达到下一个断点)

CTRL+SHIFT+I:检查表达式。CTRL+SHIFT+I+CTRL+SHIFT+I:在检查的表达式上创建监视表达式。

条件断点:右键单击断点,您可以设置触发程序执行停止的条件(此处提供Ctrl+Space的上下文辅助!)

F11 - 调试最后启动(应用程序)

CTRL+F11 - 运行最后启动(应用程序)


9

Ctrl+Alt+UPCtrl+Alt+DOWN可复制多行内容。


14
除非被您的视频驱动程序拦截,否则您会遇到屏幕倒置的问题。 - Adam Jaskiewicz
呃,该死的联想工作站 :) - guyumu

9

按下Ctrl+Alt+H可以获取方法的调用层次结构,快速查看其被哪些地方调用。


8

使用 Alt + Shift + R 快捷键进行重构和重命名。


1
Alt+Shift+R是重构->重命名的快捷键。Eclipse中还有其他几个重构快捷键。 - MetroidFan2002

7

以下是我收集的Eclipse 3最有用的键盘快捷键:

Eclipse 3 Favorite Keyboard Shortcuts. 
by -=MaGGuS=-

Navigate:

•   Ctrl + Shift + L – Shows useful keyboard shortcuts in popup window 
•   Ctrl + H – Search.
•   Ctrl + K – Goes to next search match in a single file. Shift + Ctrl + K – goes to previous match.
•   F3 - Goes to ‘declaration’ of something. Same as Ctrl + Click.
•   Ctrl + Shift + G - Use this on a method name or variable. It will search for references in the code (all the code) to that item.
•   Ctrl + O – Shows outline view of the current class or interface.
•   Ctrl + T – Shows class hierarchy of the current class or interface. F4 – shows the same in separate tab.
•   Ctrl + Shift + T - Open Type. Search for any type globally in the workspace.
•   Ctrl + Shift + R – Open Resource. Search for any file inside workspace.
•   Ctrl + J – Incremental search. Similar to the search in firefox. It shows you results as you type. Shift + Ctrl +J - Reverse incremental search.
•   Ctrl + Q – Goes to the last edit location.
•   Ctrl + Left|Right – Go Back/Forward in history.
•   Ctrl + L – Go to line number.
•   Ctrl + E – This will give you a list of all the source code windows that are currently open. You can arrow up or down on the items to go to a tab.
•   Ctrl +PgUp|PgDown – Cycles through editor tabs.
•   Ctrl + Shift + Up|Down - Bounces you up and down through the methods in the source code.
•   Ctrl + F7 – Switches between panes (views).
•   Ctrl + ,|. – Go to the previous/next error. Great in combination with Ctrl + 1.
•   Ctrl + 1 on an error – Brings up suggestions for fixing the error. The suggestions can be clicked.
•   Ctrl + F4 – Close one source window.

Edit:

•   Ctrl + Space – Auto-completion.
•   Ctrl + / – Toggle comment selected lines.
•   Ctrl + Shift + /|\ – Block comment/uncomment selected lines.
•   Ctrl + Shift + F – Quickly ‘formats’ your java code based on your preferences set up under Window –> Preferences.
•   Ctrl + I – Correct indentations.
•   Alt + Up|Down – move the highlighted code up/down one line. If nothing is selected, selects the current line.
•   Ctrl + D – Delete row.
•   Alt + Shift + Up|Down|Left|Right – select increasing semantic units.
•   Ctrl + Shift + O – Organize Imports.
•   Alt + Shift + S – Brings up “Source” menu.
o   Shift + Alt + S, R – Generate getter/setter.
o   Shift + Alt + S, O – Generate constructor using fields.
o   Shift + Alt + S, C – Generate constructor from superclass.
•   Alt + Shift + T – Brings up “Refactor” menu.
•   Alt + Shift + J – Insert javadoc comment.
•   F2 – Display javadoc popup for current item. Shift + F2 – Display javadoc in external browser.

Run/Debug:

•   F11 / Ctrl + F11 – Execute/debug.
•   Ctrl + Shift +B – Toggle breakpoint.
•   When paused: F5 – Step into, F6 – Step over, F7 – Step out, F8 – Resume.
•   Ctrl + F2 – Terminate.

EOF

7

并不是很难懂,但我认为这是最好的技巧。

假设默认设置(且您没有添加新片段)

高亮(或选择)文本(字符串或变量)…按Ctrl+Space。 然后按End+Enter键, 将触发“sysout”片段,它将所选内容包裹在其参数中。

例如:

 "hello world!"

becomes
System.out.println("hello world!");

我非常喜欢它,以至于我已经为Android的Toast和Log.i()实现了类似的代码片段 在手动调试期间节省了大量时间....


哇,我怎么不知道这个?谢谢! - Tyler
嗯,当我按下“End”键时,它只会跳到所选字符串的结尾,而不是建议列表的结尾。 - serg
也许在到达结尾之前,你应该多按一次“向下”键... :( - st0le

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接