Tuesday, March 13, 2012

JDeveloper: Code Template to show current class and method

For debugging purposes, I sometimes use a simple System.out.println statement to have some values displayed on the console. It's not the best or cleanest way, I know, but it works and is a lot faster than setting up a logging framework first. If you already have a logging framework configured, you might as well use that one, of course. Following method could also be used for quickly generating logging statements.

To keep an overview of the messages printed, I usually preceed every message with currentClass.currentMethod. In JDeveloper, there's an easy way to do this:

  • Open Tools -> Preferences...
  • Go to Code Editor -> Code Templates
  • Add a new one
  • Enter a shortcut (I use 'sopl'), and change the context to Java
  • In the code section, type System.out.println("$myCurClass$.$myCurMethod$(): $end$");
  • In the variables tab, map myCurClass to 'Class Name' and  myCurMethod to 'Method Name'
  • Leave end mapped to 'End Location'
Now you can use sopl in every Java class! Just type sopl and hit Ctrl+Enter.

No comments:

Post a Comment