1 package net.sourceforge.pmd.properties; 2 3 import java.lang.reflect.Method ; 4 5 8 public class MethodProperty extends AbstractPMDProperty { 9 10 17 public MethodProperty(String theName, String theDescription, Object theDefault, float theUIOrder) { 18 super(theName, theDescription, theDefault, theUIOrder); 19 } 20 21 26 public Class type() { 27 return Method .class; 28 } 29 30 37 public Object valueFrom(String propertyString) throws IllegalArgumentException { 38 39 Class cls = classIn(propertyString); 40 String methodName = methodNameIn(propertyString); 41 Class [] parameterTypes = parameterTypesIn(propertyString); 42 43 try { 44 return cls.getMethod(methodName, parameterTypes); 45 } catch (Exception e) { 46 throw new IllegalArgumentException ("invalid method: " + propertyString); 47 } 48 } 49 50 private Class classIn(String propertyString) throws IllegalArgumentException { 51 52 int dotPos = propertyString.lastIndexOf('.'); 53 String className = propertyString.substring(0, dotPos); 54 55 try { 56 return Class.forName(className); 57 } catch (Exception ex) { 58 throw new IllegalArgumentException ("class not found: " + className); 59 } 60 } 61 62 private String methodNameIn(String propertyString) throws IllegalArgumentException { 63 64 int dotPos = propertyString.lastIndexOf('.'); 65 return propertyString.substring(dotPos); 66 } 67 68 private Class [] parameterTypesIn(String propertyString) { 69 return null; 70 } 71 } 72 | Popular Tags |