01: package net.sourceforge.pmd.rules.strictexception;
02:
03: import net.sourceforge.pmd.AbstractRule;
04: import net.sourceforge.pmd.ast.ASTCatchStatement;
05: import net.sourceforge.pmd.ast.ASTClassOrInterfaceType;
06: import net.sourceforge.pmd.ast.ASTType;
07:
08: /**
09: * 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 visit(ASTCatchStatement node, Object data) {
18: ASTType type = node.findChildrenOfType(ASTType.class).get(0);
19: ASTClassOrInterfaceType name = type.findChildrenOfType(
20: ASTClassOrInterfaceType.class).get(0);
21: if (name.hasImageEqualTo("Throwable")) {
22: addViolation(data, name);
23: }
24: return super.visit(node, data);
25: }
26: }
|