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 93AFC200C3A for ; Fri, 31 Mar 2017 16:02:42 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 9236E160B80; Fri, 31 Mar 2017 14:02:42 +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 D7D86160B79 for ; Fri, 31 Mar 2017 16:02:41 +0200 (CEST) Received: (qmail 54167 invoked by uid 500); 31 Mar 2017 14:02:41 -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 54157 invoked by uid 99); 31 Mar 2017 14:02:41 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 31 Mar 2017 14:02:41 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 9F89D18611E for ; Fri, 31 Mar 2017 14:02:40 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.648 X-Spam-Level: X-Spam-Status: No, score=0.648 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, KAM_INFOUSMEBIZ=0.75, RCVD_IN_DNSWL_NONE=-0.0001, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (1024-bit key) header.d=wp.pl Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id s7H62mXqujAz for ; Fri, 31 Mar 2017 14:02:39 +0000 (UTC) Received: from mx4.wp.pl (mx4.wp.pl [212.77.101.12]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 5D64D5FB9D for ; Fri, 31 Mar 2017 14:02:39 +0000 (UTC) Received: (wp-smtpd smtp.wp.pl 6282 invoked from network); 31 Mar 2017 16:02:33 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wp.pl; s=1024a; t=1490968953; bh=N4/RYyzEQ+TJOsffr1b1nqtZJqyJ28PLMdHBg4CrGZs=; h=From:To:Subject; b=xvP2wFwligFkyYswezdAhMIuSTcbBiftoz38DjqiN17zbpMOibNlZgnCZLxIUCOLw BoZqCc92lHJQ6u7A1dtho2sYgn/75z7CBd02XOPvk7pMCCcm3zwFWKm0BMVF/04bhX GZzHANjyAyS5Kpo6ILwqcT12FICjRpdbpQ1IyoUU= Received: from out.poczta.wp.pl ([212.77.101.240]) (envelope-sender ) by smtp.wp.pl (WP-SMTPD) with SMTP for ; 31 Mar 2017 16:02:33 +0200 Date: Fri, 31 Mar 2017 16:02:33 +0200 From: =?ISO-8859-2?Q?Marcin_Zaj=B1czkowski?= To: users@groovy.apache.org Subject: Custom implicit type conversion on assignment Message-ID: <58de6179125f74.31289350@wp.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-2 Content-Transfer-Encoding: 8bit Content-Disposition: inline X-Mailer: Interfejs WWW nowej poczty Wirtualnej Polski X-User-Agent: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0 Organization: Poznaj Poczte WP http://poczta.wp.pl/info-start.html X-WP-IP: 82.214.136.210 X-WP-MailID: d2b39a6edd024d49ef6fac191b62cc74 X-WP-AV: skaner antywirusowy Poczty Wirtualnej Polski X-WP-SPAM: NO 0000000 [YePU] archived-at: Fri, 31 Mar 2017 14:02:42 -0000 Hi, To simplify initialization of my production Money object in tests I've written an extension module to use explicit coercion: > Money tenDolars = 10.0 as Money //works fine, but could be shorter It works fine, but it's Groovy so I would like to achieve more :). My idea is to be able to write: > Money tenDolars = 10.0 //desired construction I was thinking about AST transformation (global or annotation based) to modify assignments like those (with Money on the left side and BigDecimal on the right) in a given class (or globally in a test context) to add explicit coercion automatically. Unfortunately, usually AST transformations I've found deal with adding methods or statements in a method. Could you point a Groovy build-in transformation or a place in Groovy code which deals with implicit coercion? Marcin -- http://blog.solidsoft.info/ - Working code is not enough