Example usage for java.lang.reflect Method getModifiers

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

Introduction

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

Prototype

@Override
public int getModifiers() 

Source Link

Usage

From source file:org.apache.flink.runtime.fs.hdfs.HadoopRecoverableFsDataOutputStream.java

private static void ensureTruncateInitialized() throws FlinkRuntimeException {
    if (truncateHandle == null) {
        Method truncateMethod;
        try {// ww w  . java2  s  .  c om
            truncateMethod = FileSystem.class.getMethod("truncate", Path.class, long.class);
        } catch (NoSuchMethodException e) {
            throw new FlinkRuntimeException(
                    "Could not find a public truncate method on the Hadoop File System.");
        }

        if (!Modifier.isPublic(truncateMethod.getModifiers())) {
            throw new FlinkRuntimeException(
                    "Could not find a public truncate method on the Hadoop File System.");
        }

        truncateHandle = truncateMethod;
    }
}

From source file:com.lucidtechnics.blackboard.TargetConstructor.java

private final static List findProtectedMethods(Class _class) {
    List methodList = new ArrayList();

    Enhancer.getMethods(_class, null, methodList);

    Predicate mutatorPredicate = new Predicate() {
        public boolean evaluate(Object _object) {
            Method method = (Method) _object;

            boolean isProtected = (Modifier.isProtected(method.getModifiers()) == true);

            return isProtected;
        }/*from ww w.ja  va 2s.c o  m*/
    };

    CollectionUtils.filter(methodList, mutatorPredicate);

    return methodList;
}

From source file:org.jgentleframework.utils.control.Delegator.java

/**
 * utility method to get candidate methods to search.
 * //ww  w  .  j av  a  2  s  .  c  o  m
 * @param targetClass
 *            the target class
 * @param MethodName
 *            the method name
 * @param nargs
 *            the nargs
 * @return the candidate methods
 */
protected static Method[] getCandidateMethods(Class targetClass, String MethodName, int nargs) {

    Method[] possibilities = targetClass.getMethods();
    List holder = new ArrayList();
    for (int i = 0; i < possibilities.length; i++) {
        Method possibility = possibilities[i];
        if (possibility.getName().equals(MethodName) && possibility.getParameterTypes().length == nargs
                && Modifier.isPublic(possibility.getModifiers()))
            holder.add(possibility);
    }
    return ((Method[]) holder.toArray(EMPTY_METHOD_ARRAY));
}

From source file:com.google.gwtjsonrpc.server.JsonServlet.java

private static Map<String, MethodHandle> methods(final RemoteJsonService impl) {
    final Class<? extends RemoteJsonService> d = findInterface(impl.getClass());
    if (d == null) {
        return Collections.<String, MethodHandle>emptyMap();
    }//  ww w. j a  v  a  2s  .c om

    final Map<String, MethodHandle> r = new HashMap<String, MethodHandle>();
    for (final Method m : d.getMethods()) {
        if (!Modifier.isPublic(m.getModifiers())) {
            continue;
        }

        if (m.getReturnType() != Void.TYPE) {
            continue;
        }

        final Class<?>[] params = m.getParameterTypes();
        if (params.length < 1) {
            continue;
        }

        if (!params[params.length - 1].isAssignableFrom(AsyncCallback.class)) {
            continue;
        }

        final MethodHandle h = new MethodHandle(impl, m);
        r.put(h.getName(), h);
    }
    return Collections.unmodifiableMap(r);
}

From source file:org.batoo.common.reflect.ReflectHelper.java

/**
 * Returns the property descriptors for the class.
 * /*from  www.  jav  a 2s  .c  o  m*/
 * @param clazz
 *            the class
 * @return the property descriptors
 * 
 * @since 2.0.1
 */
