[java] Better handle explicit receiver parameters#1017
Conversation
- Allow sto match all method calls, meaning UnusedPrivateMethod will not longer produce false positives - Resolves pmd#719
| public int getParameterCount() { | ||
| return jjtGetNumChildren(); | ||
| return jjtGetNumChildren() > 0 && getFirstChildOfType(ASTFormalParameter.class).isExplicitReceiverParameter() | ||
| ? jjtGetNumChildren() - 1 : jjtGetNumChildren(); |
There was a problem hiding this comment.
@adangel @oowekyala I know this is very opinionated, so I'd like to know your opinion.
My position is, that when asking about a parameter count you are mostly interested in the number of parameters you need to pass to the method / constructor. You don't really care about explicit receiver parameters, which are by definition, only for internal use of the method itself. We may add a new method if the need arises to get the "explicit parameter count", but so far I see no use for it.
I do wonder however, if the AST shouldn't be completely changed and have the explicit receiver param be a different kind of node than formal parameters... the JSL does define it separately after all. Under that scenario, the outward behavior of this method would remain as in my implementation, so editing the grammar to split it may be done in 7.0.0 while this implementation can be used in the meantime.
There was a problem hiding this comment.
@jsotuyod Yes, it makes sense to ignore explicit receiver parameters for the ParameterCount.
The code looks quite complex for determining the count - I've just created #1019 to track this (and probably other grammar changes) for PMD 7.0.0. With the grammar change in place, it should be something like this: findChildrenOfType(ASTFormalParameter.class).size();
| public int getParameterCount() { | ||
| return jjtGetNumChildren(); | ||
| return jjtGetNumChildren() > 0 && getFirstChildOfType(ASTFormalParameter.class).isExplicitReceiverParameter() | ||
| ? jjtGetNumChildren() - 1 : jjtGetNumChildren(); |
There was a problem hiding this comment.
@jsotuyod Yes, it makes sense to ignore explicit receiver parameters for the ParameterCount.
The code looks quite complex for determining the count - I've just created #1019 to track this (and probably other grammar changes) for PMD 7.0.0. With the grammar change in place, it should be something like this: findChildrenOfType(ASTFormalParameter.class).size();
|
@adangel thanks! I'll rework it before merging |
getParameterCount()calls