#602 ParameterNumber check after an @Override

Future
closed
nobody
Check (274)
5
2013-11-17
2012-08-14
Ronan
No

Hi everyone,

(Initially this was a question asked on the mailing list, see https://sourceforge.net/mailarchive/message.php?msg_id=29660441)

I am using a rule for the parameter number. Nevertheless, I sometimes have to override some methods (in Swing, for example). Those methods may have more parameters than what the rule is configured to allow. I would like this rule to be ignored when applied to an overridden method.

I have looked at suppression filters, but they work either with a configuration file (that you need to maintain) or keywords in the code (which makes you add to your files, text for a specific tool).

Trying to write a custom filter, for what I have understood, it seems to allow reaching text and the lines of it, but you do not have access to a structure as you have in a check. I was worried that using some kind of text regexp on a line would be brittle.

Thus I have written a custom check, inheriting from ParameterNumberCheck class. But I would rather rely on something existing in checkstyle natively.

public class ParameterNumberCheckCustom extends ParameterNumberCheck {

@Override
public void visitToken(DetailAST ast) {
// if you override a method, you have no power over the (too numerous)
// number of parameters.
if (!AnnotationUtility.containsAnnotation(ast, "Override")) {
super.visitToken(ast);
} else {
final String message = "@Override found, skipping ParameterNumber check.";
System.out.println(message);
}
}
}

What do you think? Would some kind of filter be a better idea? What about a parameter for the existing ParameterNumberCheck class?

Thanks.

Discussion

  • Ivan Sopov

    Ivan Sopov - 2013-11-17
    • status: open --> closed
    • Group: --> Future
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks