Eclipse Auto Complete Templates for ATG

Eclipse has an often under-utilized feature called Templates. You’ve probably used the built in templates when Eclipse auto-completes for loops or try-catch blocks, etc… However, you can create your own templates for commonly used chunks of code. This can save you a lot of time, and more importantly can facilitate you writing better quality code.

[fusion_builder_container hundred_percent=”yes” overflow=”visible”][fusion_builder_row][fusion_builder_column type=”1_1″ background_position=”left top” background_color=”” border_size=”” border_color=”” border_style=”solid” spacing=”yes” background_image=”” background_repeat=”no-repeat” padding=”” margin_top=”0px” margin_bottom=”0px” class=”” id=”” animation_type=”” animation_speed=”0.3″ animation_direction=”left” hide_on_mobile=”no” center_content=”no” min_height=”none”]

ATG Eclipse Templates
ATG Eclipse Templates

By making commonly used code blocks available with a couple of keystrokes it is much easier to write best practices code, that otherwise you might shortcut around.

You can view, import, and create new templates by going to Eclipse’s Preferences, then opening Java->Editor->Templates. Each Template has a Name, this is what triggers it for auto-complete so making this simple and unique is good, a Description, a Context, a checkbox to Automatically insert, and then the Pattern which is the code that will get inserted for you. Within the Pattern you have access to a substantial number of variables, such as the current class or method name, variables, method arguments, dates, etc… which allow you do some very useful things.

For ATG coding I’ve created nine Templates for common code blocks.

My templates isBlank and isNotBlank create if blocks based on ATG’s StringUtils.isBlank method, which checks for null, empty, or blank Strings. Checking Strings is something that I do all the time (validating user input, query params, etc…) so being able to do it in a few keystrokes is very useful.

[/fusion_builder_column][fusion_builder_column type=”1_1″ background_position=”left top” background_color=”” border_size=”” border_color=”” border_style=”solid” spacing=”yes” background_image=”” background_repeat=”no-repeat” padding=”” margin_top=”0px” margin_bottom=”0px” class=”” id=”” animation_type=”” animation_speed=”0.3″ animation_direction=”left” hide_on_mobile=”no” center_content=”no” min_height=”none”][java]
ls.isBlank(${cursor})) {

}
[/java]

I have three templates for ATG Performance Monitor operations. Adding in ATG Performance Monitor hooks when you’re coding can make diagnosing performance problems later much easier. Using templates means you don’t have to remember the syntax or even type in the class and method names:

[/fusion_builder_column][fusion_builder_column type=”1_1″ background_position=”left top” background_color=”” border_size=”” border_color=”” border_style=”solid” spacing=”yes” background_image=”” background_repeat=”no-repeat” padding=”” margin_top=”0px” margin_bottom=”0px” class=”” id=”” animation_type=”” animation_speed=”0.3″ animation_direction=”left” hide_on_mobile=”no” center_content=”no” min_height=”none”][java]
PerformanceMonitor.startOperation(“${enclosing_type}”, “${enclosing_method}”);
[/java]

I also have four templates for the primary ATG logging methods with the respective if blocks needed to prevent unnecessary String concatenations.

[/fusion_builder_column][fusion_builder_column type=”1_1″ background_position=”left top” background_color=”” border_size=”” border_color=”” border_style=”solid” spacing=”yes” background_image=”” background_repeat=”no-repeat” padding=”” margin_top=”0px” margin_bottom=”0px” class=”” id=”” animation_type=”” animation_speed=”0.3″ animation_direction=”left” hide_on_mobile=”no” center_content=”no” min_height=”none”][java]
if(isLoggingDebug()) {
logDebug(“${enclosing_type}.${enclosing_method}:” + “${cursor}”);
}
[/java]

I’ve exported these nine ATG templates so you can easily import and start to use them.
Eclipse ATG Coding Templates.

What templates have you created?
[/fusion_builder_column][/fusion_builder_row][/fusion_builder_container]


Posted

in

by

Tags:

Comments

4 responses to “Eclipse Auto Complete Templates for ATG”

  1. John Avatar

    Hey Devon, Thanks for all the great tips. I was wondering what version of Eclipse you are using with ATG? And, do you use the ATG-provided Eclipse plugin? 3.4 and 3.5 have been out for a long time now, but ATG only has a plugin for 3.3 available? Really wanting to use it with 3.5 since the JSP editing features are so much better…

    1. Devon Avatar

      John,

      I don’t use the ATG plugin for a few reasons: the 3.3 requirement is one of them, I also really dislike how it expects you to manage your project and module location. Sometimes I miss the Repository definition editor, but that’s it.

      Currently I’m using MyEclipse 8.5, which is based on Eclipse 3.5. I really like it, and it’s worth the money for me. Although a few months ago I was just using Eclipse 3.5 combined with the JBoss Tools and several other plugins and that works pretty well.

      The upside of the newer Eclipse versions heavily outweigh losing the ATG plugin for me.

      FWIW, my favorite plugins are: Jadclipse, Subclipse, JAutodoc, Mylyn/Jira, JBoss Tools, Checkstyle, FindBugs, Regex Util.

  2. Deezer Avatar
    Deezer

    Devon, Do you put performance monitor calls in every method, or just select methods?

    1. Devon Avatar

      Just select methods. Anything that I think I may want to check on later: External system calls, remote API calls, complex/expensive operations (bulk loading data, handing large XML files), critical parts of the primary user experience, etc..

Leave a Reply

Your email address will not be published. Required fields are marked *

PHP Code Snippets Powered By : XYZScripts.com