groovy/groovy-core — pull request #174 by eddelplus (2013-04-27 11:30:59+00:00)
Title: GROOVY-6125 Bugs in GPathResult.parent() and .findAll()

The XmlSlurper sample from the documentation fails these additional asserts:

assert records.car.record.findAll({it.@type == 'price'}).parent().country == 'France'
assert records.car.country.findAll({it == 'Australia'}).'..'.record.@type == 'speed'

On on an XML, where some _cars_ don't have a _country_ child this expression will still return all countries

records.cars.country.parent()

It should only return _cars_ with at least one _country_ child.

Fixing the problem involved:

* Adding a public parent() method and parent private property to Node
* Implementing an additional subclass NodeParents of GPathResult
* Simplifying childNodes() in NodeChildren, so that it utilizes the classes nodeIterator()
* Implementing ParentNodes with a nodeIterator() override
* Cleaning up FilteredNode children to follow the same pattern
* Instantiating ParentNodes in GPathResult.parent()
* Calling parent() for property '..'

And as an added refinement to the GPath syntax:

* Defining GPathResult.getAt(closure) to call findAll(closure)

Sorry my NetBeans editor screwed up the JavaDoc indentation, make the diff a bit difficult the read.