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:com.googlecode.memcachefy.hashkey.HashKeyGenerator.java

/**
 * Generates a hashkey using the object's own hashCode function
 *
 * @param method/*ww w.  j av a  2s.  c  o  m*/
 * @param parameters
 * @return
 */
public static Integer defaultHashKey(Method method, Object[] parameters) {

    int hashCode = method.getName().hashCode();

    if (parameters == null || parameters.length == 0) {
        return hashCode;
    }

    if (parameters.length == 1) {
        return 17 * hashCode + (parameters[0] == null ? method.getName().hashCode() : parameters[0].hashCode());
    }

    for (Object object : parameters) {
        hashCode = 31 * hashCode + (object == null ? NULL_PARAM_KEY : object.hashCode());
    }

    return hashCode;
}

From source file:gov.nih.nci.cabig.caaers.utils.JSONUtils.java

public static Map<String, Object> describe(Object o) {
    Map<String, Object> m = new LinkedHashMap<String, Object>();
    Method[] methods = o.getClass().getMethods();
    for (Method method : methods) {
        String name = method.getName();
        if (!name.startsWith("get"))
            continue;
        name = name.substring(3);/*from  w w  w  . j a  v a2  s.com*/
        String firstChar = "" + name.charAt(0);
        name = firstChar.toLowerCase() + name.substring(1);
        Object value = null;
        try {
            value = method.invoke(o);
        } catch (Exception ignore) {

        }
        if (name.equals("class"))
            value = String.valueOf(value);
        m.put(name, value);

    }
    return m;
}

From source file:com.googlecode.memcachefy.hashkey.HashKeyGenerator.java

/**
 *  Generates a hashkey using reflection
 *
 * @param method//from w ww  . ja v  a2 s. c o m
 * @param parameters
 * @return
 */
public static Integer reflectionHashKey(Method method, Object[] parameters) {

    int hashCode = method.getName().hashCode();

    if (parameters == null || parameters.length == 0) {
        return hashCode;
    }

    if (parameters.length == 1) {
        return 17 * hashCode + (parameters[0] == null ? method.getName().hashCode()
                : HashCodeBuilder.reflectionHashCode(parameters[0]));
    }

    for (Object object : parameters) {
        hashCode = 31 * hashCode
                + (object == null ? NULL_PARAM_KEY : HashCodeBuilder.reflectionHashCode(object));
    }

    return hashCode;
}

From source file:com.mirth.connect.client.core.api.util.OperationUtil.java

public static Operation getOperation(Class<?> servletInterface, Method method) {
    return getOperation(servletInterface, method.getName(), method.getParameterTypes());
}

From source file:ReflectUtils.java

/**
 * Convert the Method to a Java Code String
 * (arguments are replaced by the simple types)
 * @param method Method// w  ww . ja v  a 2 s  . c o  m
 * @return
 */
public static String getJavaCallString(Method method) {
    StringBuilder call = new StringBuilder();
    call.append(method.getName());
    addParamsString(call, method.getParameterTypes());
    return call.toString();
}

From source file:Main.java

/**
 * <p>//from w w  w .  j a  va  2  s.  co m
 * Unregister a VTI.
 * </p>
 */
public static void unregisterVTI(Method method) throws SQLException {
    String methodName = method.getName();
    String sqlName = doubleQuote(methodName);

    dropObject("function", sqlName, false);
}

From source file:net.kaczmarzyk.spring.data.jpa.web.EnhancerUtil.java

@SuppressWarnings("unchecked")
static <T> T wrapWithIfaceImplementation(final Class<T> iface, final Specification<Object> targetSpec) {
    Enhancer enhancer = new Enhancer();
    enhancer.setInterfaces(new Class[] { iface });
    enhancer.setCallback(new MethodInterceptor() {
        @Override/*from   w w w . ja v  a2s .com*/
        public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
            if ("toString".equals(method.getName())) {
                return iface.getSimpleName() + "[" + proxy.invoke(targetSpec, args) + "]";
            }
            return proxy.invoke(targetSpec, args);
        }
    });

    return (T) enhancer.create();
}

From source file:Main.java

public static Method findMethodByNameAndReturnType(Class<?> targetObject, String methodName, String returnType,
        Class<?>... params) {
    for (Method method : targetObject.getDeclaredMethods()) {
        if (method.getReturnType().getName().equals(returnType) && method.getName().equals(methodName)) {
            Class[] parameterTypes = method.getParameterTypes();
            if (params.length != parameterTypes.length) {
                continue;
            }/*from  w  w w .  ja  v  a  2  s. com*/
            for (int i = 0; i < params.length; i++) {
                if (params[i] != parameterTypes[i]) {
                    break;
                }
            }
            method.setAccessible(true);
            return method;
        }
    }
    throw new NoSuchMethodError();
}

From source file:org.flywaydb.test.ExecutionListenerHelper.java

/**
 * Helper method to build test execution information with test class and
 * method/*from  w ww .  j a  v  a 2s.  c om*/
 * 
 * @param testContext of spring test environment
 * 
 * @return String like &lt;Class Name&gt;[.&lt;Method Name&gt;]
 */
public static String getExecutionInformation(TestContext testContext) {
    String result = "";
    Class<?> testClass = testContext.getTestClass();

    result = testClass.getName();

    // now check for method
    Method m = testContext.getTestMethod();
    if (m != null) {
        result = result + "." + m.getName();
    }

    return result;
}

From source file:Main.java

public static <T extends Object, Result> Result callMethodCast(T receiver, Class<Result> resultClass,
        String methodName, Object... args) throws NoSuchMethodException, IllegalAccessException,
        InvocationTargetException, InstantiationException {
    if (receiver == null || methodName == null) {
        return null;
    }/*  w ww. jav  a2s .  c  o  m*/
    Class<?> cls = receiver.getClass();
    Method toInvoke = null;
    do {
        Method[] methods = cls.getDeclaredMethods();
        methodLoop: for (Method method : methods) {
            if (!methodName.equals(method.getName())) {
                continue;
            }
            Class<?>[] paramTypes = method.getParameterTypes();
            if (args == null && paramTypes == null) {
                toInvoke = method;
                break;
            } else if (args == null || paramTypes == null || paramTypes.length != args.length) {
                continue;
            }

            for (int i = 0; i < args.length; ++i) {
                if (!paramTypes[i].isAssignableFrom(args[i].getClass())) {
                    continue methodLoop;
                }
            }
            toInvoke = method;
        }
    } while (toInvoke == null && (cls = cls.getSuperclass()) != null);
    Result t;
    if (toInvoke != null) {
        boolean accessible = toInvoke.isAccessible();
        toInvoke.setAccessible(true);
        if (resultClass != null) {
            t = resultClass.cast(toInvoke.invoke(receiver, args));
        } else {
            toInvoke.invoke(receiver, args);
            t = null;
        }
        toInvoke.setAccessible(accessible);
        return t;
    } else {
        throw new NoSuchMethodException("Method " + methodName + " not found");
    }
}