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 ThrowsClauseRule extends InspectorBase implements Parameterizable { 40 41 47 public void visit(Operation element) { 48 java.util.Iterator throwsList = element.getThrows().iterator(); 49 50 while (throwsList.hasNext()) { 51 TypeIdentifier item = (TypeIdentifier) throwsList.next(); 52 try { 53 if (!allowedThrows.contains(item.getName())) { 54 context.reportViolation(element, new Object [] {item}); 55 } 56 } catch (JselException e) { 57 context.warn(item, e); 58 } 59 } 60 } 61 62 66 private java.util.Set allowedThrows = new java.util.HashSet (); 67 68 75 public boolean setParameter(String name, Object parameter) throws ConfigurationException { 76 if ("allowed-throw".equals(name)) { 77 allowedThrows.add(parameter.toString()); 78 return true; 79 } else { 80 throw new ConfigurationException("Parameter '"+name+"' is not supported by "+getClass().getName()); 81 } 82 } 83 84 87 public String getConfigInfo() { 88 StringBuffer ret=new StringBuffer ("Allowed exceptions in the thorws clauses:\n"); 89 java.util.Iterator iter = allowedThrows.iterator(); 90 while (iter.hasNext()) { 91 ret.append("allowed-throw: " + (String ) iter.next() + "\t"); 92 } 93 ret.append("\n"); 94 return ret.toString(); 95 } 96 } 97 | Popular Tags |