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:org.callimachusproject.webdriver.helpers.BrowserFunctionalTestCase.java

public static TestSuite suite(Class<? extends BrowserFunctionalTestCase> testcase) throws Exception {
    TestSuite suite = new TestSuite(testcase.getName());
    for (Method method : testcase.getMethods()) {
        if (method.getName().startsWith("test") && method.getParameterTypes().length == 0
                && method.getReturnType().equals(Void.TYPE)) {
            addTests(testcase, suite, method);
        }//from   www  . j  ava2s. c o  m
    }
    if (suite.countTestCases() == 0) {
        suite.addTest(TestSuite.warning(testcase.getName() + " has no public test methods"));
    }
    return suite;
}

From source file:com.qingstor.sdk.utils.QSJSONUtil.java

private static boolean initParameter(JSONObject o, Field[] declaredField, Class objClass, Object targetObj)
        throws NoSuchMethodException {
    boolean hasParam = false;
    for (Field field : declaredField) {
        String methodField = QSParamInvokeUtil.capitalize(field.getName());
        String getMethodName = field.getType() == Boolean.class ? "is" + methodField : "get" + methodField;
        String setMethodName = "set" + methodField;
        Method[] methods = objClass.getDeclaredMethods();
        for (Method m : methods) {
            if (m.getName().equals(getMethodName)) {
                ParamAnnotation annotation = m.getAnnotation(ParamAnnotation.class);
                if (annotation == null) {
                    continue;
                }/* ww w  .  java2  s  . com*/
                String dataKey = annotation.paramName();

                if (o.has(dataKey)) {
                    hasParam = true;
                    Object data = toObject(o, dataKey);
                    Method setM = objClass.getDeclaredMethod(setMethodName, field.getType());
                    setParameterToMap(setM, targetObj, field, data);
                }
            }
        }
    }
    return hasParam;
}

From source file:com.diversityarrays.kdxplore.stats.StatsUtil.java

static public Object getStatNameValue(SimpleStatistics<?> ss, SimpleStatistics.StatName statName) {
    Object result = null;/*from   w  w  w  .  j a v a  2  s  .co m*/
    Method method = METHOD_BY_STATNAME.get(statName);
    try {
        result = method.invoke(ss);
    } catch (IllegalAccessException | InvocationTargetException e) {
        Shared.Log.e("StatsUtil", "SimpleStatistics." + method.getName(), e);
    }
    return result;
}

From source file:de.codesourcery.eve.apiclient.cache.FilesystemResponseCacheTest.java

private static Method findMethod(Class<?> clasz, String name) {
    for (Method m : clasz.getDeclaredMethods()) {
        final int mods = m.getModifiers();

        if (Modifier.isStatic(mods) || Modifier.isFinal(mods)) {
            continue;
        }/* w  w w  . j av a  2 s . c om*/

        if (m.getName().equals(name)) {
            return m;
        }
    }
    return null;
}

From source file:com.almende.eve.agent.AgentProxyFactory.java

/**
 * Gen proxy.//from  w w  w. j  ava  2  s  . c o  m
 * 
 * @param <T>
 *            the generic type
 * @param sender
 *            the sender
 * @param receiverUrl
 *            the receiver url
 * @param proxyInterface
 *            the interface this proxy implements
 * @return the t
 */
@SuppressWarnings("unchecked")
public static <T> T genProxy(final Agent sender, final URI receiverUrl, final Class<T> proxyInterface) {
    // http://docs.oracle.com/javase/1.4.2/docs/guide/reflection/proxy.html
    final T proxy = (T) Proxy.newProxyInstance(proxyInterface.getClassLoader(), new Class[] { proxyInterface },
            new InvocationHandler() {

                private Map<Method, Boolean> cache = new HashMap<Method, Boolean>();

                @Override
                public Object invoke(final Object proxy, final Method method, final Object[] args) {
                    boolean doSync = true;
                    if (cache.containsKey(method)) {
                        doSync = cache.get(method);
                    } else {
                        AnnotatedClass clazz = AnnotationUtil.get(proxyInterface);
                        if (clazz != null) {
                            List<AnnotatedMethod> list = clazz.getMethods(method.getName());
                            for (AnnotatedMethod m : list) {
                                if (m.getAnnotation(NoReply.class) != null) {
                                    doSync = false;
                                }
                            }
                            if (doSync && method.getReturnType().equals(void.class)
                                    && clazz.getAnnotation(NoReply.class) != null) {
                                doSync = false;
                            }
                        }
                        cache.put(method, doSync);
                    }
                    SyncCallback<JsonNode> callback = null;
                    if (doSync) {
                        callback = new SyncCallback<JsonNode>() {
                        };
                    }
                    try {
                        sender.call(receiverUrl, method, args, callback);
                    } catch (final IOException e) {
                        throw new JSONRPCException(CODE.REMOTE_EXCEPTION, e.getLocalizedMessage(), e);
                    }
                    if (callback != null) {
                        try {
                            return TypeUtil.inject(callback.get(), method.getGenericReturnType());
                        } catch (final Exception e) {
                            throw new JSONRPCException(CODE.REMOTE_EXCEPTION, e.getLocalizedMessage(), e);
                        }
                    }
                    return null;
                }
            });
    return proxy;
}

