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.Field; 30 import com.pavelvlasov.jsel.TypeDefinition; 31 import com.pavelvlasov.jsel.VariableDefinition; 32 33 34 40 public class MinimalInstanceVariableLengthRule extends InspectorBase implements Parameterizable { 41 42 48 public void visit(TypeDefinition element) { 49 java.util.Iterator iter = element.getFields().iterator(); 50 while (iter.hasNext()) { 51 Field field = (Field) iter.next(); 52 if (field instanceof VariableDefinition) { 53 VariableDefinition vd = (VariableDefinition) field; 54 String name = vd.getName(); 55 if (name.length()<minLength.intValue()) { 56 context.reportViolation(vd); 57 } 58 } 59 } 60 } 61 65 private Integer minLength; 66 67 68 75 public boolean setParameter(String name, Object value) throws ConfigurationException { 76 if ("min-length".equals(name)) { 77 minLength= (Integer ) value; 78 } else { 79 throw new ConfigurationException("Parameter '"+name+"' is not supported"); 80 } 81 return true; 82 } 83 84 87 public String getConfigInfo() { 88 StringBuffer ret=new StringBuffer ("Allowed minimal length for instance variable names:\n"); 89 ret.append("length: " + minLength + "\n"); 90 return ret.toString(); 91 } 92 } 93 | Popular Tags |