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 C65B1200BA7 for ; Thu, 6 Oct 2016 14:11:23 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id C5265160AAD; Thu, 6 Oct 2016 12:11:23 +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 15D5A160AE0 for ; Thu, 6 Oct 2016 14:11:22 +0200 (CEST) Received: (qmail 68868 invoked by uid 500); 6 Oct 2016 12:11:22 -0000 Mailing-List: contact notifications-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.apache.org Delivered-To: mailing list notifications@groovy.apache.org Received: (qmail 68845 invoked by uid 99); 6 Oct 2016 12:11:22 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 06 Oct 2016 12:11:22 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 0991F2C2A66 for ; Thu, 6 Oct 2016 12:11:22 +0000 (UTC) Date: Thu, 6 Oct 2016 12:11:22 +0000 (UTC) From: =?utf-8?Q?C=C3=A9dric_Champeau_=28JIRA=29?= To: notifications@groovy.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (GROOVY-7956) Allow @DelegatesTo on named arguments MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Thu, 06 Oct 2016 12:11:24 -0000 [ https://issues.apache.org/jira/browse/GROOVY-7956?page=3Dcom.atlassia= n.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D155= 51773#comment-15551773 ]=20 C=C3=A9dric Champeau commented on GROOVY-7956: ----------------------------------------- Another option is to remove the {{Map}} version altogether, and rely on an = annotation to tell that we allow named arguments: {{code}} void animal(@NamedArguments Animal foo, ...) { ... } {{code}} which would allow the method to be called both with a map and an {{Animal}}= , without having to define the method twice. In addition, since we use "rea= l" types here, there's no generic type information loss. > Allow @DelegatesTo on named arguments > ------------------------------------- > > Key: GROOVY-7956 > URL: https://issues.apache.org/jira/browse/GROOVY-7956 > Project: Groovy > Issue Type: New Feature > Components: GEP > Reporter: Graeme Rocher > > In order to aid static compilation for builders we have {{@DelegatesTo}} = which allows statically compiled code to know what the delegate of a closur= e is. > This proposal is to allow {{@DelegatesTo}} on {{Map}} types such that IDE= s and the static compiler can resolve the target type the named arguments a= re to be used on. > For example: > {code} > class Farm { > void animal(@DelegatesTo(Animal) Map arguments, @DelegatesTo(AnimalB= uilder) Closure callable) { > def animal =3D new Animal(arguments) > // handle closure > } > }=20 > class Animal { String name } > {code} > The following code would then fail to compile : > {code} > def farm =3D new Farm() > // compilation failure, no name property on Animal > farm.animal(nam: "Dog") {=20 > } > {code} > It would then be down to IDEs to also provide support for code completion= etc. -- This message was sent by Atlassian JIRA (v6.3.4#6332)