sonatype / modello

http://modello.codehaus.org/
7 stars 11 forks source link

Add inner Builder utility class generation #10

Closed simonetripodi closed 11 years ago

simonetripodi commented 11 years ago

I often notice that Modello users use to develop their own utility Builders in order to create Modello generated models, I wonder if it would make sense adding support for generating that classes.

For nested builders, I'd imagine something like:

<model>
[...]

  <classes>
    <class java.builder="true">
      <name>Dependency</name>
      <version>1.0.0+<version>
      <fields>
        [...]

that generates

public class Dependency
{

    // fields, getters/setters

    public static final class Builder
    {

        public Builder (set|add)XXX(XXX argument)
        {
            // set field
            return this;
        }

        public Dependency build()
        {
            Dependency dependency = new Dependency();
            // set all values
            return dependency;
        }

    }

}

If there is no objection, I can add that part - I already have it almost ready in my local copy...