ParameterNumber check after an @Override

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

ParameterNumber check after an @Override

Ronan DANIELLOU
Hi everyone,

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.

Does it make sense? If so, how may I do this? 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. This works. But I would have to maintain it in my project locally
for future checkstyle releases.

Thus, is there another better way to do it?
Do you think this request should become a feature request?

Thanks.

R.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user
Reply | Threaded
Open this post in threaded view
|

Re: ParameterNumber check after an @Override

Wippermann, Peter, Vodafone DE
Hi Ronan,

Very good idea, I really encourage you to submit this as a feature request! You could attach your sources to speed up things a little bit ;-)

Regarding the maintenance of your custom check: It depends on your implementation how much effort has to be put into maintenance.
Did you implement your custom check as a delegation to the original check? I mean something like this: http://en.wikipedia.org/wiki/Delegation_pattern#Simple
In that case all updates to the original check would become active in your check without the need to build and deliver your custom class again.

Best regards,
Peter Wippermann

P.S. I find it quite interesting how many users, who publish on this list, are actually from the TelCo (or associated) business! :-)
 

 
-----Ursprüngliche Nachricht-----
Von: Ronan DANIELLOU [mailto:[hidden email]]
Gesendet: Freitag, 10. August 2012 17:58
An: [hidden email]
Betreff: [Checkstyle-user] ParameterNumber check after an @Override

Hi everyone,

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.

Does it make sense? If so, how may I do this? 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. This works. But I would have to maintain it in my project locally for future checkstyle releases.

Thus, is there another better way to do it?
Do you think this request should become a feature request?

Thanks.

R.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user
Reply | Threaded
Open this post in threaded view
|

Re: ParameterNumber check after an @Override

Ronan DANIELLOU
Hello Peter,

thanks for your answer.

As a matter of facts, I made it work using inheritance:

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);
     }
   }
}

My concern about maintaining it was not so much about checkstyle by
itself, but more about the checkstyle plugin for eclipse, which adds XML
metadata files and other stuff on top of raw checkstyle jar for
including it in Eclipse.

And as always this kind of small stuff may add one to another in your
project and in the end you spend too much time taking care of small
maintenance tasks.

Thus I would rather rely on something existing in checkstyle, and
hopefully which will then exist in checkstyle plugin for eclipse later.

Feature request has been added:
https://sourceforge.net/tracker/?func=detail&aid=3557394&group_id=29721&atid=397081

Thanks,

R.

Le 13/08/2012 14:08, Wippermann, Peter, Vodafone DE a écrit :

> Hi Ronan,
>
> Very good idea, I really encourage you to submit this as a feature request! You could attach your sources to speed up things a little bit ;-)
>
> Regarding the maintenance of your custom check: It depends on your implementation how much effort has to be put into maintenance.
> Did you implement your custom check as a delegation to the original check? I mean something like this: http://en.wikipedia.org/wiki/Delegation_pattern#Simple
> In that case all updates to the original check would become active in your check without the need to build and deliver your custom class again.
>
> Best regards,
> Peter Wippermann
>
> P.S. I find it quite interesting how many users, who publish on this list, are actually from the TelCo (or associated) business! :-)
>
>
>
> -----Ursprüngliche Nachricht-----
> Von: Ronan DANIELLOU [mailto:[hidden email]]
> Gesendet: Freitag, 10. August 2012 17:58
> An: [hidden email]
> Betreff: [Checkstyle-user] ParameterNumber check after an @Override
>
> Hi everyone,
>
> 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.
>
> Does it make sense? If so, how may I do this? 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. This works. But I would have to maintain it in my project locally for future checkstyle releases.
>
> Thus, is there another better way to do it?
> Do you think this request should become a feature request?
>
> Thanks.
>
> R.
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Checkstyle-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/checkstyle-user
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Checkstyle-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/checkstyle-user
>

--
Ronan DANIELLOU
Alcatel-Lucent Submarine Networks
Software engineer
Centre de Villarceaux
Route de Villejust
Bureau: S 1.067
91620 NOZAY
France
Phone: +33 1 3077 2757
E-mail: [hidden email]

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Checkstyle-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user