Tools | Intellij IDEA tips for doubling coding efficiency

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:

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:

insert image description here

  • Settings under Settings > Editor > Live Templates:

insert image description here

comment template

  1. 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
  2. The specific parameter settings are shown in the figure below,
    insert image description here
    where paramsthe 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.
insert image description here

/*(详细注释,包含参数,返回值)*/
<template name="des" value="**&#10; * @Description &#10;$params$&#10; * @Return $returns$&#10; * @Author $user$&#10; * @Date $date$ $time$&#10; */" description="详细注释,包含参数,返回值" toReformat="true" toShortenFQNames="true">
  <variable name="params" expression="" defaultValue="groovyScript(&quot;if(\&quot;${_1}\&quot;.length() == 2) {return '';} else {def result=''; def params=\&quot;${_1}\&quot;.replaceAll('[\\\\[|\\\\]|\\\\s]', '').split(',').toList();for(i = 0; i &lt; params.size(); i++) {if(i&lt;(params.size()-1)){result+=' * @Param ' + params[i] + ' : ' + '\\n'}else{result+=' * @Param ' + params[i] + ' : '}}; return result;}&quot;, 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="**&#10; * @Description &#10; * @Author $user$&#10; * @Date $date$ $time$&#10; */" 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="**&#10; * $END$&#10; */" description="空白注释" toReformat="true" toShortenFQNames="true">
  <context>
    <option name="OTHER" value="true" />
  </context>
</template>

print template

  1. System.out.The template of Live Templates.
  2. $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 Enter var2.
    $END$The meaning is that when you finish all varparameters, the cursor stays here.
<template name="sout" value="System.out.println($var1$);&#10;&#10;$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(&quot;$CLASS_NAME$.$METHOD_NAME$&quot;);&#10;&#10;$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$);&#10;&#10;$END$" description="输出方法参数" toReformat="true" toShortenFQNames="true">
  <variable name="FORMAT" expression="groovyScript(&quot;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 ? '' : '\&quot;' + parameters.collect { def prefix = it.name + ' = '; def type = it.type; return type instanceof PsiArrayType ? type.componentType instanceof PsiPrimitiveType ? prefix + '\&quot; + java.util.Arrays.toString(' + it.name + ')' : prefix + '\&quot; + java.util.Arrays.deepToString(' + it.name + ')' : prefix + '\&quot; + ' + it.name }.join(' + \&quot;, ')&quot;, methodParameters())" defaultValue="" alwaysStopAt="false" />
  <context>
    <option name="JAVA_STATEMENT" value="true" />
  </context>
</template>
<template name="soutv" value="System.out.println(&quot;$EXPR_COPY$ = &quot; + $EXPR$);&#10;&#10;$END$" description="输出变量" toReformat="true" toShortenFQNames="true">
  <variable name="EXPR" expression="variableOfType(&quot;&quot;)" defaultValue="&quot;expr&quot;" 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&lt;$var1$&gt; $var2$ = new ArrayList&lt;$var3$&gt;();" 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="/**&#10; * $var1$&#10; */&#10;private int $var2$;&#10;&#10;$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="/**&#10; * $var1$&#10; */&#10;private String $var2$;&#10;&#10;$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 Templatesto , the code is also automatically generated. The difference is that Postfix Completionit is IDEAbuilt-in and cannot be modified or edited.

The actual effect is as follows:
insert image description here

  • Settings > Editor > General >Postfix Completion

insert image description here
In fact, there is nothing to say about this. The commonly used ones are for, fori, forr, iter, field, nnand 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 + 2Bring up IDEA favorites. Right click on the left side of the code Set Bookmarksto 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.

insert image description here

  • 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.

insert image description here

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.
    insert image description here
  • Change the debugging value (SetValue)
    to modify the value of the variable during debugging
    insert image description here

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?
insert image description here

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

insert image description here

  • 查看maven、类图、依赖
    Select the class/pom.xml, right-click > Show Diagram / Show Dependencies shortcut key ( Ctrl+Alt+shift+U)
    Mave dependency diagram
    insert image description here
    Class dependency diagram
    The solid line arrow refers to the inheritance relationship, and the dotted line arrow refers to the interface implementation relationship
    insert image description here
  • 查看类方法调用层次
    Navigae -> Call Hierarchy ( Ctrl+Alt+H) View which methods are called and which ones are called to view the call hierarchy
    insert image description here
  • 查看类的结构体
    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
    insert image description here

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.

Guess you like

Origin blog.csdn.net/u012294515/article/details/104564584