GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||
GeezerVison is showing github.com — [core] NodeStream API by oowekyala · Pull Request #1622 · pmd/pmd Conversation
Member
ContextWith the removal of Jaxen for 7.0.0, the method Lines 171 to 178 in 8a208b7
Doing the same check in Java without XPath would probably involve around 30 lines of clumsy null-check and type checks/casts. Changing the grammar to flatten the AST will simplify this partially, but it doesn't remove the problem. An alternative that Java 8 enables is node stream processing. Basically we can design an API where we can stream the descendants of a node, allowing to filter, flatmap to children of a certain type, flatmap to descendants, etc, in a completely type safe and null safe manner. Saxon itself has an API to write XPath-like queries in Java, leveraging the standard Stream API. From the Saxon HE doc:
That API is nice, but it's not typesafe, uses strings everywhere, and using it directly would force us to wrap the nodes in a Saxon adapter. This PRThis PR implements a feature-complete, self-contained API to stream nodes. NodeStreams
See the javadoc on the NodeStream interface for more details. The PR also refactors ForLoopCanBeForeachRule to use that new API. You can see how it blends well with Optional and regular Streams. What's more interesting is that I observed that the rule runs at least 30% faster! I would argue that with that new API in 7.0.0, we could deprecate the methods getFirstDescendantOfType, getFirstChildOfType, findFirstParentOfType, etc. until 8.0.0. Their functionality is superseded by the new API, and they're not lazy. What's missing yet:
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
There was an error while loading. Please reload this page.
Generated by 🚫 Danger |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
use iterator as main implementation
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.