Message from discussion
@RequiredArgsConstructor varargs (...) option
Received: by 10.50.171.67 with SMTP id as3mr66994igc.5.1338305585646;
Tue, 29 May 2012 08:33:05 -0700 (PDT)
X-BeenThere: project-lombok@googlegroups.com
Received: by 10.231.8.197 with SMTP id i5ls4725498ibi.9.gmail; Tue, 29 May
2012 08:33:04 -0700 (PDT)
Received: by 10.50.222.168 with SMTP id qn8mr471332igc.3.1338305584567;
Tue, 29 May 2012 08:33:04 -0700 (PDT)
Received: by 10.50.100.229 with SMTP id fb5msigb;
Tue, 29 May 2012 08:26:53 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.68.238.161 with SMTP id vl1mr1532315pbc.2.1338305213392; Tue,
29 May 2012 08:26:53 -0700 (PDT)
Authentication-Results: ls.google.com; spf=pass (google.com: domain of
fralalo...@gmail.com designates internal as permitted sender)
smtp.mail=fralalo...@gmail.com; dkim=pass
header...@gmail.com
Received: by ra8g2000pbc.googlegroups.com with HTTP; Tue, 29 May 2012 08:26:53
-0700 (PDT)
Date: Tue, 29 May 2012 08:26:53 -0700 (PDT)
In-Reply-To: <2b6dc202-7a09-413b-a0e3-01381eeace48@n22g2000yqb.googlegroups.com>
References: <2b6dc202-7a09-413b-a0e3-01381eeace48@n22g2000yqb.googlegroups.com>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0,gzip(gfe)
Message-ID: <138b2b7c-83e8-4c0d-97d3-8a84a597bdde@ra8g2000pbc.googlegroups.com>
Subject: Re: @RequiredArgsConstructor varargs (...) option
From: Francis Lalonde <fralalo...@gmail.com>
To: Project Lombok <project-lombok@googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Following Roel's interest in my proposition, I've been toiling away on
Lombok's code. I have successfully changed the Javac handler to
generate varargs when the last parameter is an array, but the Eclipse
Handler is giving me a hard time. Here is my Javac (working, tested)
code :
lombok.javac.handlers.HandleConstructor.createConstructor(AccessLevel,
JavacNode, List<JavacNode>, boolean, JCTree)
...
Iterator<JavacNode> i =3D fields.iterator();
while (i.hasNext()) {
JavacNode fieldNode =3D i.next();
...
long flags =3D Flags.FINAL;
if (field.vartype.getTag() =3D=3D JCTree.TYPEARRAY && !i.hasNext())
flags |=3D Flags.VARARGS;
JCVariableDecl param =3D maker.VarDef(maker.Modifiers(flags,
nonNulls.appendList(nullables)), field.name, field.vartype, null);
...
and here is what I have now in Eclipse, which seems like it could work
(but doesnt) :
lombok.javac.handlers.HandleConstructor.createConstructor(AccessLevel,
JavacNode, List<JavacNode>, boolean, JCTree)
...
Iterator<EclipseNode> i =3D fields.iterator();
while (i.hasNext()) {
EclipseNode fieldNode =3D i.next();
...
Argument parameter =3D new Argument(field.name, fieldPos,
copyType(field.type, source), Modifier.FINAL);
if (field.binding !=3D null) {
if ((field.binding.tagBits & TagBits.IsArrayType) !=3D 0 && !
i.hasNext()) {
parameter.type.bits |=3D ASTNode.IsVarArgs;
}
}
setGeneratedBy(parameter, source);
...
I've taken the "parameter.type.bits |=3D ASTNode.IsVarArgs" bit from
lombok's own PatchDelegate class, but I do not get the expected
effect. The generated constructor only takes a regular array and
introspecting it does not return isVarArgs() =3D=3D true.
Any Eclipse AST masters out there to help me out?
Francis
On May 2, 10:21=A0am, Francis Lalonde <fralalo...@gmail.com> wrote:
> Hello,
>
> Here's a suggestion for a smal improvement. I use the
> @RequiredArgsConstructor where I can, but also have a number of
> classes that have final Object[] members that can be initialized with
> zero..n elements. I still prefer to define explicit constructors for
> those classes so I can use varargs, which make for cleaner calling
> code. It would be nice if @RequiredArgsConstructor had an option to
> generate varargs constructors for those array fields.
>
> thus this :
>
> =A0 =A0 =A0 =A0 class ZugZug {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 final Integer[] functors;
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 public ZugZug(Integer... f) {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 functors =3D f;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 }
>
> could be turned into this
>
> =A0 =A0 =A0 =A0 @RequiredArgsConstructor(useVarArgs=3Dtrue)
> =A0 =A0 =A0 =A0 class ZugZug {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 final Integer[] functors;
> =A0 =A0 =A0 =A0 }
>
> Obviously, only one array field could be initialized this way, and it
> should be the last defined in class (to respect param order that
> requires varags to be last in signature).
>