How to have nested conditions for PMD Xpath rules

前端 未结 1 443
Happy的楠姐
Happy的楠姐 2021-01-16 12:18

My rule requires me to apply them only to methods without \'get\' as part of their name. In another words, my rules need to apply to only non-getter methods in the class. I

1条回答
  •  情话喂你
    2021-01-16 12:59

    You need to have at least some basic knowledge/understanding of XPath.

    I saw the use of . in the beginning of statement inside [] in some example code. what are they used for?

    [] is called predicate. It must contain a boolean expression. It must immediately follow a node-test. This specifies an additional condition for a node that satisfies the node-test to be selected.

    For example:

    /*/num
    

    selects all elements named num that are children of the top element of the XML document.

    However, if we want to select only such num elements, whose value is an odd integer, we add this additional condition inside a predicate:

    /*/num[. mod 2 = 1]
    

    Now this last expression selects all elements named num that are children of the top element of the XML document and whose string value represents an odd integer.

    . denotes the context node -- this is the node that has been selected so-far (or the starting node off which the complete XPath expression is evaluated).

    In my particular case, I need to combine following pieces together ...

    You forgot to say in what way / how the three expressions should be combined. In XPath some of the frequently used "combinators" are the operators and, or, and the function not().

    For example, if you want to select elements that are selected by all three provided XPath expressions, you can use the and operator:

    //PrimaryExpression
       [not(PrimarySuffix/Arguments)
      and
        PrimaryPrefix/@Label='this'
       ] 
    

    0 讨论(0)
提交回复
热议问题