Return-Path: X-Original-To: apmail-groovy-users-archive@minotaur.apache.org Delivered-To: apmail-groovy-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0527518ED2 for ; Thu, 23 Jul 2015 23:37:30 +0000 (UTC) Received: (qmail 42116 invoked by uid 500); 23 Jul 2015 23:30:50 -0000 Delivered-To: apmail-groovy-users-archive@groovy.apache.org Received: (qmail 42078 invoked by uid 500); 23 Jul 2015 23:30:50 -0000 Mailing-List: contact users-help@groovy.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.incubator.apache.org Delivered-To: mailing list users@groovy.incubator.apache.org Received: (qmail 42068 invoked by uid 99); 23 Jul 2015 23:30:50 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Jul 2015 23:30:50 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 5AC0FD72AA for ; Thu, 23 Jul 2015 23:30:50 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 3.9 X-Spam-Level: *** X-Spam-Status: No, score=3.9 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_REPLY=1, HTML_MESSAGE=3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd1-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id f0zA05wTXOIo for ; Thu, 23 Jul 2015 23:30:39 +0000 (UTC) Received: from mail-qk0-f170.google.com (mail-qk0-f170.google.com [209.85.220.170]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTPS id 68FF150614 for ; Thu, 23 Jul 2015 23:30:39 +0000 (UTC) Received: by qkbm65 with SMTP id m65so5014676qkb.2 for ; Thu, 23 Jul 2015 16:29:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=xUbnw5Jizx2babISk96tAt9xpuuh15hYhk9PnF2R6ss=; b=OVu22w1boKuP0PHBIL4yK/mM98E6KOW/m6wxcEh3SQvyuyVAb41puh7SpTtf5dQge9 UsS4PylsLErjXeA3GNGhquMZgGY7AcHyMN7u15hJ0bBqRV6xkjbL4z/unIhXaFeDL0Ri du4mlXYt8E0kvOnfctg+whX5QmulxzAiiuSyoWPth6oKhmhz6tvEEZM23mYnRQ6KJyH8 zZSsADCReQc+rINVt6AA+EqjY4+jhbsapOB1BCIywf5gs/4pUkSY58Udb20hRBddNkAq B7D86xeLA94zMTDyRMjhT3QXx6lpAnm6DkyY3u7kEJB2pW5I/IhGOiHVgRqsh7fz3Kar 7ekg== X-Received: by 10.55.27.97 with SMTP id b94mr15971425qkb.3.1437694188611; Thu, 23 Jul 2015 16:29:48 -0700 (PDT) MIME-Version: 1.0 Received: by 10.140.19.243 with HTTP; Thu, 23 Jul 2015 16:29:29 -0700 (PDT) In-Reply-To: References: <1201237332.1898371.1436823274496.JavaMail.apache@nm2.abv.bg> <822319429.1828834.1436914655124.JavaMail.apache@nm3.abv.bg> <1559789878.2111583.1437151687702.JavaMail.apache@nm3.abv.bg> From: Keegan Witt Date: Thu, 23 Jul 2015 19:29:29 -0400 Message-ID: Subject: Re: Always add no-args constructor at compile time To: users@groovy.incubator.apache.org Content-Type: multipart/alternative; boundary=001a1147f09e686f69051b934357 --001a1147f09e686f69051b934357 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable FYI: I opened GROOVY-7522 and GROOVY-7523 which, if agreed to, will make your config script a lot simpler. -Keegan On Fri, Jul 17, 2015 at 4:49 PM, Keegan Witt wrote: > Awesome! Glad I could help. > > On Fri, Jul 17, 2015 at 12:48 PM, Nikolay Totomanov > wrote: > >> Thanks a lot, Keegan! >> It works like a charm! >> >> >> >> >-------- =D0=9E=D1=80=D0=B8=D0=B3=D0=B8=D0=BD=D0=B0=D0=BB=D0=BD=D0=BE = =D0=BF=D0=B8=D1=81=D0=BC=D0=BE -------- >> >=D0=9E=D1=82: Nikolay Totomanov ntotomanov@abv.bg >> >=D0=9E=D1=82=D0=BD=D0=BE=D1=81=D0=BD=D0=BE: Re: Always add no-args cons= tructor at compile time >> >=D0=94=D0=BE: users@groovy.incubator.apache.org >> >=D0=98=D0=B7=D0=BF=D1=80=D0=B0=D1=82=D0=B5=D0=BD=D0=BE =D0=BD=D0=B0: 15= .07.2015 01:57 >> >> The code looks very clean to me! >> Thanks a lot, Keegan! >> I'll give it a try. >> >> >> >> >> >-------- =D0=9E=D1=80=D0=B8=D0=B3=D0=B8=D0=BD=D0=B0=D0=BB=D0=BD=D0=BE = =D0=BF=D0=B8=D1=81=D0=BC=D0=BE -------- >> >=D0=9E=D1=82: Keegan Witt keeganwitt@gmail.com >> >=D0=9E=D1=82=D0=BD=D0=BE=D1=81=D0=BD=D0=BE: Re: Always add no-args cons= tructor at compile time >> >=D0=94=D0=BE: users@groovy.incubator.apache.org >> >=D0=98=D0=B7=D0=BF=D1=80=D0=B0=D1=82=D0=B5=D0=BD=D0=BE =D0=BD=D0=B0: 14= .07.2015 06:04 >> >> Oh, actually Opcodes is not needed, you can take that off so you don't >> need a dependency on *org.ow2.asm:asm*. >> >> On Mon, Jul 13, 2015 at 10:53 PM, Keegan Witt >> wrote: >> >> Here's what I'm thinking. Use this as a configuration script. >> >> import java.lang.annotation.ElementType >> import java.lang.annotation.Retention >> import java.lang.annotation.RetentionPolicy >> import java.lang.annotation.Target >> import org.codehaus.groovy.ast.ASTNode >> import org.codehaus.groovy.ast.AnnotatedNode >> import org.codehaus.groovy.ast.ClassNode >> import org.codehaus.groovy.ast.ConstructorNode >> import org.codehaus.groovy.ast.Parameter >> import org.codehaus.groovy.ast.stmt.BlockStatement >> import org.codehaus.groovy.control.CompilePhase >> import org.codehaus.groovy.control.SourceUnit >> import org.codehaus.groovy.transform.AbstractASTTransformation >> import org.codehaus.groovy.transform.GroovyASTTransformation >> import org.codehaus.groovy.transform.GroovyASTTransformationClass >> import org.objectweb.asm.Opcodes >> >> @GroovyASTTransformation(phase =3D CompilePhase.CANONICALIZATION) >> public class DefaultConstructorASTTransformation extends AbstractASTTran= sformation implements Opcodes { >> public void visit(ASTNode[] nodes, SourceUnit source) { >> init(nodes, source) >> AnnotatedNode parent =3D (AnnotatedNode) nodes[1] >> >> if (parent instanceof ClassNode) { >> ClassNode cNode =3D (ClassNode) parent >> if (!cNode.getDeclaredConstructor(new Parameter[0])) { >> final BlockStatement body =3D new BlockStatement() >> cNode.addConstructor(new ConstructorNode(ACC_PUBLIC, new= Parameter[0], cNode.EMPTY_ARRAY, body)) >> } >> } >> } >> } >> @Retention(RetentionPolicy.RUNTIME) >> @Target(ElementType.TYPE) >> @GroovyASTTransformationClass("DefaultConstructorASTTransformation") >> public @interface DefaultConstructor {} >> >> withConfig(configuration) { >> ast(DefaultConstructor) >> } >> >> >> Seemed to work in my tests, but everybody should feel free to point out >> anything I goofed up. >> >> -Keegan >> >> On Mon, Jul 13, 2015 at 6:24 PM, Keegan Witt >> wrote: >> >> Sorry, I should have given you the example in the configuration script >> syntax >> >> withConfig(configuration) { >> ast(groovy.transform.TupleConstructor, includes:['']) >> } >> >> >> But it doesn't matter, because the transformation removes existing >> constructors from the class. Sorry, I got ahead of myself. >> >> -Keegan >> >> On Mon, Jul 13, 2015 at 5:45 PM, Keegan Witt >> wrote: >> >> One way that comes to mind offhand would be >> @groovy.transform.TupleConstructor(includeFields=3Dfalse, >> includeProperties=3Dfalse, includeSuperFields=3Dfalse, >> includeSuperProperties=3Dfalse) >> >> or >> @groovy.transform.TupleConstructor(includes=3D['']) >> >> Anybody know why >> @groovy.transform.TupleConstructor(includes=3D[]) >> doesn't work? >> >> -Keegan >> >> On Mon, Jul 13, 2015 at 5:34 PM, Nikolay Totomanov >> wrote: >> >> Hello, >> >> I need to always add the default constructor to my classes. >> Is it possible to achieve that using CompilerConfiguration >> >> Regards, >> Nikki >> >> >> >> >> >> > --001a1147f09e686f69051b934357 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
FYI: I opened GROOVY-7522=C2=A0and GROOVY-75= 23=C2=A0which, if agreed to, will make your config script a lot simpler= .

-Keegan

On Fri, Jul 17, 2015 at 4:49 PM, Keegan Witt <keeg= anwitt@gmail.com> wrote:
Awesome!=C2=A0 Glad I could help.

On Fri, Jul 17, 2015 at = 12:48 PM, Nikolay Totomanov <ntotomanov@abv.bg> wrote:
Thanks a lot,=C2=A0Keegan!
It works like a charm!



>-------- =D0=9E=D1=80=D0=B8=D0=B3=D0=B8=D0=BD=D0=B0=D0=BB=D0=BD=D0=BE = =D0=BF=D0=B8=D1=81=D0=BC=D0=BE --------
>=D0=9E=D1=82: Nikolay Totomanov ntotomanov@abv.bg
>=D0=9E=D1=82=D0=BD=D0=BE=D1=81=D0=BD=D0=BE: Re: Always add n= o-args constructor at compile time
>=D0=94=D0=BE: users@groovy.incubator.apache.org
>=D0=98=D0=B7=D0=BF=D1=80=D0=B0=D1=82=D0=B5=D0=BD=D0=BE =D0= =BD=D0=B0: 15.07.2015 01:57

=20 =20
The code looks very clean to me!
Thanks a lot,=C2=A0Keegan!
I'll give it a try.




>-------- =D0=9E=D1=80=D0=B8=D0=B3=D0=B8=D0=BD=D0=B0=D0=BB=D0= =BD=D0=BE =D0=BF=D0=B8=D1=81=D0=BC=D0=BE --------=20
>=D0=9E=D1=82: Keegan Witt keeganwitt@gmail.com=20
>=D0=9E=D1=82=D0=BD=D0=BE=D1=81=D0=BD=D0=BE: Re: Always add no-= args constructor at compile time=20
>=D0=94=D0=BE: users@groovy.incubator.apache.org=20
>=D0=98=D0=B7=D0=BF=D1=80=D0=B0=D1=82=D0=B5=D0=BD=D0=BE =D0=BD= =D0=B0: 14.07.2015 06:04=20

=20
Oh, actually Opcodes is not needed, you can take that off so you don&= #39;t need a dependency on=20 org.ow2.asm:asm.=20
=20
=20
=20
=20
On Mon, Jul 13, 2015 at 10:53 PM, Keegan Witt=20 <keeganwitt@gmail.com> wrote:=20
=20
=20
=20
Here's what I'm thinking.=C2=A0 Use this as a configurati= on script.=20
=20
import java.lang.annotation.ElementType
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
import java.lang.annotation.Target
import org.codehaus.groovy.ast.ASTNode
import org.codehaus.groovy.ast.AnnotatedNode
import org.codehaus.groovy.ast.Cl= assNode
import org.codehaus= .groovy.ast.ConstructorNode
import= org.codehaus.groovy.ast.Parameter
import org.codehaus.groovy.ast.stmt.BlockStatement
import org.codehaus.groovy.control.C= ompilePhase
import org.code= haus.groovy.control.SourceUnit
imp= ort org.codehaus.groovy.transform.AbstractASTTransformation
import org.codehaus.groovy.transform.GroovyASTTransformation
<= span style=3D"color:rgb(204,120,50)">import org.codehaus.groovy.transform.GroovyASTTransformationClassimport org.objectweb.a= sm.Opcodes

@GroovyASTTransform= ation(phase =3D CompilePhase.CANONICALIZATION)
public class DefaultConstructorASTTransformation= extends AbstractASTTransforma= tion implements Opcodes {
= public void visit(ASTNode[]= nodes, SourceUnit source) {
init(nodes, source)
Anno= tatedNode parent =3D (AnnotatedNode) nodes[1]

if (parent instanceof ClassN= ode) {
ClassNode cNode =3D (ClassNode) parent
= if (!cNode.getDeclaredConstru= ctor(new Parameter[0])) {
final BlockStatement body =3D new BlockStatement()
cNod= e.addConstructor(new Construct= orNode(ACC_PUBLIC, new Paramet= er[0], cNode.EMPTY_ARRAY, bod= y))
}
}
}
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@GroovyASTTransformationClass("DefaultConstructorASTTransformation"
)
public @interface DefaultConstructor {}

withConfig(configuration) {
as= t(DefaultConstructor)
}
=20
=20
=20
Seemed to work in my tests, but everybody should feel free to poi= nt out anything I goofed up.=20
=20
=20 =20
=20
=20
-Keegan
=20
=20
=20
=20
=20
=20
On Mon, Jul 13, 2015 at 6:24 PM, Keegan Witt=20 <keeganwitt@gmail.com> wrote:=20
=20
=20
=20
Sorry, I should have given you the example in the configurat= ion script syntax=20
=20
=20
withConfig(config=
uration) {
ast(groovy.transform.TupleConstructor, includes:[''])
}
=20
=20
=20
But it doesn't matter, because the transformation remove= s existing constructors from the class.=C2=A0 Sorry, I got ahead of myself.= =20
=20
=20 =20
=20
=20
-Keegan
=20
=20
=20
=20
=20
=20
On Mon, Jul 13, 2015 at 5:45 PM, Keegan Witt=20 <keeganwitt@gmail.com> wrote:=20
=20
=20
=20
=20
=20
One way that comes to mind offhand would be=20
=20 =C2=A0= =C2=A0=C2=A0 @groovy.transform.TupleConstructor(includeFields=3Dfalse, incl= udeProperties=3Dfalse, includeSuperFields=3Dfalse, includeSuperProperties= =3Dfalse)=20
=20
=20
=20
or=20
=20 =C2=A0= =C2=A0=C2=A0 @groovy.transform.TupleConstructor(includes=3D[''])=20
=20
=20
=20
=20
Anybody know why=20
=20 =C2=A0= =C2=A0=C2=A0 @groovy.transform.TupleConstructor(includes=3D[])=20
=20
doesn't work?=20

=20
=20 -Keegan
= =20
=20
=20
=20
=20
=20
On Mon, Jul 13, 2015 at 5:34 PM, Nikolay Totomanov=20 <ntotomanov@abv.bg> wrote:= =20
=20
=20
=20
Hello,=20
=20
=20
=20
=20
I need to always add the default constructor to my= classes.=20
=20
Is it possible to achieve that using CompilerConfi= guration=20
=20
=20
=20
=20
Regards,=20
=20
Nikki=20
=20
=20
=20
=20
=20
=20
=20
=20
=20
=20
=20
=20
=20
=20
=20
=20
=20
=20
=20
=20
=20
=20
=20
=20
=20 =20


--001a1147f09e686f69051b934357--