Monday, September 21, 2009

nice Code Template for log statements

This seems to be working properly again in JDeveloper 11.1.1.1.0 .
(see also forum thread "JDeveloper 11g : variable $end$ in custom Code Template")

I often find myself adding "print debug statements" to my code like this:

public class SomeClass
{
   public void someMethod()
   {
      System.out.println("SomeClass.someMethod() : some info");
   }
}

I already used the default "sop" code template to help me with that.
Now I have been able to configure my own code template that also adds the class name and method name automatically.

I don't know how to export code templates so I'll try to describe it:
In the "Preferences" dialog on the "Code Editor > Code Templates" pane I added a Shortcut "sopl" with Description "System.out.println logging".
On the "Code" tab I added:

System.out.println("$myCurClass$.$myCurMethod$() : " + $end$);




On the "Variables" tab I configured:
Name="myCurClass", Type="curClass", Default Value="x", Editable=<unchecked>
Name="myCurMethod", Type="curMethod", Default Value="x", Editable=<unchecked>



So, if I type "sopl" in my Java code followed by Ctrl+Enter I can add my log statements faster.