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 Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.1-rc-1
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      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

        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.
        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 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

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

            Dates

            • Created:
              Updated:
              Resolved: