[CheckStyle] forbidding a particular method

Discussion in 'Java' started by oliviergir@gmail.com, Mar 30, 2006.

  1. Guest

    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
    , Mar 30, 2006
    #1
    1. Advertising

  2. Carl Guest

    Re: forbidding a particular method

    wrote:
    > 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.
    Carl, Mar 30, 2006
    #2
    1. Advertising

  3. Oliver Wong Guest

    Re: forbidding a particular method

    "Carl" <> wrote in message
    news:...
    > wrote:
    >> 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.


    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
    Oliver Wong, Mar 30, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    18
    Views:
    1,245
    Roedy Green
    Jan 31, 2006
  2. Tim B
    Replies:
    1
    Views:
    2,018
    Tim B
    Apr 29, 2006
  3. Marcin Kalicinski
    Replies:
    5
    Views:
    382
    Buster
    Apr 2, 2004
  4. Replies:
    0
    Views:
    400
  5. Tim Slattery

    Nul lPointer Exception in Checkstyle

    Tim Slattery, Oct 13, 2011, in forum: Java
    Replies:
    1
    Views:
    1,125
    Tim Slattery
    Oct 14, 2011
Loading...

Share This Page