1 23 package org.hammurapi.inspectors.formatting; 24 25 import java.lang.reflect.InvocationTargetException ; 26 import java.lang.reflect.Method ; 27 import java.lang.reflect.Modifier ; 28 import java.util.HashMap ; 29 import java.util.Map ; 30 31 import com.pavelvlasov.jsel.impl.Token; 32 import org.hammurapi.HammurapiException; 33 34 35 42 public class FormattingCheckerBase implements FormattingChecker { 43 44 private static final String CHECK_PREFIX = "check_"; 45 46 private Map checkers=new HashMap (); 47 48 protected int indentationLevel=4; 49 50 { 51 Class thisClass=this.getClass(); 52 for (int i=0, mc=thisClass.getMethods().length; i<mc; i++) { 53 Method m=thisClass.getMethods()[i]; 54 if (!m.getName().equals(CHECK_PREFIX) 55 && Modifier.isPublic(m.getModifiers()) 56 && m.getName().startsWith(CHECK_PREFIX) 57 && m.getParameterTypes().length==1 58 && Token.class.isAssignableFrom(m.getParameterTypes()[0]) 59 && boolean.class.equals(m.getReturnType())) { 60 checkers.put(m.getName().substring(CHECK_PREFIX.length()), m); 61 } 62 } 63 } 64 65 public boolean check(Token aToken) throws HammurapiException { 66 Method m=(Method ) checkers.get(aToken.getTypeName()); 67 if (m==null) { 68 return false; 69 } else { 70 try { 71 return ((Boolean ) m.invoke(this, new Object [] {aToken})).booleanValue(); 72 } catch (IllegalArgumentException e) { 73 throw new HammurapiException(e); 74 } catch (IllegalAccessException e) { 75 throw new HammurapiException(e); 76 } catch (InvocationTargetException e) { 77 throw new HammurapiException(e); 78 } 79 } 80 } 81 82 public void setIndentationLevel(int indentationLevel) { 83 this.indentationLevel = indentationLevel; 84 } 85 } 86 87 88 | Popular Tags |