[core] Make Saxon support multi valued XPath properties#736
Conversation
|
Sidenote: Maybe we should throw an error when trying to use a multivalued property with Jaxen. The problem is that it treats the value as a string, which is the |
| Map<String, PropertyDescriptorExternalBuilder<?>> temp = new HashMap<>(18); | ||
| temp.put("Boolean", BooleanProperty.extractor()); | ||
| temp.put("List<Boolean>", BooleanMultiProperty.extractor()); | ||
| temp.put("List[Boolean]", BooleanMultiProperty.extractor()); |
There was a problem hiding this comment.
Wouldn't that break compatibility with existing (Java-based) rules, that use already multi-valued properties? Maybe we can have both variants in the map?
There was a problem hiding this comment.
Java-based rules don't use these factories, only XPath rules.
It breaks compatibility, but no more than the List<> form. As of release 5.8.1, the name of those properties had the form Boolean[], like an array (the List<> form was introduced during #504). Whatever we choose breaks compatibility.
But I have to stress that none of that is documented behaviour for now. It's very unlikely anyone uses it, and if they do, documentation and release notes may be enough.
There was a problem hiding this comment.
@oowekyala I agree - the old code for XPath 1.0 (Jaxen) just does a toString (which was for multi-valued properties just an array) and with XPath 1.0 compatible/2.0 (Saxon) we rejected such properties.
So, yes, we can choose freely here. Avoiding the < helps for usage inside XML, so I'm good with your suggestion List[Boolean].
|
@oowekyala Could you check, whether this todo is the same problem? Not possible to declare a multi-valued string property for a xpath rule? Thanks! |
|
@adangel The todo is now fixed. The The todo also mentioned using the value of the property in the message, which isn't currently supported. There may be a use case for it though. |
|
Err on jdk8 the tests of InvalidDependencyType work, but on jdk9 there's an IllegalAccessException thrown from there. Debugger shows that it's a call to |
|
After some digging I found this relevant resource. I think we may be in case 2.a : the proxy we use is in a dynamic module, (here named jdk.proxy2) which makes it inaccessible to the unnamed package (in which the code of pmd currently lives I guess). No idea how to correct that though Edit: This issue is not directly related to this PR. I'm reverting the commit, we can keep track of the issue in #739 |
This reverts commit 9e6be2d.
|
Note when merging this: Update the doc at Working with properties |
|
@oowekyala FYI: I've decided to merge this into 6.0.0. Since it's ready and it's actually a new feature: xpath multi valued properties can be used now! |
|
@adangel Great :) |
As exposed in #735, XPath rules couldn't declare multi valued properties due to a trivial error. That is now corrected.
Additionally, XPath rules couldn't actually use such properties, nor did they support all properties they could (see the code which translates PMD properties to XPath variables for Saxon). I corrected that for Saxon, making use of the sequence datatype provided by XPath 2.0. Jaxen treats any value as a string anyway
Hopefully this can make XPath rules more expressive, and make better use of saxon's capabilities.
Some possible improvements
I'd say that we should remove the factories for Method and File properties. They're unlikely to be useful anyway, and people can use StringProperty instead. TypeProperty could still be useful, especially with type resolution. Wdyt?
Should I create tickets to track these, too?