Example usage for java.lang.reflect Method getName

List of usage examples for java.lang.reflect Method getName

Introduction

In this page you can find the example usage for java.lang.reflect Method getName.

Prototype

@Override
public String getName() 

Source Link

Document

Returns the name of the method represented by this Method object, as a String .

Usage

From source file:net.mindengine.galen.reports.GalenTestInfo.java

public static GalenTestInfo fromMethod(Method method) {
    String name = method.getDeclaringClass().getName() + "#" + method.getName();
    return GalenTestInfo.fromString(name);
}

From source file:Main.java

public static boolean isAccessor(Method method, String findValue) {
    boolean accessor = false;
    final Class<?>[] parameterTypes = method.getParameterTypes();
    final String methodName = method.getName();
    if (parameterTypes.length == 0 && method.getReturnType() != null
            && (methodName.startsWith("get") || methodName.startsWith("is"))
            && methodName.toLowerCase().indexOf(findValue.toLowerCase()) > -1) {
        accessor = true;// ww  w .j  a va  2 s. com
    }
    return accessor;
}

From source file:com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable.java

/**
 * Returns the method with the specified name.
 *///from  www . j  a va 2  s .c o  m
private static Method findMethod(final Method[] methods, final String name) {
    for (Method m : methods) {
        if (m.getName().equals(name)) {
            return m;
        }
    }
    return null;
}

From source file:com.spstudio.common.log.ServiceExceptionLogAspect.java

/**
 * *//from  w w  w . j  av  a2 s  .  c  o  m
 * ???? service *
 *
 *
 * @param joinPoint 
 *
 * @return ??
 *
 * @throws Exception *
 */
public static String getServiceMthodDescription(JoinPoint joinPoint) throws Exception {

    String targetName = joinPoint.getTarget().getClass().getName();

    String methodName = joinPoint.getSignature().getName();

    Object[] arguments = joinPoint.getArgs();

    Class targetClass = Class.forName(targetName);

    Method[] methods = targetClass.getMethods();

    String description = ":" + targetName + " ;??:" + methodName
            + " ;???:";

    for (Method method : methods) {

        if (method.getName().equals(methodName)) {

            Class[] clazzs = method.getParameterTypes();

            if (clazzs.length == arguments.length) {

                description += method.getAnnotation(ServiceExceptionLog.class).description();

                break;

            }

        }

    }

    return description;

}

From source file:com.jsen.core.reflect.ClassFunction.java

/**
 * Extract the function name from the method.
 * /* w w w  . j a  va 2  s .co m*/
 * @param method Method of which name should be extracted.
 * @return Name of the function.
 */
public static String extractFunctionName(Method method) {
    return method.getName();
}

From source file:Main.java

public static void setProperties(Object object, Map<String, ? extends Object> properties,
        boolean includeSuperClasses) {
    if (object == null || properties == null) {
        return;/*from w w w . j  a v a  2 s .  c o m*/
    }

    Class<?> objectClass = object.getClass();

    for (Map.Entry<String, ? extends Object> entry : properties.entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();
        if (key != null && key.length() > 0) {
            String setterName = "set" + Character.toUpperCase(key.charAt(0)) + key.substring(1);
            Method setter = null;

            // Try to use the exact setter
            if (value != null) {
                try {
                    if (includeSuperClasses) {
                        setter = objectClass.getMethod(setterName, value.getClass());
                    } else {
                        setter = objectClass.getDeclaredMethod(setterName, value.getClass());
                    }
                } catch (Exception ex) {
                }
            }

            // Find a more generic setter
            if (setter == null) {
                Method[] methods = includeSuperClasses ? objectClass.getMethods()
                        : objectClass.getDeclaredMethods();
                for (Method method : methods) {
                    if (method.getName().equals(setterName)) {
                        Class<?>[] parameterTypes = method.getParameterTypes();
                        if (parameterTypes.length == 1 && isAssignableFrom(parameterTypes[0], value)) {
                            setter = method;
                            break;
                        }
                    }
                }
            }

            // Invoke
            if (setter != null) {
                try {
                    setter.invoke(object, value);
                } catch (Exception e) {
                }
            }
        }
    }
}

From source file:it.govpay.model.BasicModel.java

public static String diff(Object a, Object b)
        throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    if (a == null && b != null)
        return "[NULL] [NOT NULL]";
    if (a != null && b == null)
        return "[NOT NULL] [NULL]";
    if (a == null && b == null)
        return null;

    Method[] methods = a.getClass().getDeclaredMethods();
    for (Method method : methods) {
        if ((method.getName().startsWith("get") || method.getName().startsWith("is"))
                && method.getParameterTypes().length == 0) {
            if (method.getReturnType().isAssignableFrom(List.class)) {
                String diff = diff((List<?>) method.invoke(a), (List<?>) method.invoke(b));
                if (diff != null)
                    return diff;
            } else {
                if (!equals(method.invoke(a), method.invoke(b))) {
                    return method.getName() + "[" + method.invoke(a) + "] [" + method.invoke(b) + "]";
                }/*from   ww  w .  ja va 2 s.c o m*/
            }
        }
    }
    return null;
}

From source file:com.xhsoft.framework.common.utils.ReflectUtil.java

/**
 * <p>Description:ReflectionMap?</p>
 * @param target//from  w  w w. j  a  v  a 2  s . c  om
 * @return Map<String,Object>
 * @author wanggq
 * @since  2009-9-9
 */
@SuppressWarnings("unchecked")
public static Map<String, Object> getMapFieldData(Object target) {
    Map<String, Object> map = new HashMap<String, Object>();
    Class clazz = target.getClass();
    Field[] fields = clazz.getDeclaredFields();
    Method[] methods = clazz.getDeclaredMethods();
    for (Field field : fields) {
        String fieldName = field.getName();

        if ("messageTypeId".equals(fieldName)) {
            continue;
        }

        String getMethod = "get" + StringUtils.capitalize(fieldName);
        for (Method method : methods) {
            if (method.getName().equals(getMethod)) {

                try {
                    Object ret = method.invoke(target, null);
                    map.put(fieldName, ret);
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                }

            }

        }

    }

    return map;
}

From source file:Main.java

private static Method findGetter(Method[] methods, String name, Class<?> paramType) {
    String getterName = "get" + name;
    String isGetterName = "is" + name;
    for (Method method : methods) {
        if (Modifier.isStatic(method.getModifiers())) {
            continue;
        }/*from  w  w  w. jav  a 2s. co m*/
        String methodName = method.getName();
        if (!methodName.equals(getterName) && !methodName.equals(isGetterName)) {
            continue;
        }
        if (!method.getReturnType().equals(paramType)) {
            continue;
        }
        if (method.getParameterTypes().length == 0) {
            return method;
        }
    }
    return null;
}

From source file:com.adaptris.util.SimpleBeanUtil.java

private static Method getSetterMethod(Class c, String methodName) {
    Method result = null;/*from   w w  w  .  j a  v  a 2s  . c om*/
    Method[] methods = c.getMethods();
    for (Method m : methods) {
        String name = m.getName();
        if (name.equalsIgnoreCase(methodName)) {
            Class[] params = m.getParameterTypes();
            if (params.length == 1 && PRIMITIVES.contains(params[0])) {
                result = m;
                break;
            }
        }
    }
    return result;
}