 |
Simply insanely cool...
Posted by timboudreau on November 21, 2005 at 06:05 PM | Comments (13)
I'm still having way too much fun writing the extensible Gimp-like image viewer tutorial code (well, if I keep this up I'm just going to have to admit that it's taking on a life of its own...).
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:
Now press SPACE and the magic happens:
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!
Bookmark blog post: del.icio.us Digg DZone Furl Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment
-
YAWN!
Been in IntelliJ for years....
Posted by: donncha on November 21, 2005 at 07:33 PM
-
That _is_ cool. But like the preceding comment says, been in IntelliJ for ages.
I still find it amazing after all the intellij vs eclipse vs netbeans discussions that so many people have never really tried out IntelliJ.
Can lead a horse to water and all that...
Posted by: nevster on November 21, 2005 at 09:24 PM
-
Sorry to continue raining on the parade, Tim, but not only does IntelliJ do this, but you can tell it that RECT is supposed to be a Rectangle. If there's only one Rectangle, it will automatically use that and you're done. If there's more than one, it will show you a list of all the Rectangles so you can pick one. No typing necessary. (The way I like it.)
Posted by: grlea on November 21, 2005 at 09:53 PM
-
I still find it amazing after all the intellij vs eclipse vs netbeans discussions that so many people have never really tried out IntelliJ
It's like saying "i'm amazed by the number of people using Linux on their desktop despite the cool UIs that windows provides for a 'small' price".
*Free* is a very compelling price for a developer.
Posted by: bharathch on November 21, 2005 at 11:03 PM
-
I've given IntelliJ a spin or 2 and think it's a great IDE, but NetBeans allows me to be just as productive and it is free. It is for me NetBeans key selling point over IntelliJ, and as more and more features of the Eclipse and IntelliJ are put into NetBeans, I consider investing (time and money) in IntelliJ more and more wasted time.
So Tim, thanks for the update, and I think that it should be considered a compliment when users say that it is a feature they've long since used in another IDE. ;)
Iwan
Posted by: ieising on November 21, 2005 at 11:05 PM
-
While free (as in "free beer", I don't care about religious arguments) is nice, if spending a bit of money increases my productivity or enjoyment enough that I earn back that money over the lifetime of the product I'll spend that money.
I've not tried IntelliJ but JBuilder is for me so much nicer and more productive than either Netbeans OR Eclipse that I don't care if it costs several hundred Euro.
I've earned that money back already in a few months because of increased productivity, which is all that counts for a corporate purchase (for a hobby user it might be more difficult to estimate that benefit, but if you code 10% faster using one tool than another with the same or lower number of errors per thousand lines of code that's got to be worth something).
Posted by: jwenting on November 22, 2005 at 01:12 AM
-
I have tried IntelliJ, even used it a good deal back before NetBeans had refactoring. It's a nice product.
But I never stumbled across this feature there either, which suggests that neither IDE is really advertising it as well as it could.
Anyway, NetBeans is my day-to-day IDE, so the feature being available in IntelliJ doesn't help me in my day-to-day work.
Posted by: timboudreau on November 22, 2005 at 06:06 AM
-
Hmm, I might suggest a simplified and more general template for the last example:
throw (${WRAPPER}) new ${WRAPPER}(${ORIGINAL}.toString()).initCause(${ORIGINAL});
or for some cases just
assert false : ${EXCEPTION};
or if the wrapper class allows it
throw new ${WRAPPER}(${ORIGINAL});
Posted by: jglick on November 22, 2005 at 06:55 AM
-
I can't see any problems in people celebrating new (or current) features in the tools that they themselves use.
Take a more extreme example - if I go round and say I feel good about the Code Completion feature in Netbeans (esp with its pascal case completion!), it does not add any value in the conversation by saying things like "Oh they've got this feature in Visual Studio for C++ long ago! Why don't you Java guys just use C++?"
Posted by: alexlamsl on November 22, 2005 at 06:56 AM
-
Another point is that ${cursor} can be used to determine where the cursor ends up after the last tab is pressed. As an example is my favourite template
public void test${name}() throws Exception
{
${cursor}
}
${name} gets highlighted, you type the replacement and then press tab which takes you to the place indicated by the ${cursor}. The ${cursor} doesn't appear as other variables do.
Posted by: dynamite on November 22, 2005 at 07:14 AM
-
but you can tell it that RECT is supposed to be a Rectangle. If there's only one Rectangle, it will automatically use that and you're done. If there's more than one, it will show you a list of all the Rectangles so you can pick one.
This is also supported.
Heres one of my boilerplate favorites:
${Class}[] ${cursor} = ${Class}[] ${cursor} = (${Class}[]) ${collection instanceof="java.util.Collection"}.toArray(new ${Class}[${collection}.size()]);
(The cast is unnecessary with a templated collection)
And hey, while we're at it, make those templated collections a bit easier
${Class class}<${Type class}> ${name} = new ${Class}<${Type}>();
You can use ctrl-k and ctrl-l for "recently typed completion" (or whatever thats called) while filling in the fields.
Posted by: ianschneider on November 22, 2005 at 05:38 PM
-
Very cool feature! Thanks for bringing it to our attention!
I believe you are correct that features like these should be publicized more. Personally, I would like to see these features in an updated version of "Netbeans: The Definitive Guide". ;-)
Erik
Posted by: evickroy on November 23, 2005 at 09:46 AM
-
alarm beyonce lyric ring
bad credit debt consolidation
angel locsin
billy gilman
debt consolidation
famous daves
gold digger
golds gym
chell rell
bob esponja
consolidation federal loan student
bobs furniture
insurance lead
consolidation loan
corporate gift basket
jennifer beals
katrina halili
kelly ripa
bounty dog hunter
bridge fergie london lyric
brinkley christie
bronx zoo
corporate gift idea
lead mlm
lead mortgage
pepsi cola
acid battery lead sealed
power ranger spd
private voyeur
rolex replica
credit card consolidation
brookfield zoo
chris daughtry
daisy fuentes
ronnie coleman
snow patrol lyric
term life insurance quote
tony matterhorn
weider
dannii minogue
destinys child
dierks bentley
Posted by: skwer on January 12, 2007 at 03:16 PM
|