Groovy
  1. Groovy
  2. GROOVY-1851

Expose unary plus and unary minus operators as interceptable method calls: positive() and negative()

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.1-rc-1
    • Component/s: None
    • Labels:
      None

      Description

      I'm writing a Groovy builder for Compass (Lucene) queries, and it would be nice to use + and - in the closure, since it mirrors Lucene's own query string syntax, eg:

          def query = builder.build {
             +term('keywords', 'book')
             -term('keywords', 'audio')
             queryString('color theory')
         } 
      

      would create a query that in Lucene query string syntax looks like +keywords:book -keywords:audio all:color all:theory.

      (Incidentally this query means: 'keywords' MUST have the value 'book' and MUST NOT have the value 'audio' and 'all' SHOULD (may or may not) have 'color' and 'theory'.)

      Ok they don't mirror each other exactly, but for those familar with Lucene query string syntax I think this will just feel "right".

      So can these + and - operators be made interceptable method calls?

      I think the opinion of the list was to use positive() and negative() as the method names: http://www.nabble.com/use-of-%2B-and---in-DSL--tf3623677.html

        Activity

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        169d 16h 19m 1 Paul King 10/Oct/07 00:32
        Resolved Resolved Closed Closed
        43d 5h 50m 1 Paul King 22/Nov/07 05:23
        Mark Thomas made changes -
        Workflow jira [ 12969233 ] Default workflow, editable Closed status [ 12977014 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12730966 ] Default workflow, editable Closed status [ 12742916 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Paul King made changes -
        Field Original Value New Value
        Resolution Fixed [ 1 ]
        Fix Version/s 1.1-rc-1 [ 13165 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Assignee Paul King [ paulk ]
        Hide
        Paul King added a comment -

        You can now override negative(), positive() and bitwiseNegate() corresponding to -x, +x, ~x.

        Show
        Paul King added a comment - You can now override negative(), positive() and bitwiseNegate() corresponding to -x, +x, ~x.
        Maurice Nicholson created issue -

          People

          • Assignee:
            Paul King
            Reporter:
            Maurice Nicholson
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development