From users-return-581-apmail-groovy-users-archive=groovy.apache.org@groovy.incubator.apache.org Mon Jul 27 06:52:58 2015 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 1BD8618A22 for ; Mon, 27 Jul 2015 06:52:58 +0000 (UTC) Received: (qmail 4262 invoked by uid 500); 27 Jul 2015 06:52:55 -0000 Delivered-To: apmail-groovy-users-archive@groovy.apache.org Received: (qmail 4227 invoked by uid 500); 27 Jul 2015 06:52:54 -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 4216 invoked by uid 99); 27 Jul 2015 06:52:54 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Jul 2015 06:52:54 +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 73AADD7D31 for ; Mon, 27 Jul 2015 06:52:54 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 3.879 X-Spam-Level: *** X-Spam-Status: No, score=3.879 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, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd1-us-west.apache.org (amavisd-new); domainkeys=pass (1024-bit key) header.from=ntotomanov@abv.bg header.d=abv.bg; dkim=pass (1024-bit key) header.d=abv.bg Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id e0jJIHwfujia for ; Mon, 27 Jul 2015 06:52:46 +0000 (UTC) Received: from smtp-out.abv.bg (smtp-out.abv.bg [194.153.145.80]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTP id D049520908 for ; Mon, 27 Jul 2015 06:52:45 +0000 (UTC) Received: from mail23.abv.bg (nm2.ni.bg [192.168.151.161]) by smtp-out.abv.bg (Postfix) with ESMTP id B934D56EB1E for ; Mon, 27 Jul 2015 09:52:08 +0300 (EEST) DomainKey-Signature: a=rsa-sha1; s=smtp-out; d=abv.bg; c=simple; q=dns; b=vM3pmgaAhhHROsBm4JH/6vryS8FhZ3XFMCn8dHlTKoDVNImQ0krFK+X/hGj745FMF 2Uk8dXS3vjUr0UEW0wsDqt7iDERu6wcoFTTmNRsGWKH1xTHrHVOtgqDlW3zr1l6FwVB r6n1MKthA9CwlMHhgEzul+84H8y5wdxb9lfT/Tg= DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=abv.bg; s=smtp-out; t=1437979928; bh=oYkrW97hrNWjB28rtqGzNx8LLHqc1qpE5OY5Ym5R43c=; h=Date:From:To:Message-ID:In-Reply-To:References:Subject: MIME-Version:Content-Type:DKIM; b=XW/0v5MwknUCqRxeBoTbwWWjw5QNDviMm+B4OufGTlKkjlCrhmXvDWUlGQaYtKdXf gXFLTLBjH00/HNaCbc2t0ID7AjSO+8VMte8pAy+SWmPiC1MdZYYdKM4w6YyQCDRt7o dio5m3f97xC33X/FL//3zgGcK24lTlLS+DeWsaRA= Received: from nm2.abv.bg (localhost.localdomain [127.0.0.1]) by mail23.abv.bg (Postfix) with ESMTP id C48DC16C52D for ; Mon, 27 Jul 2015 09:52:08 +0300 (EEST) Date: Mon, 27 Jul 2015 09:52:08 +0300 (EEST) From: Nikolay Totomanov To: users@groovy.incubator.apache.org Message-ID: <1731904052.200581.1437979928799.JavaMail.apache@nm2.abv.bg> 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> Subject: Re: Always add no-args constructor at compile time MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_200580_261654723.1437979928793" X-Mailer: AbvMail 3.0 X-Originating-IP: 79.100.0.18 ------=_Part_200580_261654723.1437979928793 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Looks promising. Thank you for the heads up >-------- Оригинално писмо -------- >От: Keegan Witt keeganwitt@gmail.com >Относно: Re: Always add no-args constructor at compile time >До: users@groovy.incubator.apache.org >Изпратено на: 24.07.2015 02:29 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 keeganwitt@gmail.com > wrote: Awesome! Glad I could help. On Fri, Jul 17, 2015 at 12:48 PM, Nikolay Totomanov ntotomanov@abv.bg > wrote: Thanks a lot, Keegan! It works like a charm! >-------- Оригинално писмо -------- >От: Nikolay Totomanov ntotomanov@abv.bg >Относно: Re: Always add no-args constructor at compile time >До: users@groovy.incubator.apache.org >Изпратено на: 15.07.2015 01:57 The code looks very clean to me! Thanks a lot, Keegan! I'll give it a try. >-------- Оригинално писмо -------- >От: Keegan Witt keeganwitt@gmail.com >Относно: Re: Always add no-args constructor at compile time >До: users@groovy.incubator.apache.org >Изпратено на: 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 keeganwitt@gmail.com > 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 = CompilePhase.CANONICALIZATION) public class DefaultConstructorASTTransformation extends AbstractASTTransformation implements Opcodes { public void visit(ASTNode[] nodes, SourceUnit source) { init(nodes, source) AnnotatedNode parent = (AnnotatedNode) nodes[ 1 ] if (parent instanceof ClassNode) { ClassNode cNode = (ClassNode) parent if (!cNode.getDeclaredConstructor( new Parameter[ 0 ])) { final BlockStatement body = 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 keeganwitt@gmail.com > 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 keeganwitt@gmail.com > wrote: One way that comes to mind offhand would be @groovy.transform.TupleConstructor(includeFields=false, includeProperties=false, includeSuperFields=false, includeSuperProperties=false) or @groovy.transform.TupleConstructor(includes=['']) Anybody know why @groovy.transform.TupleConstructor(includes=[]) doesn't work? -Keegan On Mon, Jul 13, 2015 at 5:34 PM, Nikolay Totomanov ntotomanov@abv.bg > wrote: Hello, I need to always add the default constructor to my classes. Is it possible to achieve that using CompilerConfiguration Regards, Nikki ------=_Part_200580_261654723.1437979928793 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable
Looks promising. Thank you for the heads up


>-------- =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= 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: 24.07.2015 02:29

=20 =20
FYI: I opened=20 GROOVY-7522 and=20 GROOVY-7523 which, if agreed to, will make your config scr= ipt a lot simpler.

-Keegan

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

On Fri, Jul 17, 2015 at 12:48 PM, Nikolay Totomanov=20 <ntotomanov@abv.bg> wrote:
Thanks a lot, Keegan!=20
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 --------=20
>=D0=9E=D1=82: Nikolay Totomanov=20 nto= tomanov@abv.bg=20
>=D0=9E=D1=82=D0=BD=D0=BE=D1=81=D0=BD=D0=BE: Re: Alwa= ys add no-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!=20
Thanks a lot, Keegan!=20
I'll give it a try.=20
=20
=20
=20
=20
>-------- =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=20 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
=20
Oh, actually Opcodes is not needed, you can take that off= so you don'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&g= t; wrote:=20
=20
=20
=20
Here's what I'm thinking.  Use this as a configu= ration script.=20
=20
import java.lang.annotation.ElementType=

import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicyimport java.lang.annotation.Target
import org.codehaus.groovy.ast.ASTNode
import org.codehaus.groovy.ast.Annotat= edNode
import org.codehaus.= groovy.ast.ClassNode
import org.codehaus.groovy.ast.ConstructorNode
import org.codehaus.groovy.ast.Parameter
import org.codehaus.groovy.ast.stmt.BlockStatem= ent
import org.codehaus.gro= ovy.control.CompilePhase
import org.codehaus.groovy.control.SourceUnit
import org.codehaus.groovy.transform.AbstractASTTransforma= tion
import org.codehaus.groovy.transform.GroovyASTTransformatio= n
import org.codehaus.groovy.transform.GroovyASTTransform= ationClass
import or= g.objectweb.asm.Opcodes

@Groov= yASTTransformation(phase =3D CompilePhase.CANONICALIZATION)
public class
DefaultConstructorASTT= ransformation extends Abstract= ASTTransformation implements O= pcodes {
public void vi= sit(ASTNode[] nodes, SourceUnit source) {
init(nodes, source) AnnotatedNode parent =3D (AnnotatedNode) nodes[1]

if (parent instanceof = ClassNode) {
ClassNode cNode =3D (ClassNode) parent if (!cNode.getDe= claredConstructor(new Paramete= r[0])) {
<= span style=3D"color:rgb(204,120,50)">final
BlockStatement body =3D <= span style=3D"color:rgb(204,120,50)">new BlockStatement()
= cNode.addConstructor(new ConstructorNode(ACC_PUBLIC, new <= /span>Parameter[0], cNode.EMP= TY_ARRAY, body))
}
}
}
}
@Retention(RetentionPolicy.RUNTIME)
@Target
(ElementType.TYPE)
@GroovyASTTransformationClass
("DefaultConstructorASTTransformation")
public @interface DefaultConstructor {}

withConfig(configuration) {
= ast(DefaultConstructor)
}
=20
=20
=20
Seemed to work in my tests, but everybody should feel= free to point 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<= /a>> wrote:=20
=20
=20
=20
Sorry, I should have given you the example in th= e configuration script syntax=20
=20
=20
with=
Config(configuration) {
ast(groovy.transform.TupleConstructor, includes:[''])
}
=20
=20
=20
But it doesn't matter, because the transformatio= n removes existing constructors from the class.  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     @groovy.transform.TupleConstructor(includeFields= =3Dfalse, includeProperties=3Dfalse, includeSuperFields=3Dfalse, includeSup= erProperties=3Dfalse)=20
=20
=20
=20
or=20
=20     @groovy.transform.TupleConstructor(includes=3D['']= )=20
=20
=20
=20
=20
Anybody know why=20
=20     @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 const= ructor to my classes.=20
=20
Is it possible to achieve that using C= ompilerConfiguration=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
=20

=20

=20 =20 ------=_Part_200580_261654723.1437979928793--