List of usage examples for java.lang.reflect Method getName
@Override
public String getName()
From source file:org.psnively.scala.beans.ScalaBeanInfo.java
private static void addScalaSetter(Map<String, PropertyDescriptor> propertyDescriptors, Method writeMethod) { String propertyName = writeMethod.getName().substring(0, writeMethod.getName().length() - SCALA_SETTER_SUFFIX.length()); PropertyDescriptor pd = propertyDescriptors.get(propertyName); if (pd != null && pd.getWriteMethod() == null) { try {/*from w w w .ja v a 2 s .c o m*/ pd.setWriteMethod(writeMethod); } catch (IntrospectionException ex) { logger.debug("Could not add write method [" + writeMethod + "] for " + "property [" + propertyName + "]: " + ex.getMessage()); } } else if (pd == null) { try { pd = new PropertyDescriptor(propertyName, null, writeMethod); propertyDescriptors.put(propertyName, pd); } catch (IntrospectionException ex) { logger.debug("Could not create new PropertyDescriptor for " + "writeMethod [" + writeMethod + "] property [" + propertyName + "]: " + ex.getMessage()); } } }
From source file:com.helpinput.core.MapConvertor.java
/** * javaBean??Map// w w w.jav a2 s . c o m * * @param javaBean * javaBean * @return Map */ public static Map<String, Object> toMap(Object javaBean) { Map<String, Object> result = new HashMap<String, Object>(); Method[] methods = javaBean.getClass().getDeclaredMethods(); for (Method method : methods) { try { if (method.getName().startsWith("get")) { String field = method.getName(); field = field.substring(field.indexOf("get") + 3); field = field.toLowerCase().charAt(0) + field.substring(1); Object value = method.invoke(javaBean, (Object[]) null); result.put(field, null == value ? "" : value.toString()); } } catch (Exception e) { } } return result; }
From source file:com.helpinput.core.MapConvertor.java
/** * map??Javabean/* ww w . j a v a 2s . co m*/ * * @param javabean * javaBean * @param values * map? */ public static Object toJavaBean(Object javabean, Map<?, ?> data) { Method[] methods = javabean.getClass().getDeclaredMethods(); for (Method method : methods) { try { if (method.getName().startsWith("set")) { Class<?>[] parmaTypes = method.getParameterTypes(); if (parmaTypes.length == 1) { String fieldName = methodNameGetFieldName(method.getName()); Object value = Utils.convert(data.get(fieldName), parmaTypes[0]); method.invoke(javabean, value); // String field = method.getName(); // field = field.substring(field.indexOf("set") + 3); // field = field.toLowerCase().charAt(0) + field.substring(1); // method.invoke(javabean, new Object[] { data.get(field) }); } } } catch (Exception e) { } } return javabean; }
From source file:com.gargoylesoftware.htmlunit.javascript.host.ActiveXObject.java
/** * Gets the first method found of the class with the given name * and the correct annotation//from w w w . ja va2s. c o m * @param clazz the class to search on * @param name the name of the searched method * @param annotationClass the class of the annotation required * @return {@code null} if not found */ static Method getMethod(final Class<? extends SimpleScriptable> clazz, final String name, final Class<? extends Annotation> annotationClass) { if (name == null) { return null; } Method foundMethod = null; int foundByNameOnlyCount = 0; for (final Method method : clazz.getMethods()) { if (method.getName().equals(name)) { if (null != method.getAnnotation(annotationClass)) { return method; } foundByNameOnlyCount++; foundMethod = method; } } if (foundByNameOnlyCount > 1) { throw new IllegalArgumentException( "Found " + foundByNameOnlyCount + " methods for name '" + name + "' in class '" + clazz + "'."); } return foundMethod; }
From source file:org.kantega.dogmaticmvc.web.DogmaticMVCHandler.java
public static Method findSameMethod(Method method, Class classToTest) { for (Method m : classToTest.getMethods()) { if (m.getName().equals(method.getName()) && Arrays.equals(m.getParameterTypes(), method.getParameterTypes())) { method = m;//from ww w . j a va 2s .c o m break; } } return method; }
From source file:com.qcadoo.view.internal.CustomMethodHolder.java
public static boolean methodExists(final String className, final String methodName, final ApplicationContext applicationContext, final Class<?>[] expectedParameterTypes) { Preconditions.checkArgument(!StringUtils.isBlank(className), "class name attribute is not specified!"); Preconditions.checkArgument(!StringUtils.isBlank(methodName), "method name attribute is not specified!"); Preconditions.checkArgument(expectedParameterTypes != null, "expected parameter types are not specified!"); try {//from w w w. ja v a 2 s . c o m final Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(className); for (Method method : clazz.getMethods()) { if (method.getName().equals(methodName) && Arrays.deepEquals(method.getParameterTypes(), expectedParameterTypes)) { return true; } } return false; } catch (ClassNotFoundException e) { return false; } }
From source file:org.dimitrovchi.conf.service.ServiceParameterUtils.java
public static <P> P parameters(final String prefix, final Environment environment) { final AnnotationParameters aParameters = annotationParameters(); return (P) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), aParameters.annotations.toArray(new Class[aParameters.annotations.size()]), new InvocationHandler() { @Override//from w w w . j a v a 2 s . c o m public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if ("toString".equals(method.getName())) { return reflectToString(prefix, proxy); } return environment.getProperty(prefix + "." + method.getName(), (Class) method.getReturnType(), method.getDefaultValue()); } }); }
From source file:com.allinfinance.system.util.BeanUtils.java
/** * //from w ww . j a v a2s . co m * @param bean * @param map * @throws NoSuchMethodException * @throws InvocationTargetException * @throws IllegalAccessException */ public static void iterateBeanProperties(Object bean, Map<String, String> map) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { Method[] methods = bean.getClass().getMethods(); String propertyName = null; String methodName = null; for (Method method : methods) { methodName = method.getName(); if (methodName.startsWith("set")) { propertyName = methodName.substring(methodName.indexOf("set") + 3); propertyName = propertyName.substring(0, 1).toLowerCase() + propertyName.substring(1); map.put(propertyName, getProperty(bean, propertyName)); } } }
From source file:com.seleniumtests.util.StringUtility.java
public static String constructMethodSignature(final Method method, final Object[] parameters) { return method.getDeclaringClass().getCanonicalName() + "." + method.getName() + "(" + constructParameterString(parameters) + ")"; }
From source file:com.yahoo.sql4d.sql4ddriver.Util.java
public static List<Method> getAllSetters(Class<?> clazz) { Method[] allMethods = clazz.getMethods(); List<Method> setters = new ArrayList<>(); for (Method method : allMethods) { if (method.getName().startsWith("set")) { setters.add(method);//from w w w .j a v a2s .co m } } return setters; }