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.Operation; 31 import com.pavelvlasov.jsel.TypeIdentifier; 32 33 39 public class ThrowTooGeneralExceptionTypeRule 40 extends InspectorBase implements Parameterizable { 41 42 48 public void visit(Operation operation) { 49 java.util.Iterator it=operation.getThrows().iterator(); 50 while (it.hasNext()) { 51 TypeIdentifier ti = (TypeIdentifier) it.next(); 52 try { 53 if (tooGeneralExceptions.contains(ti.getName())) { 54 context.reportViolation(ti); 55 } 56 } catch (JselException e) { 57 context.warn(operation, e); 58 } 59 } 60 } 61 62 66 private java.util.Set tooGeneralExceptions = new java.util.HashSet (); 67 68 75 public boolean setParameter(String name, Object parameter) throws ConfigurationException { 76 if ("general-exceptions".equals(name)) { 77 tooGeneralExceptions.add(parameter.toString()); 78 return true; 79 } 80 81 throw new ConfigurationException("Parameter '"+name+"' is not supported by "+getClass().getName()); 82 } 83 84 87 public String getConfigInfo() { 88 StringBuffer ret=new StringBuffer ("Not allowed exceptions:\n"); 89 java.util.Iterator iter = tooGeneralExceptions.iterator(); 90 while (iter.hasNext()) { 91 ret.append("general-exception: " + (String ) iter.next() + "\t"); 92 } 93 ret.append("\n"); 94 return ret.toString(); 95 } 96 } 97 | Popular Tags |