Quick fill label in eclipse

Is there a quick way to pass an object / primitive to other objects / primitives in eclipse. I'm looking for something like a quick try / catch block: you select a block and press Ctrl + Alt + Z to quickly surround the block with try / catch.

So, for quick casting, you again select the block, you press the keys and quickly type the name of the object using autocomplete, and voila you make the cast.

I know that this exists via Ctrl + 1 when automatic correction is available, but I would also like to do it separately.

Thanks.

+4
source share
2 answers

I actually have this code template configured for my Eclipse. Here you can configure it.

Open the Preferences dialog by going to Windows > Preferences , and then going to Java > Editor > Templates . Click New... here to create a new code template as shown below.

Code template

Now, in the Java file editor, select the Object you want to print and press Ctrl + Space .

Ctrl + Space drop-down

Call the code template and you get something like

 [type] [new_name] = ([type]) new ArrayList<String>(); 

where [] indicates that the type can be specified using autocomplete.

A default cast template is also available, which can be invoked by typing cast and then pressing Ctrl + Space . The difference is that it does not support selection, but allows you to specify the target using autocomplete. I find both options useful.

 [type] [new_name] = ([type]) [name]; 
+6
source

Eclipse provides a way to create shortcuts for quick fixes.

You can create a shortcut that "presses ctrl + 1 and then selects the option to add a throw." Using this approach, you don’t even need to select a block, just step over it, for example, when using ctrl + 1, plus you use the existing IDE option.

This can be done from the menu Window > Preferences > General > Keys , and then search for the Quick Fix - Add Cast command. Assign your commitment and do it! (image cannot be uploaded due to my reputation).

PD: In my case, there were two Quick Fix - Add Cast commands Quick Fix - Add Cast , and only one of them did the trick, you might have to try both.

+2
source

Source: https://habr.com/ru/post/1491935/


All Articles