generate code with live template

Is it possible to write live templates which iterate over the fields in a class and generate code?

For example, if one has the following class:

public class FooBar {
Foo myfoo;
Bar bar;
|
}

I'd like a live template which generates a constructor that looks like this:

public class FooBar {
Foo myfoo;
Bar bar;

// generated code
public FooBar(){
myfoo = new Foo();
bar = new Bar();
}
// generated code

}

Is this possible? Any tips appreciated.

3 comments
Comment actions Permalink

No, it is not possible with live templates.
Use alt-insert/generate constructor instead.

Eugene.

"Brian K. Buckley" <briankbuckley@comcast.net> wrote in message
news:17401114.1065712721566.JavaMail.itn@is.intellij.net...

Is it possible to write live templates which iterate over the fields in a

class and generate code?
>

For example, if one has the following class:

>

public class FooBar {
Foo myfoo;
Bar bar;
|
}

>

I'd like a live template which generates a constructor that looks like

this:
>

public class FooBar {
Foo myfoo;
Bar bar;

>

// generated code
public FooBar(){
myfoo = new Foo();
bar = new Bar();
}
// generated code

>

}

>

Is this possible? Any tips appreciated.



0
Comment actions Permalink

A GREAT new feature for IDEA would be the ability to run xdoclet to generate source code at the point of the cursor, much like live templates currently do.

This would allow users to define their own custom code generators for constructors, setters, getters, equals, hashcode and whatever else, by writing their own custom XDT files and taghandlers.

Brian

0
Comment actions Permalink

On Mon, 13 Oct 2003 08:19:45 +0000, Brian K. Buckley wrote:

A GREAT new feature for IDEA would be the ability to run xdoclet to
generate source code at the point of the cursor, much like live templates
currently do.


Hmmm, integrated XDoclet support. Now that'd be cool. Background xdoclet
generation/compilation as you edit code and add xdoclet javadoc. Would
solve a lot of uncompilable code due to non-generated interfaces that you
implement.

Now, I know its easy enough to just run your xdoclet ant task and add your
generated code path as a source dir, but hey ;)

Time for an xdoclet plugin I think :)

--
Discouragement is a dissatisfaction with the past, a distaste for the
present, and a distrust of the future - Maree de Jong, CLCA.

0

Please sign in to leave a comment.