Skip to content

Apex_CustomRule: Check existence of specific class / method name using count function #3031

Answered by oowekyala
haigsn asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, on a first look there are two things that are wrong with your XPath expression:

  • A nested class in Apex is a UserClass directly under another UserClass (UserClassMethods is not a node, at least with PMD 6.16.0)
  • When you want to look for the children of a node, you shouldn't prefix the nested XPath expression with / -> this would search for children of the root of the document, not of the context node.
    So
//UserClass[count(/UserClassMethods[@Image="bulkApexTest"])=0]

becomes

//UserClass[count(./UserClass[@Image="bulkApexTest"])=0]

Notice the nested expression starts with ./, to select the children of the context node (which here is the outer UserClass).

Replies: 24 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by adangel
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1919 on January 15, 2021 09:23.