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.LanguageElement; 30 import com.pavelvlasov.jsel.TypeDefinition; 31 32 33 39 public class InnerClassNestingRule extends InspectorBase implements Parameterizable { 40 44 private Integer maxNesting; 45 46 52 public void visit(TypeDefinition element) { 53 if (maxNesting!=null) { 54 int i=0; 55 for (LanguageElement parent=element.getParent(); parent!=null && parent instanceof TypeDefinition; parent=parent.getParent()) { 56 i++; 57 } 58 if (i>maxNesting.intValue()) { 59 context.reportViolation(element); 60 } 61 } 62 } 63 64 71 public boolean setParameter(String name, Object parameter) throws ConfigurationException { 72 if ("max-nesting".equals(name)) { 73 maxNesting = (Integer ) parameter; 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 ("Allowed maximum nesting for inner classes:\n"); 85 ret.append("max-nesting: " + maxNesting + "\n"); 86 return ret.toString(); 87 } 88 } 89 | Popular Tags |