Issue Details (XML | Word | Printable)

Key: GROOVY-1851
Type: New Feature New Feature
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Paul King
Reporter: Maurice Nicholson
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
groovy

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

Created: 23/Apr/07 07:12 AM   Updated: 22/Nov/07 05:23 AM
Component/s: None
Affects Version/s: None
Fix Version/s: 1.1-rc-1

Time Tracking:
Not Specified


 Description  « Hide
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



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Paul King added a comment - 09/Oct/07 11:32 PM
You can now override negative(), positive() and bitwiseNegate() corresponding to -x, +x, ~x.