Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the live templates for Java in Intellij-IDEA?

No Java

I could not find the live templates for Java! Who can tell me how to set? Thanks.

like image 704
noodles Avatar asked Nov 15 '13 06:11

noodles


3 Answers

They're inside all the nodes that are not specific to another language than Java: iterations, output, plain, surround, etc.

like image 105
JB Nizet Avatar answered Nov 14 '22 09:11

JB Nizet


As JB Nizet wrote there is not a special node for Java (but you can create one). If you want your own Live Template for Java created do the following.

  1. Open Settings window (File -> Settings)

  2. Click on Editor -> Live Templates

  3. Choose Template Group in which you want to add your Live Template (you can create your own Template Group if you wish)

  4. Click on + icon and choose Live Template

  5. Specify the Abbreviation, Description and Template text.

  6. Do not forget to define the context (in your case Java)

Example

Here is an example of how to create your own TODO text

Open the Setting window with Live Templates editor (as specified above).

Click on + icon and select Template Group.

Name this group Java.

enter image description here

Click on + icon again and select Live Template.

Specify your Live Template and DEFINE CONTEXT.

enter image description here

In my case writing mtodo and pressing enter will result in:

// TODO myName

You can even use variables. Write in your Template text e.g. $DATE$ and $TIME$

// TODO myName $DATE$ $TIME$

Click on Edit variables button and assign to each variable (defined by dollar sign) and expression (predefined function).

enter image description here

Now mtodo will result in

// TODO myName 13.10.2015 15:39

Predefined functions could be found here. The example was created using IntelliJ IDEA 15 EAP.

like image 38
vitfo Avatar answered Nov 14 '22 08:11

vitfo


For those of you who have taken Postfix completion for Live templates, it is worth mentioning they are different. from not-choosing pretty good answers from @JB Niznet and @vitfo, I guess that's the case for OP writer. The document, here, says:

Postfix code completion is similar to live templates, it transforms the current expression without selecting it. For example, you can type .if after an expression to invoke the corresponding postfix completion and wrap the expression with an if statement.

You can check out a list of postfix completions:

  1. Open the Preferences window
  2. Click on Editor -> General -> Postfix completion
like image 2
inherithandle Avatar answered Nov 14 '22 09:11

inherithandle