Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id AEC162009F4 for ; Thu, 26 May 2016 23:53:05 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id AD288160A18; Thu, 26 May 2016 21:53:05 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id CE5C7160A17 for ; Thu, 26 May 2016 23:53:04 +0200 (CEST) Received: (qmail 58866 invoked by uid 500); 26 May 2016 21:53:04 -0000 Mailing-List: contact users-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.apache.org Delivered-To: mailing list users@groovy.apache.org Received: (qmail 58856 invoked by uid 99); 26 May 2016 21:53:04 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 May 2016 21:53:03 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 8E29A1A0783 for ; Thu, 26 May 2016 21:53:03 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.179 X-Spam-Level: * X-Spam-Status: No, score=1.179 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id cZWhFb6bBplA for ; Thu, 26 May 2016 21:53:01 +0000 (UTC) Received: from mail-lf0-f41.google.com (mail-lf0-f41.google.com [209.85.215.41]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 7669E5F2C2 for ; Thu, 26 May 2016 21:53:00 +0000 (UTC) Received: by mail-lf0-f41.google.com with SMTP id w16so26011759lfd.2 for ; Thu, 26 May 2016 14:53:00 -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; bh=YUw7CEq66YQKrZDYz1RMTjRIEnYMfHQVQGRz67KOsRA=; b=ELNXUsTFs4GxITQJp/ZN64qNXfdWD/v+VW7XRcx+MOuevUkdXrwRSVXo6402k6vC4w gxsCcOihaEylNt5CEWqG0GJAAUsJiRaadc2H1xPSuKRtbAGGZfJua1bBOKLEfLu235sK MmfschAPA8rzjgXwcng0yBlCVOoGrFRU/fLjPJQQbRceSCZlS6KmmrASnWRn3/camM6r uPtZY2cGIlQK9wM5mJWcLVb2nMPOB4GLHRfx4kNyixdlaof8HqH/pNoGtLkf5rfSS6BQ abcLIapToPOnsKzY6upgxYC8oJFue1CakNw2gcYj+9RW5E5fBZQLyxPBwuKPgumGtO0E wnaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=YUw7CEq66YQKrZDYz1RMTjRIEnYMfHQVQGRz67KOsRA=; b=RPEehquemCw0Qy1P0qj6DzbVCH6/m+w/6pPVC4+04+hr1Gm+BVBkXAZ40Z3AG+SUuw ZSU4wc0wPTu4OKga2ARL/upAxZBr/cDl9B415F8wW/TSSxstiktUrR+Kf/f/U9bqi3zq hrlT8TfdRwuGoJ+PQt6IDkvuqXPiFFGIxLAmU48tp9AJ3qJ89yRDe7CzBIEeSZvYwXWl ad+4NpqTXWf9iA1QkPPZJDBaanYETZ101wZE6Bd2XiMpS8NrzYDUmNSL2sBJ/2N1/qej rfIgY+WRJTyXNtMlbw9KZAJ/1zJ/zBFKcCnWvXyB7/h1Hu2XtHKfDTeNbsLxZfd1JoTK J1qA== X-Gm-Message-State: ALyK8tJGwMse3X4j5JD+H/iymw9uRShTXoF2sUYW5IiZFrYbPN5nSAqX9KmV3059ldEE4dgv3rMZ/rVh11xtPQ== X-Received: by 10.25.87.65 with SMTP id l62mr2867825lfb.4.1464299579886; Thu, 26 May 2016 14:52:59 -0700 (PDT) MIME-Version: 1.0 Received: by 10.25.213.9 with HTTP; Thu, 26 May 2016 14:52:20 -0700 (PDT) In-Reply-To: References: From: Paolo Di Tommaso Date: Thu, 26 May 2016 23:52:20 +0200 Message-ID: Subject: Re: List and GString To: users@groovy.apache.org Content-Type: multipart/alternative; boundary=001a11418d404dd2d40533c5d033 archived-at: Thu, 26 May 2016 21:53:05 -0000 --001a11418d404dd2d40533c5d033 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Looking in the GString implementation I noticed that it call the InvokeHelper.write method. I've tried implementing a DelegatingMetaClass but it does not work. At the end of the day it should to be possible to use meta-programming to override Java compiled code. Maybe the trick you are mentioning is ExpondoMetaClass.enableGlobally ? Is there any other possible workaround ? Cheers, Paolo On Thu, May 26, 2016 at 11:02 PM, Emmanuel Rosa wrote: > The rendering is actually produced by InvokerHelper: > https://github.com/apache/groovy/blob/master/src/main/org/codehaus/groovy= /runtime/InvokerHelper.java#L123 > > I tried overriding it with a category and also via the metaClass, but > neither worked. I recall some kind of trick that=E2=80=99s needed when us= ing the > metaClass with some classes, to get it to take, but I don=E2=80=99t remem= ber the > details. :( > > On May 26, 2016, at 2:06 PM, Paolo Di Tommaso > wrote: > > Dear all, > > I have a use case in which I need to override the `toString` method of a > custom List class and use it when interpolating that list object in a > GString. > > It turns out the Groovy uses its own formatting methods for List and othe= r > structures, so the my custom `toString` is simply ignored. > > To explain it better take in consideration this example: > > class MyList extends ArrayList { > > String toString() { > this.join('-') > } > > } > > > def x =3D new MyList() > x << 1 << 2 << 3 > > assert x.toString() =3D=3D '1-2-3' > assert "$x" =3D=3D '1-2-3' > > Assertion failed: > assert "$x" =3D=3D '1-2-3' > | | > | false > [1, 2, 3] > > The second assertion fails for the reason said above. Now I'm wondering i= t > there's any way to override somehow the GString default rendering mechani= sm > in such a way I can inject my own formatting rule for my custom class. > > Any suggestion is appreciated. > > > > Cheers, > Paolo > > > > > --001a11418d404dd2d40533c5d033 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Looking in the GString implementation I noticed that it ca= ll the InvokeHelper.write me= thod.=C2=A0

I've tried implementing a DelegatingMe= taClass=C2=A0but it does not work. At the end of the day it should to b= e possible to use meta-programming to override Java compiled code.

Maybe the trick you are mentioning is ExpondoMetaClass.enableGlobally ?

<= div>
Is there any other possible workaround ?=C2=A0


Cheers,
Paolo

=

On Thu, May= 26, 2016 at 11:02 PM, Emmanuel Rosa <goaway1000@gmail.com> wrote:
The rendering is actually produced by InvokerHelper:=C2=A0https://github.com/apache/= groovy/blob/master/src/main/org/codehaus/groovy/runtime/InvokerHelper.java#= L123

I tried overriding it with a category and also = via the metaClass, but neither worked. I recall some kind of trick that=E2= =80=99s needed when using the metaClass with some classes, to get it to tak= e, but I don=E2=80=99t remember the details. :(

On May 26, 2016, at 2:06 PM, = Paolo Di Tommaso <paolo.ditommaso@gmail.com> wrote:

Dear all,=C2=A0

I have a use case in which I need = to override the `toString` method of a custom List class and use it when in= terpolating that list object in a GString.=C2=A0

I= t turns out the Groovy uses its own formatting methods for List and other s= tructures, so the my custom `toString` is simply ignored.=C2=A0
<= br>
To explain it better take in consideration this example:=C2= =A0

class= MyList extends ArrayList {

=C2=A0 Stri= ng toString() {
=C2=A0= =C2=A0 this.join('-')
=C2=A0 }

=
}


= def x =3D new MyList()
x << 1 << 2 << 3=C2=A0

assert x.toString() =3D=3D '1-2-3'
assert "$x" =3D=3D '1-2-3'

Assertion failed:=C2=A0
assert "$x" =3D=3D '1-2-3&#= 39;
=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0| =C2=A0|
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0false
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0[1, 2, 3]<= /font>

The second assertion fails for the re= ason said above. Now I'm wondering it there's any way to override s= omehow the GString default rendering mechanism in such a way I can inject m= y own formatting rule for my custom class.=C2=A0

A= ny suggestion is appreciated.=C2=A0



Cheers,
Paolo


=


--001a11418d404dd2d40533c5d033--