1 23 package org.hammurapi.inspectors; 24 25 import org.hammurapi.InspectorBase; 26 27 import com.pavelvlasov.config.ConfigurationException; 28 import com.pavelvlasov.config.Parameterizable; 29 import com.pavelvlasov.jsel.JselException; 30 import com.pavelvlasov.jsel.TypeSpecification; 31 import com.pavelvlasov.jsel.statements.Handler; 32 33 39 public class CatchTooGeneralExceptionTypeRule 40 extends InspectorBase implements Parameterizable { 41 42 47 public void visit(Handler expHandler) { 48 TypeSpecification ts = expHandler.getParameter().getTypeSpecification(); 49 try { 50 if (tooGeneralExceptions.contains(ts.getName())) { 51 context.reportViolation(expHandler); 52 } 53 } catch (JselException e) { 54 context.warn(expHandler, e); 55 } 56 } 57 58 62 private java.util.Set tooGeneralExceptions = new java.util.HashSet (); 63 64 71 public boolean setParameter(String name, Object parameter) throws ConfigurationException { 72 if ("general-exceptions".equals(name)) { 73 tooGeneralExceptions.add(parameter.toString()); 74 return true; 75 } else { 76 throw new ConfigurationException("Parameter '"+name+"' is not supported by "+getClass().getName()); 77 } 78 } 79 80 83 public String getConfigInfo() { 84 StringBuffer ret=new StringBuffer ("Too general exceptions to be catched:\n"); 85 java.util.Iterator iter = tooGeneralExceptions.iterator(); 86 while (iter.hasNext()) { 87 ret.append("general-exception: " + (String ) iter.next() + "\t"); 88 } 89 ret.append("\n"); 90 return ret.toString(); 91 } 92 } 93 | Popular Tags |