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:Main.java

static Method getMethod(Class clazz, String methodName) {
    final Method[] methods = clazz.getMethods();
    for (Method method : methods) {
        if (method.getName().equals(methodName)) {
            method.setAccessible(true);/*  ww w  .  j  a v  a2  s .  c om*/
            return method;
        }
    }
    return null;
}

From source file:Main.java

public static boolean hasMethod(Object obj, String method) {
    assert method != null;
    Method[] ms = obj.getClass().getMethods();
    for (Method m : ms) {
        if (m.getName().equals(method))
            return true;
    }/*from   ww w  .j  a  v  a  2s  .co  m*/
    return false;
}

From source file:Main.java

public static Method[] getMethodsByName(Class<?> clazz, String name) {
    Method[] methods = clazz.getMethods();
    List<Method> list = new ArrayList<Method>();

    for (Method method : methods) {
        if (method.getName().equals(name))
            list.add(method);// w  w w  .  j a  v  a2 s . com
    }

    return list.toArray(new Method[list.size()]);
}

From source file:Main.java

private static boolean hasMethod(String methodName, Method[] method) {
    for (Method m : method) {
        if (methodName.equals(m.getName())) {
            return true;
        }/*from  w  ww .j av  a2s  . c  om*/
    }
    return false;
}

From source file:Main.java

public static String getPropertyName(Method getter) {
    String getterName = getter.getName();
    assert getterName.startsWith("get"); // todo check for "is"
    return decapitalize(getterName.substring(3));
}

From source file:Main.java

public static boolean checkSetMet(Method[] methods, String fieldSetMet) {
    for (Method met : methods) {
        if (fieldSetMet.equals(met.getName())) {
            return true;
        }/*  w w w . ja  v  a  2s .  c o m*/
    }
    return false;
}

From source file:Main.java

private static Method getBooleanMethod(Class clazz) {
    Method[] methods = clazz.getDeclaredMethods();
    for (Method method : methods) {
        if (TextUtils.equals(method.getName(), "getBoolean")) {
            return method;
        }/* ww w .j av  a  2s.  c o  m*/
    }
    return null;
}

From source file:Main.java

private static Method getHasMethod(Class clazz) {
    Method[] methods = clazz.getDeclaredMethods();
    for (Method method : methods) {
        if (TextUtils.equals(method.getName(), "has")) {
            return method;
        }// w w w . j  ava2s . c o  m
    }
    return null;
}

From source file:Main.java

public static boolean hasAnnotation(Class<? extends Annotation> annotation, Object object, String methodName) {
    try {/*  w  w  w .j a  v a 2  s . c o  m*/
        Class<? extends Object> c = object.getClass();

        for (Method m : c.getMethods()) {
            if (m.getName().equals(methodName)) {
                if (m.isAnnotationPresent(annotation)) {
                    return true;
                }
            }
        }
    } catch (Exception e) {
    }
    return false;
}

From source file:Main.java

public static long generateCodeOfMethod(Class<?> providerClass, Method method) {
    StringBuilder buider = new StringBuilder(method.getName());
    long classCode = providerClass.getName().hashCode();
    Class<?>[] paramTypes = method.getParameterTypes();
    for (Class<?> c : paramTypes) {
        buider.append(c.getName());/*from w  w  w  . j  a  v  a2 s  .  co  m*/
    }
    return classCode << 32 + buider.toString().hashCode();
}