Re: Writing tests that depend on information not available in the AST
"Lars Kühne" <[email protected]>
| Newsgroups | gmane.comp.java.audit.checkstyle.user |
|---|---|
| Message-ID | <[email protected]> |
On Fri, Mar 28, 2008 at 2:42 PM, Christian wrote: > ... For example I want to write a check that looks for > code that catches an exception to log an error and > then rethrows the same exception. This shall be > prohibited, provided the exception is a subclass of > some given class. > > Can I achieve this with checkstyle? I was thinking > about retrieving the name of the class via > IDENT.getText(), loading that class and finding out > about inheritance via reflection. Is this correct or > is there an easier way to achieve this? That should be possible, provided that the fully qualified class names of the exception classes can be deduced easily from the IDENT. Watch out for inner classes and such, but for typical exception classes it should work as you described. Another very popular tool, findbugs, works on the byte code level, and they might have a plugin api as well (not sure, but I know they have a plugin API internally). Maybe findbugs is a more suitable tool for your use case, as you have all information available at the byte code level. > Another issue: there's a good introduction tutorial on > writing new checks on the website, Thanks, good to hear that (I wrote most of it). > but it is limited > to the given example - is there some comprehensive > list of possibilities, such as a list of tags that can > be queried from the AST? Our javadoc of DetailAST should be quite complete, you have query methods like getChildCount(), branchContains(), etc. Is that what you meant with "tags"? /Lars ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace