[CheckStyle] forbidding a particular method

O

oliviergir

Hello,
How can I implement a rule with checkstyle that would warn when the
code would call the method "receive()" on an instance of the class
"MessageConsumer" ?

I know that checkstyle might not be the appropriate tool for that, but
could I chek that the method "receive" is not called with a long
parameter superior with 5000 ?

thanks
 
C

Carl

Hello,
How can I implement a rule with checkstyle that would warn when the
code would call the method "receive()" on an instance of the class
"MessageConsumer" ?

I know that checkstyle might not be the appropriate tool for that, but
could I chek that the method "receive" is not called with a long
parameter superior with 5000 ?

thanks

Hello,

I Have no experience with checkstyle, but based on my understanding of
your question I think that java assertions may fit your requirements.

See
http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html
for more details.

Alternatively, you could just have your method throw an
IllegalArgumentException if the argument was out of range.

Hope this helps,
Carl.
 
O

Oliver Wong

Carl said:
Hello,

I Have no experience with checkstyle, but based on my understanding of
your question I think that java assertions may fit your requirements.

See
http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html
for more details.

Alternatively, you could just have your method throw an
IllegalArgumentException if the argument was out of range.

Presumably the OP wishes to check for these violations at compile time
(because they've got an ant script to automatically run checkstyle right
after compilation, for example), rather than runtime. I'm not familiar with
checkstyle, so I don't know how to solve this using CheckStyle either, but
it can be solved using AspectJ.

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top