1. 智能code补全
IntelliJ IDEA 智能code补全functions is 其最强 big features之一, 它可以根据 on under 文智能推荐code, big big improvingDevelopmentefficiency.
1.1 basiccode补全
basiccode补全可以补全class, method, variable名etc.. using fast 捷键Ctrl + 空格可以触发basiccode补全.
1.2 智能code补全
智能code补全比basiccode补全更智能, 它会根据 on under 文filter掉不相关 选项. using fast 捷键Ctrl + Shift + 空格可以触发智能code补全.
1.3 class名补全
class名补全可以补全class 全限定名. using fast 捷键Ctrl + Alt + 空格可以触发class名补全.
1.4 语句补全
语句补全可以补全完整 语句, such asif-else, for循环, while循环etc.. using fast 捷键Ctrl + Shift + Enter可以触发语句补全.
1.5 补全最近using 符号
using fast 捷键Alt + /可以补全最近using 符号, such asvariable名, method名etc..
2. codeformat
codeformat可以使code保持一致 风格, improvingcode readable 性 and 可maintenance性.
2.1 format当 before file
using fast 捷键Ctrl + Alt + L可以format当 before file.
2.2 format选in code
先选in要format code, 然 after using fast 捷键Ctrl + Alt + L可以format选in code.
2.3 自定义codeformat规则
要自定义codeformat规则, 请按照以 under 步骤operation:
- 点击File > Settings (Windows/Linux) or IntelliJ IDEA > Preferences (macOS)
- 选择Editor > Code Style
- 选择要configuration language, such as"Java"
- configurationcode样式规则, such asindent, 换行, 空格etc.
- 点击"Apply" and "OK"保存设置
2.4 import and exportcode样式
你可以import and exportcode样式, 以便 in 不同 project and 团队in共享一致 code风格.
- 点击"management"按钮可以import and exportcode样式
- IntelliJ IDEA in 置了 many 种流行 code样式, such asGoogle, Oracleetc.
3. coderefactor
coderefactor is 指 in 不改变codefunctions before 提 under , optimizationcodestructure, improvingcode readable 性 and 可maintenance性. IntelliJ IDEAproviding了强 big coderefactorfunctions.
3.1 rename
rename可以renamevariable, method, class, packageetc.. using fast 捷键Shift + F6可以触发renameoperation.
3.2 提取method
提取method可以将一段重复 code提取 for 一个独立 method. using fast 捷键Ctrl + Alt + M可以触发提取methodoperation.
3.3 提取variable
提取variable可以将一个表达式提取 for 一个variable. using fast 捷键Ctrl + Alt + V可以触发提取variableoperation.
3.4 提取常量
提取常量可以将一个硬编码 值提取 for 一个常量. using fast 捷键Ctrl + Alt + C可以触发提取常量operation.
3.5 提取字段
提取字段可以将一个局部variable提取 for class 字段. using fast 捷键Ctrl + Alt + F可以触发提取字段operation.
3.6 in 联
in 联可以将method调用replace for method体, or 者将variablereplace for 其值. using fast 捷键Ctrl + Alt + N可以触发 in 联operation.
3.7 move and copy
move and copy可以move or copyclass, method, 字段etc.. using fast 捷键F6可以触发moveoperation, using fast 捷键Ctrl + F5可以触发copyoperation.
3.8 更改methodsignature
更改methodsignature可以modifymethod 名称, parameter, 返回class型etc.. using fast 捷键Ctrl + F6可以触发更改methodsignatureoperation.
4. code生成
IntelliJ IDEA可以自动生成一些常用 code, such asconstructmethod, getter/settermethod, toStringmethodetc., improvingDevelopmentefficiency.
4.1 生成constructmethod
要生成constructmethod, 请按照以 under 步骤operation:
- in classin right 键点击
- 选择"Generate" > "Constructor"
- 选择要package含 字段
- 点击"OK"
4.2 生成getter/settermethod
要生成getter/settermethod, 请按照以 under 步骤operation:
- in classin right 键点击
- 选择"Generate" > "Getter and Setter"
- 选择要生成getter/settermethod 字段
- 点击"OK"
4.3 生成toStringmethod
要生成toStringmethod, 请按照以 under 步骤operation:
- in classin right 键点击
- 选择"Generate" > "toString()"
- 选择要package含 字段 and 格式
- 点击"OK"
4.4 生成equals and hashCodemethod
要生成equals and hashCodemethod, 请按照以 under 步骤operation:
- in classin right 键点击
- 选择"Generate" > "equals() and hashCode()"
- 选择要package含 字段 and implementation方式
- 点击"OK"
4.5 生成overridemethod
要生成overridemethod, 请按照以 under 步骤operation:
- in classin right 键点击
- 选择"Generate" > "Override Methods"
- 选择要override method
- 点击"OK"
4.6 生成implementmethod
要生成implementmethod, 请按照以 under 步骤operation:
- in classin right 键点击
- 选择"Generate" > "Implement Methods"
- 选择要implement method
- 点击"OK"
4.7 usingLive Templates
Live Templates is acode模板, 可以 fast 速生成常用 code片段. 例such as, 输入"psvm"然 after 按Tab键可以生成mainmethod, 输入"sout"然 after 按Tab键可以生成System.out.println()语句.
你可以throughFile > Settings > Editor > Live Templates来自定义Live Templates.
5. codeanalysis and check
IntelliJ IDEA in 置了强 big codeanalysis and checkfunctions, 可以helping你发现 and 修复codein issues.
5.1 实时codecheck
IntelliJ IDEA会实时checkcodein 语法error, warning and 建议, 并 in 编辑器in显示相应 标记.
5.2 codecheck结果窗口
using fast 捷键Alt + 6可以打开codecheck结果窗口, 查看所 has codeissues.
5.3 runcodecheck
点击analysis > Inspect Code可以runcodecheck, check整个project or specific Table of Contents.
5.4 quick fix
for 于 big many 数codeissues, IntelliJ IDEA都providing了quick fix选项. using fast 捷键Alt + Enter可以查看 and applicationquick fix.
5.5 code异味检测
IntelliJ IDEA可以检测codein 异味, such as重复code, 过 long method, 过 big classetc., 并providingrefactor建议.
6. advanced编辑functions
IntelliJ IDEA还providing了许 many advanced编辑functions, improvingDevelopmentefficiency.
6.1 how heavy选择
how heavy选择可以同时编辑 many 个位置 code. using fast 捷键Alt + 点击可以添加how heavy选择, using fast 捷键Ctrl + Alt + Shift + J可以选择所 has 匹配 文本.
6.2 列编辑模式
列编辑模式可以按列编辑code. using fast 捷键Shift + Alt + 鼠标拖动可以进入列编辑模式, or 者using fast 捷键Alt + Shift + Insert切换列编辑模式.
6.3 codefold
codefold可以fold and unfoldcode块, improvingcode readable 性. using fast 捷键Ctrl + -可以fold当 before code块, using fast 捷键Ctrl + +可以unfold当 before code块, using fast 捷键Ctrl + Shift + -可以fold所 has code块, using fast 捷键Ctrl + Shift + +可以unfold所 has code块.
6.4 书签
书签可以标记 important code位置, 方便 fast 速导航. using fast 捷键F11可以添加 or delete书签, using fast 捷键Shift + F11可以查看所 has 书签.
6.5 跳转 to 定义
using fast 捷键Ctrl + 鼠标点击 or Ctrl + B可以跳转 to 符号 定义位置.
6.6 find用法
using fast 捷键Alt + F7可以find符号 所 has 用法.
6.7 查看inheritance层次structure
using fast 捷键Ctrl + H可以查看class inheritance层次structure.
6.8 查看method调用层次structure
using fast 捷键Ctrl + Alt + H可以查看method 调用层次structure.
实践练习
请按照以 under 步骤completion练习:
- creation一个 new Javaclass, 命名 for "Person", package含name, age, email字段
- usingcode生成functions生成constructmethod, getter/settermethod, toStringmethod, equals and hashCodemethod
- creation一个testclass, using智能code补全functionswritingtestcode
- usingcodeformatfunctionsformatcode
- 尝试usingrefactorfunctions, such asrename, 提取method, in 联etc.
- usingLive Templates生成一些常用 code片段
- usingcodecheckfunctionscheckcodein issues, 并usingquick fixfunctions修复它们