During the epidemic, I stayed in the house and fiddled with various things. Recently, I have studied IDEA well, after all, I am a guy who eats. If a worker wants to do a good job, he must first sharpen his tools!
Learning path:
-
It is recommended to take a look at the free course " IntelliJ IDEA Artifact Use Skills " of MOOC Flash . It takes about two hours to use IDEA while watching it, and it takes nearly a day. It feels like my sword has begun to strike, and the rest is to master it proficiently. It is definitely a great weapon in work.
-
Intellij Idea Use Tutorial Summary A very comprehensive tutorial summary, bookmark it first!
IDEA menu introduction
menu name | meaning |
---|---|
File | The creation of the project, as well as the settings of the software, import and export, configuration path, etc.; |
Edit | edit, file text editing operations |
View | A view is a window that you can see in your field of view |
Navigate | Navigate, jump in project engineering, quickly find methods |
Code | source code file |
Analyze | Analyze the source code to see the dependencies between classes |
Refactor | Shortcut operations: such as extracting static classes, extracting functions, and extracting abstract methods |
Build | build, compile project |
Run | run, debug |
Tools | Provides some tools, plugin settings, etc. |
CVS | Version control, GIT, SVN |
Window | window, switch project |
Help | help |
Most of the time, I don’t know the shortcut keys. If I know which menu I am in, then click on the menu, and the shortcut keys are written behind the button.
Live Templates
What do you mean Live Templates
? The translation is a dynamic template. According to the template you defined, just type the shortcut abbreviation to generate your preset code.
The actual effect is as follows:
- Settings under Settings > Editor > Live Templates:
comment template
My comment template prompt uses des. In actual use, type one first/
, and then type des to pop up the content of the comment.
Note that the code starts with**
an asterisk, and/
the slash cannot be written in the code, otherwise the parameters will not be loaded in actual use- The specific parameter settings are shown in the figure below,
whereparams
the script is used to analyze
groovyScript("if(\"${_1}\".length() == 2) {return '';} else {def result=''; def params=\"${_1}\".replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList();for(i = 0; i < params.size(); i++) {if(i<(params.size()-1)){result+=' * @Param ' + params[i] + ' : ' + '\\n'}else{result+=' * @Param ' + params[i] + ' : '}}; return result;}", methodParameters());
Copy the following 3 comment templates respectively, and then paste them in Live Templates. See the animation for the operation! ! very convenient
Since the abbreviations of my three comment templates are the same, they need to be copied to different groups. The sum below can be copied 属性模版
and 打印模版
pasted directly.
/*(详细注释,包含参数,返回值)*/
<template name="des" value="** * @Description $params$ * @Return $returns$ * @Author $user$ * @Date $date$ $time$ */" description="详细注释,包含参数,返回值" toReformat="true" toShortenFQNames="true">
<variable name="params" expression="" defaultValue="groovyScript("if(\"${_1}\".length() == 2) {return '';} else {def result=''; def params=\"${_1}\".replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList();for(i = 0; i < params.size(); i++) {if(i<(params.size()-1)){result+=' * @Param ' + params[i] + ' : ' + '\\n'}else{result+=' * @Param ' + params[i] + ' : '}}; return result;}", methodParameters()); " alwaysStopAt="true" />
<variable name="returns" expression="methodReturnType()" defaultValue="" alwaysStopAt="true" />
<variable name="user" expression="user()" defaultValue="" alwaysStopAt="true" />
<variable name="date" expression="date()" defaultValue="" alwaysStopAt="true" />
<variable name="time" expression="time()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="OTHER" value="true" />
</context>
</template>
/*只需要粘贴以下即可(简单注释,无参无返回)*/
<template name="des" value="** * @Description * @Author $user$ * @Date $date$ $time$ */" description="简单注释,无参无返回" toReformat="true" toShortenFQNames="true">
<variable name="user" expression="user()" defaultValue="" alwaysStopAt="true" />
<variable name="date" expression="date()" defaultValue="" alwaysStopAt="true" />
<variable name="time" expression="time()" defaultValue="" alwaysStopAt="true" />
<context>
<option name="OTHER" value="true" />
</context>
</template>
/*只需要粘贴以下即可(空白注释)*/
<template name="des" value="** * $END$ */" description="空白注释" toReformat="true" toShortenFQNames="true">
<context>
<option name="OTHER" value="true" />
</context>
</template>
print template
System.out.
The template ofLive Templates
.$var1$
It means that when the code appears, the cursor will stay here, and you can input your content directly by typing on the keyboard, and the cursor will move to the next one after pressing Entervar2
.
$END$
The meaning is that when you finish allvar
parameters, the cursor stays here.
<template name="sout" value="System.out.println($var1$); $END$" description="System.out.println" toReformat="true" toShortenFQNames="true">
<variable name="var1" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
<template name="soutm" value="System.out.println("$CLASS_NAME$.$METHOD_NAME$"); $END$" description="输出类名和方法名" toReformat="true" toShortenFQNames="true">
<variable name="CLASS_NAME" expression="className()" defaultValue="" alwaysStopAt="false" />
<variable name="METHOD_NAME" expression="methodName()" defaultValue="" alwaysStopAt="false" />
<context>
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
<template name="soutp" value="System.out.println($FORMAT$); $END$" description="输出方法参数" toReformat="true" toShortenFQNames="true">
<variable name="FORMAT" expression="groovyScript("import com.intellij.psi.*;import com.intellij.psi.util.PsiTreeUtil; def file = PsiDocumentManager.getInstance(_editor.project).getPsiFile(_editor.document); PsiMethod method = PsiTreeUtil.findElementOfClassAtOffset(file, _editor.caretModel.offset, PsiMethod.class, false); PsiParameter[] parameters = method == null ? PsiParameter.EMPTY_ARRAY : method.parameterList.parameters; return parameters.size() == 0 ? '' : '\"' + parameters.collect { def prefix = it.name + ' = '; def type = it.type; return type instanceof PsiArrayType ? type.componentType instanceof PsiPrimitiveType ? prefix + '\" + java.util.Arrays.toString(' + it.name + ')' : prefix + '\" + java.util.Arrays.deepToString(' + it.name + ')' : prefix + '\" + ' + it.name }.join(' + \", ')", methodParameters())" defaultValue="" alwaysStopAt="false" />
<context>
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
<template name="soutv" value="System.out.println("$EXPR_COPY$ = " + $EXPR$); $END$" description="输出变量" toReformat="true" toShortenFQNames="true">
<variable name="EXPR" expression="variableOfType("")" defaultValue=""expr"" alwaysStopAt="true" />
<variable name="EXPR_COPY" expression="escapeString(EXPR)" defaultValue="" alwaysStopAt="false" />
<context>
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
attribute template
The operation is the same as above, just copy and paste~~~
<template name="li" value="List<$var1$> $var2$ = new ArrayList<$var3$>();" description="ArrayList" toReformat="false" toShortenFQNames="false">
<variable name="var1" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="var2" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="var3" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="GROOVY_DECLARATION" value="true" />
<option name="GROOVY_STATEMENT" value="true" />
<option name="JAVA_DECLARATION" value="true" />
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
<template name="pri" value="private int $var1$;" description="private int" toReformat="false" toShortenFQNames="false">
<variable name="var1" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="GROOVY_DECLARATION" value="true" />
<option name="GROOVY_STATEMENT" value="true" />
<option name="JAVA_DECLARATION" value="true" />
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
<template name="pric" value="/** * $var1$ */ private int $var2$; $END$" description="private int 带注释" toReformat="false" toShortenFQNames="false">
<variable name="var1" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="var2" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="GROOVY_DECLARATION" value="true" />
<option name="GROOVY_STATEMENT" value="true" />
<option name="JAVA_DECLARATION" value="true" />
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
<template name="prs" value="private String $var1$;" description="private String" toReformat="false" toShortenFQNames="false">
<variable name="var1" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="GROOVY_DECLARATION" value="true" />
<option name="GROOVY_STATEMENT" value="true" />
<option name="JAVA_DECLARATION" value="true" />
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
<template name="prsc" value="/** * $var1$ */ private String $var2$; $END$" description="private String 带注释" toReformat="false" toShortenFQNames="false">
<variable name="var1" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="var2" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="GROOVY_DECLARATION" value="true" />
<option name="GROOVY_STATEMENT" value="true" />
<option name="JAVA_DECLARATION" value="true" />
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
<template name="psfi" value="public static final int $var1$ = $var2$;" description="public static final int" toReformat="false" toShortenFQNames="false">
<variable name="var1" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="var2" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="GROOVY_DECLARATION" value="true" />
<option name="JAVA_DECLARATION" value="true" />
</context>
</template>
<template name="psfs" value="public static final String $var1$ = $var2$;" description="public static final String" toReformat="false" toShortenFQNames="false">
<variable name="var1" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="var2" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="GROOVY_DECLARATION" value="true" />
<option name="JAVA_DECLARATION" value="true" />
</context>
</template>
<template name="pui" value="public int $var1$;" description="public int" toReformat="false" toShortenFQNames="false">
<variable name="var1" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="GROOVY_DECLARATION" value="true" />
<option name="GROOVY_STATEMENT" value="true" />
<option name="JAVA_DECLARATION" value="true" />
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
<template name="pus" value="public String $var1$;" description="public String" toReformat="false" toShortenFQNames="false">
<variable name="var1" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="GROOVY_DECLARATION" value="true" />
<option name="GROOVY_STATEMENT" value="true" />
<option name="JAVA_DECLARATION" value="true" />
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
<template name="st" value="String $var1$ = $var2$;" description="String" toReformat="false" toShortenFQNames="false">
<variable name="var1" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="var2" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="GROOVY_DECLARATION" value="true" />
<option name="GROOVY_STATEMENT" value="true" />
<option name="JAVA_DECLARATION" value="true" />
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
Postfix Completion
Similar Live Templates
to , the code is also automatically generated. The difference is that Postfix Completion
it is IDEA
built-in and cannot be modified or edited.
The actual effect is as follows:
- Settings > Editor > General >Postfix Completion
In fact, there is nothing to say about this. The commonly used ones are for
, fori
, forr
, iter
, field
, nn
and so on.
The specific usage can be found in the instructions, and you can check it out and use it. Just know there is such a thing~~~
Collection, bookmark function
ALT + 2
Bring up IDEA favorites. Right click on the left side of the codeSet Bookmarks
to bookmark the current line of code.- Set bookmark with mnemonic Set the serial number for the label, and then you can directly enter
Ctrl + 序号
the label corresponding to the jump, which is very helpful for reading the source code.
- Add to Favorites (
Alt+Shift+F
) Add to favorites, refers to the favorites of the current file. For the well-written code, or the code that is going to go back and read carefully, it is a collection.
debugging
Debugging code is usually one of the functions we use the most. But do you know the following two functions?
- Conditional breakpoints
are generally used in loops and judgments. When the set value is met, the breakpoint will be entered.
- Change the debugging value (SetValue)
to modify the value of the variable during debugging
Git
Git is our version control tool, and my friends usually use it a lot. There is also a small function here, do you know?
structure diagram
It is simply a great tool for reading code! ! Proper use of this function will allow you to read the source code of the framework handy.
查看当前类 Field Method大纲
The shortcut keys for Navigae -> File Structure vary from person to person. I use the shortcut keys of Eclipse so it isCtrl+F3/Ctrl+O
查看maven、类图、依赖
Select the class/pom.xml, right-click > Show Diagram / Show Dependencies shortcut key (Ctrl+Alt+shift+U
)
Mave dependency diagram
Class dependency diagram
The solid line arrow refers to the inheritance relationship, and the dotted line arrow refers to the interface implementation relationship
查看类方法调用层次
Navigae -> Call Hierarchy (Ctrl+Alt+H
) View which methods are called and which ones are called to view the call hierarchy
查看类的结构体
After entering a class, if you want to quickly view other methods of the class, you can also use the structure function provided by IDEA, shortcut keysAlt+7
After mastering the use of the above structural diagrams, it is not easy to check the source code and understand the framework? ?
Plug-in recommendation
-
Key promoterX ★★★★★
Shortcut key prompt plug-in, click a function with the mouse multiple times, and the shortcut key will be prompted in the lower right corner -
Statistic ★★★★
counts the number of lines of code in the project -
JRebel Plugin ★★★★
Hot deployment plug-in, every time IDEA changes the code, it needs to be restarted to take effect. But it is said that this software charges, how to crack Baidu by itself.