Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jdt-ui-dev] Templates and variable substitution case

Two template requests:
* smart case on variable names
* automatic import adding

Background:
I was creating a template for event firing, and realized it would be cool if
there was a way for substitution variables to change case in a smart way.

Suppose I had a template that had the following pattern (forget the fact
that it needs better error handling ;)

  java.util.ArrayList _${eventName}Listeners = new java.util.ArrayList();
  public void add${eventName}Listener(${eventName}Listener l) {
    _${eventName}Listeners.add(l);
  }
  public void remove${eventName}Listener(${eventName}Listener l) {
    _${eventName}Listeners.remove(l);
  }
  public void fire${specificEvent}() {
    if (_${eventName}Listeners.isEmpty())
      return;

    ${eventName}Event e = new ${eventName}Event;
    java.util.Iterator i;
    synchronized(_${eventName}Listeners) {
      i = _${eventName}Listeners.clone().iterator();
    }

    while(i.hasNext()) {
      ${eventName}Listener l = (${eventName}Listener)i.next();
      l.${specificEvent}(e);
    }
  }

I'd like to be able to type "sun" for the eventName and have it appear as

  _sunListeners
  addSunEvent
  SunEvent
  fireSunEvent
  ...

in the above completion. Ideally, the macro would automatically figure out
whether it should be upper or lower case, but an extension like

  ${eventName:startUpper}
  ${eventName:startLower}

would be cool.


Second: In the above completion, I use java.util.ArrayList -- it would be
nice to have that changed to "ArrayList" and add the import automatically.

Comments?
-- Scott

==============================================================
Scott Stanchfield    scott@xxxxxxxxxxxx    http://javadude.com

Lead author of "Effective VisualAge for Java, Version 3"
                                      http://javadude.com/evaj

VisualAge for Java Tips and Tricks     http://javadude.com/vaj

AWT & Swing FAQ Manager, jGuru.com
Visit for Java Enlightenment!             http://www.jguru.com
==============================================================




Back to the top