Re: Preventing HAJOs
"Spoonauer, Michael" <[email protected]>
| Newsgroups | gmane.comp.java.audit.checkstyle.user |
|---|---|
| Message-ID | <5904C6EA1AC43B418E30B3D6FA2647520993A421@MSGMMKCLF2WIN.DMN1.FMR.COM> |
Thanks, Lars. Does either check sound like something it would make sense to add to a future distribution of Checkstyle? And I can't take credit for HAJO. J I heard it first from Ron Bodkin <http://rbodkin.blogs.com/> at NewAspects during his "Using Aspects to work with Annotations" talk at TSSJS 2007 in Las Vegas. Thanks again, Mike From: [email protected] [mailto:[email protected]] On Behalf Of Lars Kühne Sent: Tuesday, April 03, 2007 3:36 PM To: [email protected] Subject: Re: [Checkstyle-user] Preventing HAJOs Mike, yes, such a check should be pretty easy to write. The only slightly complicated part would be the import resolution to figure out the fully qualified name of an annotation. You could probably take a peek at the UnusedImports check sources in the checkstyle distribution to figure that out. Another idea that would be even easier to implement than the whitelist approach: Limit * the maximum number of annotations in a class divided by the number of method definitions + field definitions + 1. Some value around 2 or 3 should be a good default. * the maximum number of annotations per method/field/class. Probably something like 4 would be a good default This approach is completely straightforward to implement and would also be much easier to configure, no need for a project specific whitelist definition. Cheers, and thanks for contributing HAJO to the JAS (Java Acronym Soup) :-) Lars On 4/3/07, Spoonauer, Michael wrote: As our development teams begin to adopt the use of annotations within their Java classes, we would like to prevent the devolution of those classes into HAJOs (heavily annotated Java objects). Annotations make sense in some contexts, but not in all. Does anyone know if a Checkstyle engine running against a Java SE 5.0 class would be capable of determining what annotations have been defined within that class (whether at the class, method or field level)? If that is possible, we would probably pursue the definition of a custom check that limits the allowable annotations declared within a Java class to a configurable white list. Thanks, Mike ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Checkstyle-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/checkstyle-user