groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Milles (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-8376) Add @DelegatesTo to SwingBuilder methods that call setDelegate
Date Sun, 12 Nov 2017 17:55:00 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-8376?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16248930#comment-16248930
] 

Eric Milles commented on GROOVY-8376:
-------------------------------------

Thanks.  Along these same lines, {{DGM.identity}} is an alias for {{with}} but lacks the {{@DelegatesTo}}
and {{@ClosureParams}} annotations of {{with}}.
{code}
    /**
     * Allows the closure to be called for the object reference self.
     * Synonym for 'with()'.
     *
     * @param self    the object to have a closure act upon
     * @param closure the closure to call on the object
     * @return result of calling the closure
     * @since 1.0
     */
    public static <T> T identity(Object self, Closure<T> closure) {
        return DefaultGroovyMethods.with(self, closure);
    }

    public static <T,U> T with(
            @DelegatesTo.Target("self") U self,
            @DelegatesTo(value=DelegatesTo.Target.class,
                    target="self",
                    strategy=Closure.DELEGATE_FIRST)
            @ClosureParams(FirstParam.class)
            Closure<T> closure) {
        @SuppressWarnings("unchecked")
        final Closure<T> clonedClosure = (Closure<T>) closure.clone();
        clonedClosure.setResolveStrategy(Closure.DELEGATE_FIRST);
        clonedClosure.setDelegate(self);
        return clonedClosure.call(self);
    }

    public static <T,U> U tap(
            @DelegatesTo.Target("self") U self,
            @DelegatesTo(value=DelegatesTo.Target.class,
                    target="self",
                    strategy=Closure.DELEGATE_FIRST)
            @ClosureParams(FirstParam.class)
            Closure<T> closure) {
        return (U) with(self, true, (Closure<Object>)closure);
    }
{code}

> Add @DelegatesTo to SwingBuilder methods that call setDelegate
> --------------------------------------------------------------
>
>                 Key: GROOVY-8376
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8376
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Eric Milles
>
> 4 mehtods in SwingBuilder (edt, doLater, doOutside, build) call setDelegate(this) on
their closure params.  Could each have the param annotated with {{@DelegatesTo(SwingBuilder)}}?
> Ex:
> {code}
>     public Object build(@DelegatesTo(SwingBuilder) Closure c) {
>         c.setDelegate(this)
>         return c.call()
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message