1 package com.puppycrawl.tools.checkstyle.checks.coding; 20 21 import com.puppycrawl.tools.checkstyle.api.DetailAST; 22 import com.puppycrawl.tools.checkstyle.api.FullIdent; 23 import com.puppycrawl.tools.checkstyle.api.TokenTypes; 24 import com.puppycrawl.tools.checkstyle.checks.CheckUtils; 25 26 31 public final class IllegalCatchCheck extends AbstractIllegalCheck 32 { 33 34 public IllegalCatchCheck() 35 { 36 super(new String [] {"Exception", "Error", 37 "RuntimeException", "Throwable", 38 "java.lang.Error", 39 "java.lang.Exception", 40 "java.lang.RuntimeException", 41 "java.lang.Throwable", 42 }); 43 } 44 45 46 public int[] getDefaultTokens() 47 { 48 return new int[] {TokenTypes.LITERAL_CATCH}; 49 } 50 51 52 public int[] getRequiredTokens() 53 { 54 return getDefaultTokens(); 55 } 56 57 58 public void visitToken(DetailAST aDetailAST) 59 { 60 final DetailAST paramDef = 61 aDetailAST.findFirstToken(TokenTypes.PARAMETER_DEF); 62 final DetailAST excType = paramDef.findFirstToken(TokenTypes.TYPE); 63 final FullIdent ident = CheckUtils.createFullType(excType); 64 65 if (isIllegalClassName(ident.getText())) { 66 log(aDetailAST, "illegal.catch", ident.getText()); 67 } 68 } 69 } 70 | Popular Tags |