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:cz.muni.fi.editor.database.test.helpers.AbstractDAOTest.java

protected static void checkMethods(Class testClass, Class testingInterface) {
    Set<String> testMethods = new HashSet<>();
    for (Method m : testClass.getDeclaredMethods()) {
        if (m.isAnnotationPresent(Test.class)) {
            testMethods.add(m.getName());
        }//from w  ww  .  j a va2s .c om
    }

    List<String> targetMethods = new ArrayList<>(
            Arrays.asList("create", "update", "getById", "delete", "getAll", "getClassType"));
    targetMethods.addAll(new ArrayList<>(Arrays.asList(testingInterface.getDeclaredMethods())).stream()
            .map(m -> m.getName()).collect(Collectors.toList()));
    testMethods.forEach(targetMethods::remove);

    Assert.assertEquals("Following method(s) are missing in DAO test :" + targetMethods.toString(), 0,
            targetMethods.size());
}

From source file:com.arpnetworking.jackson.BuilderDeserializer.java

static boolean isSetterMethod(final Class<?> builderClass, final Method method) {
    return method.getName().startsWith(SETTER_PREFIX) && builderClass.equals(method.getReturnType())
            && !method.isVarArgs() && method.getParameterTypes().length == 1;
}

From source file:mangotiger.poker.channel.EventChannelImpl.java

static boolean methodMatchesEvent(final Method method, final Class<?> event) {
    return METHOD_NAME.equals(method.getName()) && Modifier.isPublic(method.getModifiers())
            && Void.TYPE.equals(method.getReturnType()) && method.getParameterTypes().length == 1
            && method.getParameterTypes()[0].isAssignableFrom(event);
}

From source file:com.outcastgeek.traversal.TraverseUtils.java

/**
 * @param pojo is the POJO to be traversed
 * @param pathSteps is traversal path/*ww  w  .  j  av a2 s  . co m*/
 * @return the object a the end of the path
 * @throws TraverseException
 */
public static Object getPath(Object pojo, String... pathSteps) throws TraverseException {

    Object value = null;

    try {
        Class pojoClass = pojo.getClass();
        Method[] declaredMethods = pojoClass.getDeclaredMethods();
        int pathStepLength = pathSteps.length;
        logger.debug("Traversing {}...", pojo);
        for (int i = 0; i < pathStepLength; i++) {
            String step = pathSteps[i];
            logger.debug("Step: {}", step);
            for (Method method : declaredMethods) {
                String methodName = method.getName();
                if (StringUtils.containsIgnoreCase(methodName, step)) {
                    value = pojoClass.getDeclaredMethod(methodName).invoke(pojo);
                    break;
                }
            }
            if (i == pathStepLength - 1) {
                break;
            } else {
                String[] followingSteps = ArrayUtils.removeElement(pathSteps, step);
                return getPath(value, followingSteps);
            }
        }
    } catch (Exception e) {
        throw new TraverseException(e);
    }

    return value;
}

From source file:Main.java

/**
 * Wraps an {@link ExecutorService} in such a way as to &quot;protect&quot;
 * it for calls to the {@link ExecutorService#shutdown()} or
 * {@link ExecutorService#shutdownNow()}. All other calls are delegated as-is
 * to the original service. <B>Note:</B> the exposed wrapped proxy will
 * answer correctly the {@link ExecutorService#isShutdown()} query if indeed
 * one of the {@code shutdown} methods was invoked.
 *
 * @param executorService The original service - ignored if {@code null}
 * @param shutdownOnExit  If {@code true} then it is OK to shutdown the executor
 *                        so no wrapping takes place.
 * @return Either the original service or a wrapped one - depending on the
 * value of the <tt>shutdownOnExit</tt> parameter
 *///w  ww  .  jav  a  2 s .com
public static ExecutorService protectExecutorServiceShutdown(final ExecutorService executorService,
        boolean shutdownOnExit) {
    if (executorService == null || shutdownOnExit) {
        return executorService;
    } else {
        return (ExecutorService) Proxy.newProxyInstance(resolveDefaultClassLoader(executorService),
                new Class<?>[] { ExecutorService.class }, new InvocationHandler() {
                    private final AtomicBoolean stopped = new AtomicBoolean(false);

                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        String name = method.getName();
                        if ("isShutdown".equals(name)) {
                            return stopped.get();
                        } else if ("shutdown".equals(name)) {
                            stopped.set(true);
                            return null; // void...
                        } else if ("shutdownNow".equals(name)) {
                            stopped.set(true);
                            return Collections.emptyList();
                        } else {
                            return method.invoke(executorService, args);
                        }
                    }
                });
    }
}

From source file:io.openmessaging.rocketmq.utils.BeanUtils.java

public static Class<?> getMethodClass(Class<?> clazz, String methodName) {
    Method[] methods = clazz.getMethods();
    for (Method method : methods) {
        if (method.getName().equalsIgnoreCase(methodName)) {
            return method.getParameterTypes()[0];
        }/*from  w  ww .j  ava 2  s.  c  o  m*/
    }
    return null;
}

From source file:com.galenframework.reports.GalenTestInfo.java

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

From source file:cz.jirutka.validator.collection.internal.AnnotationUtils.java

/**
 * Whether the annotation type contains attribute of the specified name.
 *///from  w w w  .  j  a v  a  2s  . c  o  m
public static boolean hasAttribute(Class<? extends Annotation> annotationType, String attributeName) {

    for (Method m : annotationType.getDeclaredMethods()) {
        if (m.getName().equals(attributeName)) {
            return true;
        }
    }
    return false;
}

From source file:com.outcastgeek.traversal.TraverseUtils.java

/**
 * @param pojo is the POJO to be traversed
 * @param pathSteps is traversal path//  www  . j  a v a  2  s  .c o  m
 * @return true or false
 * @throws TraverseException
 */
public static boolean isNullPath(Object pojo, String... pathSteps) throws TraverseException {

    boolean isNullPath = false;

    try {
        Class pojoClass = pojo.getClass();
        Method[] declaredMethods = pojoClass.getDeclaredMethods();
        int pathStepLength = pathSteps.length;
        logger.debug("Traversing {}...", pojo);
        for (int i = 0; i < pathStepLength; i++) {
            String step = pathSteps[i];
            logger.debug("Step: {}", step);
            Object value = null;
            for (Method method : declaredMethods) {
                String methodName = method.getName();
                if (StringUtils.containsIgnoreCase(methodName, step)) {
                    value = pojoClass.getDeclaredMethod(methodName).invoke(pojo);
                    break;
                }
            }
            if (value != null) {
                if (i == pathStepLength - 1) {
                    break;
                } else {
                    String[] followingSteps = ArrayUtils.removeElement(pathSteps, step);
                    return isNullPath(value, followingSteps);
                }
            } else {
                isNullPath = true;
                break;
            }
        }
    } catch (Exception e) {
        throw new TraverseException(e);
    }

    return isNullPath;
}

From source file:de.unisb.cs.st.javalanche.mutation.runtime.testDriver.junit.Junit4Util.java

public static Method getSuiteMethod(Class<?> forName) {
    Method[] methods = forName.getMethods();
    for (Method method : methods) {
        if (method.getName().equals("suite") && method.getParameterTypes().length == 0) {
            return method;
        }//from w ww .  ja v a  2s. c o  m
    }
    return null;
}