Re: Looking for additional checks

"Lars Kühne" <[email protected]>
Newsgroups gmane.comp.java.audit.checkstyle.user
Message-ID <[email protected]>
On 9/24/07, Arindam.Chandra wrote:
>
>  Hi,
>
>
>
> We want to include the following checks in CheckStyle;-
>
>
>
> a.                   in String equals check, the constant should be on
> LHS. If both are variables then the LHS variable should have a null check
>

The first part should be easy to implement, just try to find METHOD_CALL
tree nodes with name "equals" and a single parameter String literal.

The second part is impossible to implement as a checkstyle check, because of
architectural limitations in checkstyle. Bytecode checkers like Findbugs are
probably better suited for this, because they have full type information and
I guess they already analyze control flow.


b.                   size/length calculation of Collections should be done
> outside loops
>

This rule is questionable. Consider this code, which tries to filter the
first 5 entries from another collection that start with "X":

List<String> result = new ArrayList();
for (String orig: otherCollection) {
  if (result.size() == 5) {
    break;
  }
  if (orig.startsWith("X") {
    result.add(orig);
  }
}

You can't pull the result.size() call out of the for loop without modifying
behavior.


c.                   there should not be commented out code in java files
>

How does "code" look like?

Maybe you might get good results by configuring multiple TodoComment checks,
each with a different formats, one for each pattern that smells like java
syntax and not natural language. Example patterns would include something
like "=.*;", "for *(", "while *(", etc.

I have gone through the documentation on "how to write customized checks"
> but could not figure how out the above three.
>
>
>
> Also, is it possible to detect unused imports, excessive logic etc. in JSP
> through CheckStyle.
>

No. We get this question quite often, but to our knowledge there isn't a JSP
parser available.

Regards,
Lars

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

_______________________________________________
Checkstyle-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/checkstyle-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.