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 B629F200B26 for ; Sun, 12 Jun 2016 13:20:22 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id B3B7D160A06; Sun, 12 Jun 2016 11:20:22 +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 0E91D160A2C for ; Sun, 12 Jun 2016 13:20:21 +0200 (CEST) Received: (qmail 53556 invoked by uid 500); 12 Jun 2016 11:20:21 -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 53537 invoked by uid 99); 12 Jun 2016 11:20:21 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 12 Jun 2016 11:20:21 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id E3FB42C033A for ; Sun, 12 Jun 2016 11:20:20 +0000 (UTC) Date: Sun, 12 Jun 2016 11:20:20 +0000 (UTC) From: "Paul King (JIRA)" To: notifications@groovy.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Created] (GROOVY-7860) Groovy could implement an @AutoImplement transform MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Sun, 12 Jun 2016 11:20:22 -0000 Paul King created GROOVY-7860: --------------------------------- Summary: Groovy could implement an @AutoImplement transform Key: GROOVY-7860 URL: https://issues.apache.org/jira/browse/GROOVY-7860 Project: Groovy Issue Type: New Feature Reporter: Paul King Assignee: Paul King Groovy provides numerous facilities for dynamically creating 'Proxy' implementations of interfaces, e.g.: {code} def emptyIterator = [hasNext: { false }] as Iterator {code} There is special support for Closures, maps of Closures, SAM method coercion and various proxy generator classes. Typically such dynamic creation is exactly what is required, e.g. a one-off usage object or a testing stub of some kind. But other times, compile time creation of such classes would be useful. This proposal suggests a transform to reduce boilerplate code for a number of common scenarios where code can be created. The proposal has numerous configuration options but doesn't try to support everything that the dynamic options provide. E.g. no map of Closures is supported; you _can_ just create a class manually in that case. The transform allows the above example to be as follows: {code} @AutoImplement class EmptyStringIterator implements Iterator { boolean hasNext() { false } } {code} which provides a method having signature '{{String next()}}' with an implementation that returns the default value for the return type ({{null}} for {{String}}). Alternatively, we can make it throw an exception as follows: {code} @AutoImplement(exception=UnsupportedOperationException) class EmptyStringIterator implements Iterator { boolean hasNext() { false } } {code} This would in fact be a closer match to the initial dynamic case shown above. -- This message was sent by Atlassian JIRA (v6.3.4#6332)