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

private static Set<Method> findMethodsCompatibleWith(boolean staticMethod, Set<Method> methods,
        String methodName, Class<?>[] argTypes) {
    final Set<Method> list = new HashSet<Method>(methods);
    for (final Iterator<Method> it = list.iterator(); it.hasNext();) {
        final Method method = it.next();
        if (!methodName.equals(method.getName())) {
            it.remove();//from  w  w w . j  a v  a 2 s. co m
            continue;
        }
        if (argTypes.length != method.getParameterTypes().length) {
            it.remove();
            continue;
        }
        if (Modifier.isAbstract(method.getModifiers())
                || Modifier.isStatic(method.getModifiers()) != staticMethod) {
            it.remove();
            continue;
        }
        if (!isMethodArgCompatible(method, argTypes)) {
            it.remove();
            continue;
        }

    }
    return list;
}

From source file:jp.go.nict.langrid.testresource.loader.NodeLoader_1_2.java

protected static void addProperties(Class<?> clazz, Set<String> properties, Set<String> tupleProperties) {
    for (Method m : clazz.getDeclaredMethods()) {
        if (m.getParameterTypes().length != 1)
            continue;
        String name = m.getName();
        if (!name.startsWith("set"))
            continue;
        if (!Modifier.isPublic(m.getModifiers()))
            continue;
        String propName = name.substring(3, 4).toLowerCase() + name.substring(4);
        if (m.getParameterTypes()[0].isArray()) {
            tupleProperties.add(propName);
        } else {/*from  ww  w .j  av  a2  s  .  c  o m*/
            properties.add(propName);
        }
    }
}

From source file:autocorrelator.apps.SDFGroovy.java

private static void exitWithHelp(String msg, Options options) {
    System.err.println(msg);//from  w  w w. j a va  2s  .  c o  m
    HelpFormatter formatter = new HelpFormatter();
    formatter.setWidth(120);
    formatter.printHelp(INTROText, options);

    StringBuilder sb = new StringBuilder();
    Class<SDFGroovyHelper> helper = SDFGroovyHelper.class;
    for (Method m : helper.getMethods()) {
        if ((m.getModifiers() & Modifier.STATIC) == 0 || (m.getModifiers() & Modifier.PUBLIC) == 0)
            continue;

        String meth = m.toString();
        meth = meth.replaceAll("public static final ", "");
        meth = meth.replaceAll("java\\.lang\\.", "");
        meth = meth.replaceAll("java\\.math\\.", "");
        meth = meth.replaceAll("autocorrelator\\.apps\\.SDFGroovyHelper.", "");
        sb.append('\t').append(meth).append('\n');
    }
    System.out.println("Imported internal functions:");
    System.out.println(sb);
    System.exit(1);

}

From source file:cn.webwheel.ActionSetter.java

public static String isSetter(Method method) {
    if (Modifier.isStatic(method.getModifiers()))
        return null;
    String name = method.getName();
    if (!name.startsWith("set"))
        return null;
    if (name.length() < 4)
        return null;
    if (method.getParameterTypes().length != 1)
        return null;
    name = name.substring(3);//w ww  . j  a v  a2  s  . c o  m
    if (name.length() > 1 && name.equals(name.toUpperCase()))
        return name;
    return name.substring(0, 1).toLowerCase() + name.substring(1);
}

From source file:net.mindengine.blogix.BlogixMain.java

private static Method findCommandMethod(String name) {
    Method[] methods = BlogixMain.class.getDeclaredMethods();
    for (Method method : methods) {
        if (Modifier.isStatic(method.getModifiers()) && method.getName().equals("cmd_" + name)) {
            return method;
        }/*  w  w w.  j ava 2  s .c  o m*/
    }
    return null;
}

From source file:net.servicefixture.util.ReflectionUtils.java

/**
 * Returns the first public method that matches method name.
 *///  w  w  w.  j  a va  2 s  .  c  o m
public static Method findMethodByName(Class type, String methodName) {
    Method[] methods = type.getMethods();
    for (int i = 0; i < methods.length; i++) {
        Method method = methods[i];
        if (method.getName().equals(methodName) && Modifier.isPublic(method.getModifiers())) {
            return method;
        }
    }
    return null;
}

From source file:edu.umich.flowfence.common.QMDescriptor.java

public static QMDescriptor forMethod(Context context, Method method) {
    Class<?> definingClass = method.getDeclaringClass();
    String methodName = method.getName();
    Class<?>[] paramTypes = method.getParameterTypes();
    if ((method.getModifiers() & Modifier.STATIC) != 0) {
        return forStatic(context, definingClass, methodName, paramTypes);
    } else {/*from   w w  w . j a  v  a2s  .  co  m*/
        return forInstance(context, definingClass, methodName, paramTypes);
    }
}

From source file:edu.umich.oasis.common.SodaDescriptor.java

public static SodaDescriptor forMethod(Context context, Method method) {
    Class<?> definingClass = method.getDeclaringClass();
    String methodName = method.getName();
    Class<?>[] paramTypes = method.getParameterTypes();
    if ((method.getModifiers() & Modifier.STATIC) != 0) {
        return forStatic(context, definingClass, methodName, paramTypes);
    } else {/*from  w  w  w.  jav a2s .c o  m*/
        return forInstance(context, definingClass, methodName, paramTypes);
    }
}

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;
        }/*from   ww  w  .jav  a 2  s  . c o m*/

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

From source file:org.alfresco.module.org_alfresco_module_rm.api.PublicAPITestUtil.java

/**
 * Get all the classes referenced by the given class, which might be used by an extension. We consider visible
 * methods, constructors, fields and inner classes, as well as superclasses and interfaces extended by the class.
 *
 * @param initialClass The class to analyse.
 * @param consideredClasses Classes that have already been considered, and which should not be considered again. If
 *            the given class has already been considered then an empty set will be returned. This set will be
 *            updated with the given class.
 * @return The set of classes that might be accessible by an extension of this class.
 *///w  w  w  .jav a 2  s  . co m
private static Set<Class<?>> getReferencedClassesFromClass(Class<?> initialClass,
        Set<Class<?>> consideredClasses) {
    Set<Class<?>> referencedClasses = new HashSet<>();

    if (consideredClasses.add(initialClass)) {
        for (Method method : initialClass.getDeclaredMethods()) {
            if (isVisibleToExtender(method.getModifiers())) {
                referencedClasses.addAll(getClassesFromMethod(method));
            }
        }
        for (Constructor<?> constructor : initialClass.getDeclaredConstructors()) {
            if (isVisibleToExtender(constructor.getModifiers())) {
                referencedClasses.addAll(getClassesFromConstructor(constructor));
            }
        }
        for (Field field : initialClass.getDeclaredFields()) {
            if (isVisibleToExtender(field.getModifiers())) {
                referencedClasses.addAll(getClassesFromField(field));
            }
        }
        for (Class<?> clazz : initialClass.getDeclaredClasses()) {
            if (isVisibleToExtender(clazz.getModifiers())) {
                referencedClasses.addAll(getReferencedClassesFromClass(clazz, consideredClasses));
            }
        }
        if (initialClass.getSuperclass() != null) {
            referencedClasses
                    .addAll(getReferencedClassesFromClass(initialClass.getSuperclass(), consideredClasses));
        }
        for (Class<?> clazz : initialClass.getInterfaces()) {
            referencedClasses.addAll(getReferencedClassesFromClass(clazz, consideredClasses));
        }
    }
    return referencedClasses;
}