That's nice but what I want is to be able to select a word and then have this appear below the line in which the word is found:
System.out.println("word: " + word);
Yes, this is exactly what the keyboard shortcut of the week (see yesterday's blog entry) does for System.err.println. So, using Sandip's excellent LineOperations code (LineOperations.java) as my starting point, here's the InjectSout module for NetBeans IDE 5.5 Beta 2:
How it works is that you select a word in a Java file. Any word. Not necessarily a variable or a field or anything like that. It could be anything at all, because the assumption is that you're smart enough to know which words make sense for this functionality. Then you press Ctrl-F1. (By the way, if there's a conflict between shortcuts provided by different modules, I wonder what happens..?) If no word is selected, you get a message telling you to select a word. If a word is selected, it is put in a new line below the current line (with a line above and below, which, if you don't like them, you can delete as always with Ctrl-E) within a System.out.println statement as described above. The status bar also shows the line that is added. If more than one word is selected, the same thing happens, again under the assumption that you're smart enough to only select the appropriate parts of the code. The Ctrl-F1 shortcut only works in Java files, which also makes sense.
Note: After you use the shortcut, you need to save the file, otherwise you can't use the shortcut again. Don't know why this is the case, something with locking or cursors maybe. (But not a big problem, just do Ctrl-S). The code that is generated is not formatted. You need to do that yourself. (Not a problem, use Ctrl-Shift-F.) Something else is that I don't know where the shortcut is found in the Keymap, so don't know where you'd need to go to change the shortcut to something different.
So remember: if it isn't working, save the file and try again.
The module could very easily be extended for JOptionPane, for example. Or maybe a palette could be added with statements such as these for 'injection' into the code. I guess I'm not using the word 'inject' correctly, or at least not as used in the Java EE 5 specification, but on the other hand I don't mind not being Java EE 5 compliant, in this instance...