In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
IDEA Live how to use Template, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
Summarizing the common ways of IDEA Live Template Live template allows you to quickly, efficiently and correctly insert frequently used or custom code snippets. 1. Demo
There are three types of live template: simple type, parameterized type and surround type.
Simple type
A simple type is a fixed code snippet that, when expanded by an acronym, is expanded in the source code. For example, the simplest and most common pdvm expansion is the definition of the main function.
Parameter type
Parameter types are templates with parameters in the code snippet. Parameters are defined with $, such as parameter MY. This $MY$, parameter type is very useful. Many of our custom templates will use parameters, which will be explained later in the configuration.
Surround type
Wrapping templates refers to templates that wrap blocks of code, such as try catch, as well as the callable statements demonstrated below.
The three types of demonstrations are as follows:
As shown in the figure, iterations is the acronym group,fori that comes with idea, and as the name implies, this group is for operations such as iterations.
When using it, we can type 10. Foricharge list.fori or type fori directly and then press the tab key (arrow 7) to insert the code. Idea generates different code snippets according to the context. For example, 10.fori directly generates "for (int I = 0; I)."
< 10; i++) {",而直接输入fori则是"for (int i = 0; i < ; i++) {",注意此时10没有自动生成需要你手动输入。 我们可以点击2处新建自己的template,template的缩略词在同一group内不能重复,所以为了不和自带的键重复我们最好新建自己的一个group比如MY,不同的group中的缩略词可以重复。箭头5是描述用来助记的。 我们来自定义一个如下图:I customized an info (code snippet: "$CLASS$.$METHOD$ linenum:$LINE$, param: {$PARAM$} info:$MY$" $END$), outputting the class name, method name, number of lines, and parameters, which are necessary for logging. The $PARAM$ variable uses the script. / / methodParameters is a predefined function, where the script is in double quotes, and the _ 1 placeholder takes only the methodParameters parameter groovyScript ("_ 1.collect {it +'= [\" >)
About backup and sharing: the live template file is saved in "{user} {version}\ config\ templates". User refers to the user directory, and version is the idea directory. For example, my directory is C:\ Users\ chen.IntelliJIdea2017.3\ config\ templates, where the file name is group. You can also save the configuration by selecting live template in the File- > Export Settings dialog box.
Description: when setting the value of a variable, there is a column Skip if define, which means that if a value is skipped (that is, whether the cursor pauses), the position of the cursor is determined by the order in the variables dialog box, and it can be sorted with the arrow on the right. If all the variables are populated, it jumps to the location of the $END$ variable, and if no $END$ is defined, to the end of the code snippet.
The default shortcut keys for the win platform are three ctrl+j (insert live template), ctrl+alt+j (sround with live template) and ctrl+alt+t (sround with).
Keyboard shortcuts are often used in live template, so you need to remember. Because each platform is different, someone may have modified the shortcut key, so I marked the corresponding name of the shortcut key in parentheses. If your idea shortcut key does not work, you can directly click on the figure to search for the name.
Ctrl+j: insert ordinary live template
Ctrl+alt+j: insert the live template of the package
Ctrl+alt+t: insert the code snippet of the package, which contains ctrl+alt+j but also contains some statements that come with the system, such as if,while, for, and so on.
* * here you need to focus on the code snippet of the package * *, which actually refers to the code you selected with the cursor. Using this code snippet requires us to use the cursor to select and then enter the shortcut keys ctrl+alt+t or ctrl+alt+j to select the desired acronym. In the custom code snippet, there is a built-in $SELECTION$ that refers to the code you selected with the cursor. When you insert the code snippet, the code you selected will be inserted into $SELECTION$. Let's implement a sloge with a wrapper snippet with the following settings:
2.4 actual combat
I have customized several code snippets that are very commonly used, namely
"info": output debugging information
/ / Code snippet "$CLASS$.$METHOD$ ~ linenum:$LINE$, param: {$PARAM$} info:$MY$" $END$ / / variable definition $CLASS$:className () $METHOD$:methodName () $LINE$:lineNumber () $PARAM$:groovyScript ("_ 1.collect {it +'= [\" >
"fen": a comment on the dividing line
/ / Code snippet / *-$E$-* / $END$
"log": define log constants
/ / Code snippet private static final Logger logger= LoggerFactory.getLogger ($CLASS$.class); / / variable definition $CLASS$:className ()
"zhushi": comments with names and dates
/ / Code snippet / / comment-- $USER$-- $D$-> $ANNOTATION$ / / variable definition $USER$: "chenfangzhi" $D$: date ("YYYY-MM-DD hh:mm:ss")
"todo": todo comment
/ / Code snippet / / todoBy$USER$-$D$-> $TODO$ / / variable definition $USER$: "chenfangzhi" $D$: date ("YYYY-MM-DD hh:mm:ss") description: I will not explain the function of todo. Item 4 and item 5 here may be very similar. There are many places that need to mark who is operating. Many current projects are developed by many people, if the default todo is used. It will be very confusing, and then we need to define our own todo comments, and we need to take the name with us. The code snippet can be defined by itself, with both todo and name, so that it can be filtered when viewing the todo list. As shown below:
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.