JDeveloper code templates

0 0
Read Time:1 Minute, 31 Second

When you write a lot of code, no matter what sophisticated framework you use, there are pieces of code that you end up writing over and over again (especially when using Java). Writing logging code in Java is a good example. A common pattern is to initialize a static logger variable in every class you want to log something. Fortunately, JDeveloper has a feature called “Code Templates” that can make your life a lot easier! I have seen several blogs that explain how to use Code Templates for logging code (I saw one from as early as 2006; the feature itself has actually been available since 2004!). But still a lot of people are not aware of this feature (or perhaps simply forget to use it).

That is why I created the simplest logging code templates ever. Download the Code Templates XML file and import them into JDeveloper, see screenshot below (note that you cannot import the file from a location with a space in the path, a known JDeveloper issue).

image

 

Now simply enter “log” followed by Ctrl-Enter at the start of the class to create a static logger variable.

image

image

 

After that, simply enter “log” followed by Ctrl-Enter anywhere you want to log something.

image

image

 

That is easy, right? A slightly more complicated example is the template: “lvar”. With this template you can easily log the name and value of a variable. Simply enter “lvar” followed by Ctrl-Enter and then you can choose the variable to log (currently does not work for primitive types).

image

 

Remember that code templates are not limited to logging code (or to Java code)! Whenever you find that you have to type the same thing (or similar things) over and over again you could probably create a code template that does it for you.

About Post Author

Paco van der Linden

Software engineer with an interest in amazing and performant UI's, distributed systems and robotics. Graduated with a masters degree in Computer Science and Engineering, focusing on Information Security Technology (i.e. a lot of mathematics, cryptographic algorithms and protocols, secure coding and such). I focus on web application development, using the latest front-end technologies, e.g. WebComponents/Polymer, AngularJS, etc. Because of AMIS's long history with Oracle technology (almost exclusively), my speciality has become creating user-friendly interfaces on top of complex enterprise systems.
Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %
Next Post

ADF DVT Speed Date: Meeting the Pie Graph

Recently the ADF Special Interest Group at AMIS organized an ADF DVT Speed Date. During this speed date, six ADF specialists from our team presented their favorite Data Visualization Component from the DVT library. In a series of blog posts we share the information with a broader audience. In this […]
%d bloggers like this: