Eclipse 和 IntelliJ IDEA 都提供了写代码的辅助功能,包括代码补全、代码生成、快速修饰和动态模板等功能。intellij-idea
1. 快速修复(Quick-fixes)编辑器
快捷键:Alt+Enteride
全部的快速修复都是基于 Settings | Editor | Inspections 中的选项进行提示。函数
批量修复post
若是须要一次多多个地方进行修复,如整个目录(folder)、一个模块(module)或整个项目(project),能够使用下面两个功能:ui
Eclipseidea |
|
IntelliJ IDEAspa |
|
Action3d |
Shortcutcode |
Action |
Shortcut |
Quick fix |
Ctrl+1 |
Show intention action |
Alt+Enter |
2. 生成代码(Generating code)
生成代码操做:Code | Generate (Alt+Insert)
该操做不只能够在编辑器中使用,在项目窗口和导航栏也能够使用:
此时用于新建文件或包。
3. 代码补全(Code completion)
IntelliJ IDEA提供了多种类型的代码补全功能,包括:
对于这些补全功能的详细描述,能够参考文章:
https://dzone.com/articles/top-20-code-completions-in-intellij-idea
IDEA默认不显示选择项的文档,不过能够经过以下设置启用:
不过不建议启用,在须要时,能够用Ctrl+Q快捷键调用,如此能够看到对应方法的文档,以下:
当光标在构造函数或方法的括号中,经过 Ctrl+P 能够看到参数信息:
如图,StringReader只有一个构造函数,接受字符串参数。
Eclipse |
|
IntelliJ IDEA |
|
Action |
Shortcut |
Action |
Shortcut |
Code completion |
Ctrl+Space |
Basic completion |
Ctrl+Space |
- |
- |
Smart completion |
Ctrl+Shift+Space |
- |
- |
Statement completion |
Ctrl+Shift+Enter |
使用方法:输入触发字符串,按Tab键,以下:
IDEA的模板触发方式和Eclipse稍有不一样,以下:
Template |
Eclipse |
IntelliJ IDEA |
Define a main method |
main |
psvm |
Iterate over an array |
for |
itar |
Iterate over a collection |
for |
itco |
Iterate over a list |
for |
itli |
Iterate over an iterable using foreach syntax |
foreach |
iter |
Print to System.out |
sysout |
sout |
Print to System.err |
syserr |
serr |
Define a static field |
static_final |
psf |
可用模板列表: Settings | Editor | Live Templates
除了这种常规模板,还有一些其余形式的模板。
后缀模板(postfix templates)
可用后缀模板列表:Settings | Editor | General | Postfix Completion
包含式动态模板(Surround with live template)
快捷键:Ctrl+Alt+J
和上面不一样,此时按 Enter 键选择