views:

104

answers:

3

I'm using the CheckStyle plugin for Eclipse.

It's great at finding things I didn't intend 99% of the time, but the 1% of the time I actually did intent to knowingly violate a rule, I would like to let CheckStyle know it need not concern itself with flagging a warning.

Example: the Missing a Javadoc comment rule. Most of the time I want Javadoc comments on my methods. However, a method such as:

public boolean isValid() {
  return valid;
}

can probably get by without one.

Is there anything like the @SuppressWarnings annotation which can be used to flag a specific CheckStyle rule violation as acceptable? Some sort of specially formatted comment, maybe? I don't want to disable the rule, I just want to ignore a specific violation.

(I realize in this case I could just write the Javadoc comment, but in other cases fixing the rule violation isn't so simple).

A: 

Install this plug-in: http://eclipse-cs.sourceforge.net/

It will give you a GUI for selecting rules you want to apply. Or you can directly edit the XML config file, although this is quite tedious.

edit 1: OK, you want to suppress warning only for one method. Sorry I didn't get your point.

Pierre Gardin
he already has the plugin. He wants to suppress warnings
Bozho
He doesn't say WHICH plugin. there are several of them.
Pierre Gardin
"He wants to suppress warnings"this is exactly what I provide in my reply.
Pierre Gardin
A: 

Seems pretty tedious but there needs to be explicit XML configuration to ignore it. You can probably find a GUI to do it via using the Checkstyle plugin for Eclipse or Netbeans. The example I've found is on the Checkstyle configuration page.

<?xml version="1.0"?>

<!DOCTYPE suppressions PUBLIC
    "-//Puppy Crawl//DTD Suppressions 1.1//EN"
    "http://www.puppycrawl.com/dtds/suppressions_1_1.dtd"&gt;

<suppressions>
    <suppress checks="JavadocStyleCheck"
              files="AbstractComplexityCheck.java"
              lines="82,108-122"/>
    <suppress checks="MagicNumberCheck"
              files="JavadocStyleCheck.java"
              lines="221"/>
</suppressions>
Synthesis
+1  A: 

Synthesis pointed to the Checkstyle configuration page. Skimming it, I found SuppressWithNearbyCommentFilter which seems promising, unless I misunderstood its purpose...

PhiLho