Simply insanely cool...
And I write a lot of random logging code that looks like:
doSomething (rect.x, rect.y, rect.width, rect.height);
Try this in NetBeans 5.0: Open the options window, go to Editor | Code Templates. Click New to add a new abbreviation. Enter
${RECT}.x, ${RECT}.y, ${RECT}.width, ${RECT}.height
Assign it the abbreviation rr.
Now, in the editor, simply type rr[SPACE]. Like this:
And type a string like bounds. Presto! All of the repetitions of the string change too!
It seems trivial, but I can't remember the last time I was this gaga about an editor feature - I keep having more uses for it. For example, standard NetBeans module boilerplate:
${Clazz} singleton = (${Clazz}) Lookup.getDefault().lookup(${Clazz}.class);
|
(the | character is where to put the caret after I press Enter)
will generate, e.g.,
MyService singleton = (MyService) Lookup.getDefault().lookup(MyService.class);
or a classic, converting a checked exception to a runtime exception:
IllegalStateException ise = new IllegalStateException (${Exception}.getMessage());
ErrorManager.getDefault().annotate (ise, ${Exception});
throw ise;
and assign it to the abbreviation "ise". I type ise[SPACE] and get
IllegalStateException ise = new IllegalStateException(e.getMessage());
ErrorManager.getDefault().annotate(ioe, e);
throw ise;
with the name of the exception selected so I can correct it. Wow!
- Login or register to post comments
- Printer-friendly version
- timboudreau's blog
- 579 reads





