How to wrap selected code with user defined text before and after the selection

StackOverflow https://stackoverflow.com/questions/22643735

  •  21-06-2023
  •  | 
  •  

Вопрос

In eclipse, I'd like to select a section of code with my mouse and then hit some sort of keyboard shortcut that causes the selection to be surrounded like so:

// [region]
public void someFunction() {
    ...
}
// [endregion]

Where the code is surrounded by the (user defined) comment lines "// [region]" and "// [endregion]" How would I do this? In netbeans, you can do something similar as referenced here: http://wiki.netbeans.org/SurroundWithCodeFolding

Это было полезно?

Решение

Yes you can cover a single or block of statements with if, do, for, while etc etc.

Select a single or block of statements then press Alt + Shift + Z

You will see the below popup. Choose the appropriate option. Hit Enter

enter image description here

But you asking to cover a set of statements with method, for this you have to refractor the code.

Select a single or block of statements then press Shift + Alt + M

Then a dialog will appear, fill up the details and click on OK button.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top