Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Applying conditions to code templates (code generation)
Applying conditions to code templates (code generation) [message #329445] Tue, 24 June 2008 14:34 Go to next message
Eclipse UserFriend
Hello.

I wrote a tool for a plugin that replaces the "default" Java Code
Templates with a set of custom templates bundled with the plugin. Good
stuff, except that detailed templates are desired, and it would be good if
the template loaded was dependent on the context of the file's creation.

The desired behavior is that a new java class would have it's name
examined, and generate slightly different "new class" code comments,
depending on key patterns of the java file name.

Is there some way to apply conditional tests to a template? Like, to have
eclipse test if "*foo*" is in a class name. If so, include the "foo"
comment in the class body, else, use "default".

Thanks.
Re: Applying conditions to code templates (code generation) [message #329625 is a reply to message #329445] Mon, 30 June 2008 09:55 Go to previous message
Eclipse UserFriend
Well, in the interest of enlightening future plugin developers, I'll
contribute what progress has been made here.

Templates, TemplateContexts, ContextTypes, and TemplateVariables are used
to resolve a template pattern into actual code generation.

ContextTypes hold template variables, which work together to resolve a
context into actual content.
There's a "general" TemplateContextType registry and a
CodeTemplateContextType registry. The JavaPlugin has a method for
retrieving these registries, like the one below.
JavaPlugin.getDefault().getCodeTemplateContextRegistry()

You can retrieve the registry, and replace the registry types with your
own ContextTypes. The CodeTemplateContextRegistry contains all the
TemplateContextTypes used in Windows>Preferences>Java>Code
Style>Templates. This is pretty useful, but only so useful.

Unfortunately, a "new class wizard" uses ContexTypes and variables to
resolve everything BUT the superclass, which is what I'm endeavoring to
use. The new class wizard tweaks the autogenerated content afterwards,
plugging in the superclass and implementation information without using
templates at all.

It appears to accomplish my purposes, it would be necessary to hook the
new class file wizard. If anyone has any pro-tips on how to do this, I'm
all ears.
Previous Topic:Ganymede keymap in pdf format
Next Topic:[Databinding] ObservableListTreeContentProvider
Goto Forum:
  


Current Time: Wed Apr 16 10:10:13 EDT 2025

Powered by FUDForum. Page generated in 0.02987 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top