From source file:io.dyn.core.handler.Handlers.java

public static <A extends Annotation> A find(Class<A> anno, Method method) {
    if (null == method) {
        return null;
    }/*from   ww w.  ja v  a 2 s  . co  m*/

    A on = AnnotationUtils.findAnnotation(method, anno);
    if (null != on) {
        return on;
    }

    Class<?>[] implClasses = method.getDeclaringClass().getInterfaces();
    for (Class<?> cl : implClasses) {
        try {
            Method m = cl.getDeclaredMethod(method.getName(), method.getParameterTypes());
            if (null != m) {
                on = find(anno, m);
                if (null != on) {
                    return on;
                }
            }
        } catch (NoSuchMethodException e) {
        }
    }

    return null;
}

From source file:com.cisco.ca.cstg.pdi.utils.Util.java

/**
 * This method validates an object and return the id 
 * @param obj/*from   w w  w. j a  va  2 s .c  om*/
 * @return id, if id not available then <blank> 
 */

public static Object nullValidationAndReturnId(Object obj) {
    if (obj != null) {
        try {
            Class<?> childClass = Class.forName(obj.getClass().getName());
            Method[] childMethod = childClass.getDeclaredMethods();

            for (Method childM : childMethod) {
                if ("getid".equalsIgnoreCase(childM.getName())) {
                    return childM.invoke(obj);
                }
            }
        } catch (Exception e) {
            LOGGER.error("Error caught while fetching the id of object.", e);
        }
    }
    return null;
}

From source file:com.google.code.siren4j.util.ReflectionUtils.java

/**
 * Determine if the method is a getter.//from  w w w  .  j a va2 s  .  com
 *
 * @param method
 * @return
 */
public static boolean isGetter(Method method) {
    String name = method.getName();
    String[] splitname = StringUtils.splitByCharacterTypeCamelCase(name);
    return !method.getReturnType().equals(void.class) && Modifier.isPublic(method.getModifiers())
            && (splitname[0].equals(GETTER_PREFIX_BOOLEAN) || splitname[0].equals(GETTER_PREFIX));
}

From source file:com.google.code.siren4j.util.ReflectionUtils.java

/**
 * Determine if the method is a setter./*from   w  w w .  ja va2 s. c om*/
 *
 * @param method
 * @return
 */
public static boolean isSetter(Method method) {
    String name = method.getName();
    String[] splitname = StringUtils.splitByCharacterTypeCamelCase(name);
    return method.getReturnType().equals(void.class) && Modifier.isPublic(method.getModifiers())
            && splitname[0].equals(SETTER_PREFIX);
}

From source file:pt.webdetails.cpf.SimpleContentGenerator.java

/**
 * Get a map of all public methods with the Exposed annotation.
 * Map is not thread-safe and should be used read-only.
 * @param classe Class where to find methods
 * @param log classe's logger/*from  ww w .ja va2  s.c  o m*/
 * @param lowerCase if keys should be in lower case.
 * @return map of all public methods with the Exposed annotation
 */
protected static Map<String, Method> getExposedMethods(Class<?> classe, boolean lowerCase) {
    HashMap<String, Method> exposedMethods = new HashMap<String, Method>();
    Log log = LogFactory.getLog(classe);
    for (Method method : classe.getMethods()) {
        if (method.getAnnotation(Exposed.class) != null) {
            String methodKey = method.getName().toLowerCase();
            if (exposedMethods.containsKey(methodKey)) {
                log.error("Method " + method + " differs from " + exposedMethods.get(methodKey)
                        + " only in case and will override calls to it!!");
            }
            log.debug("registering " + classe.getSimpleName() + "." + method.getName());
            exposedMethods.put(methodKey, method);
        }
    }
    return exposedMethods;
}