KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > pmd > rules > strictexception > AvoidCatchingThrowable


1 package net.sourceforge.pmd.rules.strictexception;
2
3 import net.sourceforge.pmd.AbstractRule;
4 import net.sourceforge.pmd.ast.ASTCatchStatement;
5 import net.sourceforge.pmd.ast.ASTClassOrInterfaceType;
6 import net.sourceforge.pmd.ast.ASTType;
7
8 /**
9  * Finds <code>catch</code> statements
10  * containing <code>throwable</code> as the type definition.
11  * <p/>
12  *
13  * @author <a mailto:trondandersen@c2i.net>Trond Andersen</a>
14  */

15 public class AvoidCatchingThrowable extends AbstractRule {
16
17     public Object JavaDoc visit(ASTCatchStatement node, Object JavaDoc data) {
18         ASTType type = (ASTType) node.findChildrenOfType(ASTType.class).get(0);
19         ASTClassOrInterfaceType name = (ASTClassOrInterfaceType) type.findChildrenOfType(ASTClassOrInterfaceType.class).get(0);
20         if (name.hasImageEqualTo("Throwable")) {
21             addViolation(data, name);
22         }
23         return super.visit(node, data);
24     }
25 }
26
Popular Tags