You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by uehaj <gi...@git.apache.org> on 2016/03/08 22:10:35 UTC

[GitHub] groovy pull request: Javalike method pointer groovy 7772

GitHub user uehaj opened a pull request:

    https://github.com/apache/groovy/pull/287

    Javalike method pointer groovy 7772

    This is a change for method pointer semantics in groovy discussed in following issue.
    https://issues.apache.org/jira/browse/GROOVY-7772
    
    ref.
    http://docs.groovy-lang.org/latest/html/documentation/index.html#method-pointer-operator
    https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html#type


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/uehaj/groovy javalike-method-pointer-GROOVY-7772

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/groovy/pull/287.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #287
    
----
commit 0308f6fe44ba354ba3eaf61d45f924895d09483d
Author: UEHARA Junji <ue...@jggug.org>
Date:   2016-03-07T21:18:54Z

    GROOVY-7772: Change method pointer like Java 8

commit f2ab90ea1ee0960d2a87b0feb536c4134841eb82
Author: UEHARA Junji <ue...@jggug.org>
Date:   2016-03-08T20:00:44Z

    GROOVY-7772: Add test cases.

commit 280a27b6b4715d153e01258670dda5131ebed187
Author: UEHARA Junji <ue...@jggug.org>
Date:   2016-03-08T20:28:32Z

    GROOVY-7772: Handle too few arguments as missing method exception.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] groovy pull request: Javalike method pointer groovy 7772

Posted by blackdrag <gi...@git.apache.org>.
Github user blackdrag commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/287#discussion_r55440244
  
    --- Diff: src/main/org/codehaus/groovy/runtime/MethodClosure.java ---
    @@ -62,9 +74,34 @@ public String getMethod() {
         }
     
         protected Object doCall(Object arguments) {
    +        if (getOwner() instanceof Class && !isStaticMethod) {
    +            if (arguments instanceof Object[]) {
    +                Object[] args = (Object[])arguments;
    +                if (args.length <= 0) {
    +                    throw new MissingMethodException(method, (Class)getOwner(), args);
    +                }
    +                Object insertedReceiver = args[0];
    +                Object[] newArgs = Arrays.copyOfRange(args, 1, args.length);
    +                return InvokerHelper.invokeMethod(insertedReceiver, method, newArgs);
    +            }
    +            return InvokerHelper.invokeMethod(arguments, method, new Object[]{});
    +        }
             return InvokerHelper.invokeMethod(getOwner(), method, arguments);
         }
     
    +    @SuppressWarnings("unchecked")
    +    public Object call(Object... args) {
    +        try {
    --- End diff --
    
    why do we need this method?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] groovy pull request: Javalike method pointer groovy 7772

Posted by blackdrag <gi...@git.apache.org>.
Github user blackdrag commented on a diff in the pull request:

    https://github.com/apache/groovy/pull/287#discussion_r55433138
  
    --- Diff: src/spec/test/CoercionTest.groovy ---
    @@ -214,7 +214,7 @@ boolean doFilter(String s) { s.contains('G') }
     Predicate filter = this.&doFilter
     assert filter.accept('Groovy') == true
     
    -Greeter greeter = GroovySystem.&getVersion
    +Greeter greeter = new GroovySystem().&getVersion
    --- End diff --
    
    this change does not make sense to me. getVersion is a static method, so GroovySystem.&getVersion must be fine


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---