Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-345

Expando did not use native property

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.0-beta-5
    • 1.0-beta-6
    • None
    • None
    • XP, latest HEAD

    Description

      The idea is to get this to work, as said by John:

      If f is a method in the object then call the method otherwise if f is a property and is an instance of Closure then call the closure.

      import groovy.util.Expando
      class F extends Expando{
      p = 1;
      p()

      { 'p' }

      q =

      { 'q' }

      }

      f = new F()

      println f.p // property access
      println f.p() // function access with a match
      println f.q.call() // property access
      println f.q() // call function first then find a closure property to call

      produced:

      1
      p
      q
      q

      The last statement now is a valid run.

      Here is the patch: (a oneliner)

      Index: Expando.java
      ===================================================================
      RCS file: /scm/cvspublic/groovy/groovy-core/src/main/groovy/util/Expando.java,v
      retrieving revision 1.1
      diff -u -r1.1 Expando.java
      — Expando.java 31 Dec 2003 12:39:47 -0000 1.1
      +++ Expando.java 30 Mar 2004 18:17:36 -0000
      @@ -103,7 +103,9 @@
      return super.invokeMethod(name, args);
      }
      catch (GroovyRuntimeException e) {

      • Object value = getExpandoProperties().get(name);
        + //br: Object value = getExpandoProperties().get(name);
        + // should get a "native" property match first. getProperty includes such fall-back logic
        + Object value = this.getProperty(name);
        if (value instanceof Closure) {
        Closure closure = (Closure) value;
        closure.setDelegate(this);

      Attachments

        Activity

          People

            Unassigned Unassigned
            bingran Bing Ran
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 5m
                5m
                Remaining:
                Remaining Estimate - 5m
                5m
                Logged:
                Time Spent - Not Specified
                Not Specified