public static PropertyDescriptor[] getProperties(Class<?> clazz) {
    final List<PropertyDescriptor> properties = Lists.newArrayList();

    final Method[] methodList = clazz.getDeclaredMethods();

    // check each method.
    for (final Method method : methodList) {
        if (method == null) {
            continue;
        }

        // skip static and private methods.
        final int mods = method.getModifiers();
        if (Modifier.isStatic(mods) || !Modifier.isPublic(mods) || method.isBridge() || method.isSynthetic()) {
            continue;
        }

        final String name = method.getName();

        if (method.getParameterTypes().length == 0) {
            if (name.startsWith(ReflectHelper.GET_PREFIX)) {
                properties.add(new PropertyDescriptor(clazz, name.substring(3), method));
            } else if ((method.getReturnType() == boolean.class) && name.startsWith(ReflectHelper.IS_PREFIX)) {
                properties.add(new PropertyDescriptor(clazz, name.substring(2), method));
            }
        }
    }

    return properties.toArray(new PropertyDescriptor[properties.size()]);
}

From source file:com.snaplogic.snaps.firstdata.Create.java

static boolean isSetter(Method method) {
    return Modifier.isPublic(method.getModifiers()) && method.getReturnType().equals(void.class)
            && method.getParameterTypes().length == 1 && method.getName().matches(REGEX_SET);
}

From source file:com.snaplogic.snaps.firstdata.Create.java

static boolean isGetter(Method method) {
    if (Modifier.isPublic(method.getModifiers()) && method.getParameterTypes().length == 0) {
        String methodName = method.getName();
        if (methodName.matches(GET_REGEX) && !method.getReturnType().equals(void.class))
            return true;
        if (methodName.matches(IS_REGEX) && method.getReturnType().equals(boolean.class))
            return true;
    }//w  ww .  j a v a 2s.com
    return false;
}

From source file:io.stallion.reflection.PropertyUtils.java

public static List<String> getPropertyNames(Class clazz) throws PropertyException {
    Method[] methods = clazz.getMethods();
    List<String> names = list();
    for (int i = 0; i < methods.length; i++) {
        Method method = methods[i];
        String name = method.getName();
        if (method.getModifiers() == Modifier.PUBLIC && method.getParameterTypes().length == 0
                && (name.startsWith("get") || name.startsWith("is"))
                && containsSetterForGetter(clazz, method)) {
            String propertyName;//ww  w  . j  av a2  s .co  m
            if (name.startsWith("get"))
                propertyName = Character.toLowerCase(name.charAt(3)) + name.substring(4);
            else
                propertyName = Character.toLowerCase(name.charAt(2)) + name.substring(3);
            names.add(propertyName);
        }
    }
    return names;
}

From source file:net.pms.external.ExternalFactory.java

private static void postInstall(Class<?> clazz) {
    Method postInstall;
    try {/*from ww w  .j a v a  2 s .  c o  m*/
        postInstall = clazz.getDeclaredMethod("postInstall", (Class<?>[]) null);

        if (Modifier.isStatic(postInstall.getModifiers())) {
            postInstall.invoke((Object[]) null, (Object[]) null);
        }
    }

    // Ignore all errors
    catch (SecurityException | NoSuchMethodException | IllegalArgumentException | IllegalAccessException
            | InvocationTargetException e) {
    }
}

From source file:org.exem.flamingo.shared.util.el.ELServiceImpl.java

public static Method findMethod(String className, String methodName) throws ServiceException {
    Method method = null;
    try {/*from   w w  w .  java2s  . c  om*/
        Class clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
        for (Method m : clazz.getMethods()) {
            if (m.getName().equals(methodName)) {
                method = m;
                break;
            }
        }
        if (method == null) {
            // throw new ServiceException(ErrorCode.E0111, className, methodName);
        }
        if ((method.getModifiers() & (Modifier.PUBLIC | Modifier.STATIC)) != (Modifier.PUBLIC
                | Modifier.STATIC)) {
            // throw new ServiceException(ErrorCode.E0112, className, methodName);
        }
    } catch (ClassNotFoundException ex) {
        // throw new ServiceException(ErrorCode.E0113, className);
    }
    return method;
}