Example usage for java.lang.reflect Modifier isStatic

List of usage examples for java.lang.reflect Modifier isStatic

Introduction

In this page you can find the example usage for java.lang.reflect Modifier isStatic.

Prototype

public static boolean isStatic(int mod) 

Source Link

Document

Return true if the integer argument includes the static modifier, false otherwise.

Usage

From source file:org.apache.tapestry.listener.ListenerMap.java

private static Map buildMethodMap(Class beanClass) {
    if (LOG.isDebugEnabled())
        LOG.debug("Building method map for class " + beanClass.getName());

    Map result = new HashMap();
    Method[] methods = beanClass.getMethods();

    for (int i = 0; i < methods.length; i++) {
        Method m = methods[i];//w w  w. j  av  a 2s.co m
        int mods = m.getModifiers();

        if (Modifier.isStatic(mods))
            continue;

        // Probably not necessary, getMethods() returns only public
        // methods.

        if (!Modifier.isPublic(mods))
            continue;

        // Must return void

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

        Class[] parmTypes = m.getParameterTypes();

        if (parmTypes.length != 1)
            continue;

        // parm must be IRequestCycle

        if (!parmTypes[0].equals(IRequestCycle.class))
            continue;

        // Ha!  Passed all tests.

        result.put(m.getName(), m);
    }

    return result;

}

From source file:net.sf.ehcache.config.BeanHandler.java

/**
 * Finds a creator method./*ww w.  j  a  va  2  s . c  om*/
 */
private static Method findCreateMethod(Class objClass, String name) {
    final String methodName = makeMethodName("create", name);
    final Method[] methods = objClass.getMethods();
    for (int i = 0; i < methods.length; i++) {
        final Method method = methods[i];
        if (!method.getName().equals(methodName)) {
            continue;
        }
        if (Modifier.isStatic(method.getModifiers())) {
            continue;
        }
        if (method.getParameterTypes().length != 0) {
            continue;
        }
        if (method.getReturnType().isPrimitive() || method.getReturnType().isArray()) {
            continue;
        }
        return method;
    }

    return null;
}

From source file:Main.java

public static Collection<Field> getDeepDeclaredFields(Class<?> c) {
    if (_reflectedFields.containsKey(c)) {
        return _reflectedFields.get(c);
    }//from w  w w.j av  a  2  s .  c  o  m
    Collection<Field> fields = new ArrayList<Field>();
    Class<?> curr = c;

    while (curr != null) {
        try {
            Field[] local = curr.getDeclaredFields();

            for (Field field : local) {
                if (!field.isAccessible()) {
                    try {
                        field.setAccessible(true);
                    } catch (Exception ignored) {
                    }
                }

                int modifiers = field.getModifiers();
                if (!Modifier.isStatic(modifiers) && !field.getName().startsWith("this$")
                        && !Modifier.isTransient(modifiers)) {
                    fields.add(field);
                }
            }
        } catch (ThreadDeath t) {
            throw t;
        } catch (Throwable ignored) {
        }

        curr = curr.getSuperclass();
    }
    _reflectedFields.put(c, fields);
    return fields;
}

From source file:io.s4.comm.util.JSONUtil.java

public static Map<String, Object> getMap(Object obj) {
    Map<String, Object> map = new HashMap<String, Object>();
    if (obj != null) {
        if (Map.class.isAssignableFrom(obj.getClass())) {
            return (Map) obj;
        } else {//from   www.j a va  2  s.c o m

            Field[] fields = obj.getClass().getDeclaredFields();
            for (int i = 0; i < fields.length; i++) {
                if (!fields[i].isAccessible()) {
                    fields[i].setAccessible(true);
                }
                try {
                    String name = fields[i].getName();
                    Object val = fields[i].get(obj);
                    if (!Modifier.isStatic(fields[i].getModifiers())
                            && !Modifier.isTransient(fields[i].getModifiers())) {
                        if (fields[i].getType().isPrimitive() || knownTypes.contains(fields[i].getType())) {
                            map.put(name, val);
                        } else if (fields[i].getType().isArray()) {
                            int length = Array.getLength(val);
                            Object vals[] = new Object[length];
                            for (int j = 0; j < length; j++) {
                                Object arrVal = Array.get(val, j);
                                if (arrVal.getClass().isPrimitive() || knownTypes.contains(arrVal.getClass())) {
                                    vals[j] = arrVal;
                                } else {
                                    vals[j] = getMap(arrVal);
                                }
                            }
                            map.put(name, vals);
                        } else {
                            map.put(name, getMap(val));
                        }
                    }
                } catch (Exception e) {
                    throw new RuntimeException("Exception while getting value of " + fields[i], e);
                }
            }
        }
    }
    return map;
}

From source file:com.tmind.framework.pub.utils.MethodUtils.java

public static Method findMethod(Class start, String methodName, int argCount, Class args[]) {
    // For overriden methods we need to find the most derived version.
    // So we start with the given class and walk up the superclass chain.
    for (Class cl = start; cl != null; cl = cl.getSuperclass()) {
        Method methods[] = getPublicDeclaredMethods(cl);
        for (int i = 0; i < methods.length; i++) {
            Method method = methods[i];
            if (method == null) {
                continue;
            }/*from   ww  w  .j  a  v  a 2 s. c  om*/
            // skip static methods.
            int mods = method.getModifiers();
            if (Modifier.isStatic(mods)) {
                continue;
            }
            // make sure method signature matches.
            Class params[] = method.getParameterTypes();
            if (method.getName().equals(methodName) && params.length == argCount) {
                boolean different = false;
                if (argCount > 0) {
                    for (int j = 0; j < argCount; j++) {
                        if (params[j] != args[j]) {
                            different = true;
                            continue;
                        }
                    }
                    if (different) {
                        continue;
                    }
                }
                return method;
            }
        }
    }

    // Now check any inherited interfaces.  This is necessary both when
    // the argument class is itself an interface, and when the argument
    // class is an abstract class.
    Class ifcs[] = start.getInterfaces();
    for (int i = 0; i < ifcs.length; i++) {
        Method m = findMethod(ifcs[i], methodName, argCount);
        if (m != null) {
            return m;
        }
    }

    return null;
}

From source file:io.ingenieux.lambada.maven.ServeMojo.java

public void loadPathHandlers() throws Exception {
    final Set<Method> methodsAnnotatedWith = extractRuntimeAnnotations(ApiGateway.class);

    getLog().info("There are " + methodsAnnotatedWith.size() + " found methods.");

    for (Method m : methodsAnnotatedWith) {
        ApiGateway a = m.getAnnotation(ApiGateway.class);
        PathHandler pathHandler = new PathHandler();

        pathHandler.setPath(a.path());//from   w w w  . j a  v a  2  s.co m
        pathHandler.setMethod(m);

        boolean bStatic = Modifier.isStatic(m.getModifiers());

        // TODO: ApiGateway
        getLog().info("Class: " + m.getDeclaringClass().getName());

        if (!bStatic) {
            try {
                pathHandler.setInstance(m.getDeclaringClass().newInstance());
            } catch (Exception exc) {
                throw new RuntimeException("Unable to create class " + m.getDeclaringClass(), exc);
            }
        }

        pathHandler.setMethodType(a.method());

        getLog().info("Added path handler: " + pathHandler);

        pathHandlers.add(pathHandler.build());
    }

}

From source file:com.lexicalscope.fluentreflection.FluentMethodImpl.java

@Override
public boolean isStatic() {
    return Modifier.isStatic(method.getModifiers());
}

From source file:de.taimos.dvalin.interconnect.core.spring.InterconnectBeanPostProcessor.java

private InjectionMetadata buildResourceMetadata(Class<?> clazz) {
    LinkedList<InjectionMetadata.InjectedElement> elements = new LinkedList<InjectionMetadata.InjectedElement>();
    Class<?> targetClass = clazz;

    do {/*from w  w w.ja v  a 2  s.c o  m*/
        LinkedList<InjectionMetadata.InjectedElement> currElements = new LinkedList<InjectionMetadata.InjectedElement>();
        for (Field field : targetClass.getDeclaredFields()) {
            if (field.isAnnotationPresent(Interconnect.class)) {
                if (Modifier.isStatic(field.getModifiers())) {
                    throw new IllegalStateException(
                            "@Interconnect annotation is not supported on static fields");
                }
                currElements.add(new InterconnectElement(field, null));
            }
        }
        for (Method method : targetClass.getDeclaredMethods()) {
            Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
            if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
                continue;
            }
            if (method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
                if (bridgedMethod.isAnnotationPresent(Interconnect.class)) {
                    if (Modifier.isStatic(method.getModifiers())) {
                        throw new IllegalStateException(
                                "@Interconnect annotation is not supported on static methods");
                    }
                    if (method.getParameterTypes().length != 1) {
                        throw new IllegalStateException(
                                "@Interconnect annotation requires a single-arg method: " + method);
                    }
                    PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
                    currElements.add(new InterconnectElement(method, pd));
                }
            }
        }
        elements.addAll(0, currElements);
        targetClass = targetClass.getSuperclass();
    } while ((targetClass != null) && (targetClass != Object.class));

    return new InjectionMetadata(clazz, elements);
}

From source file:org.seasar.dao.spring.autoregister.AbstractBeanAutoRegister.java

private boolean isApplicableAspect(final Method method) {
    final int mod = method.getModifiers();
    return !Modifier.isFinal(mod) && !Modifier.isStatic(mod);
}

From source file:at.ac.tuwien.infosys.jcloudscale.classLoader.caching.fileCollectors.FileCollectorAbstract.java

/**
 * Collects the list of required files without content.
 * @param clazz the class that related files should be collected for. (joda style)
 * @return List of files that are required for specified class or 
 * null if none are required. //from  w ww  .ja  v  a  2s .  co m
 */
protected List<ClassLoaderFile> collectRequiredFiles(Class<?> clazz) {
    FileDependency fileDependency = clazz.getAnnotation(FileDependency.class);

    if (fileDependency == null)
        return null;

    List<ClassLoaderFile> files = new ArrayList<ClassLoaderFile>();

    if (fileDependency.dependencyProvider().equals(IFileDependencyProvider.class)) {// we have static files
        //         ContentType contentType = fileDependency.accessType() == FileAccess.ReadOnly ? 
        //                                    ContentType.ROFILE : ContentType.RWFILE;
        ContentType contentType = ContentType.ROFILE;

        String[] fileNames = fileDependency.files();

        if (fileNames == null || fileNames.length == 0)
            return null;

        for (String filename : fileNames) {
            File file = RemoteClassLoaderUtils.getRelativePathFile(filename);
            if (!file.exists()) {
                log.severe("Class " + clazz.getName() + " set file " + filename
                        + " as required, but the file is missing at " + file.getAbsolutePath());
                continue;
            }

            files.add(new ClassLoaderFile(filename, file.lastModified(), file.length(), contentType));
        }
    } else {// we have dynamic file list, let's process it.
        Class<? extends IFileDependencyProvider> dependentFilesProviderClass = fileDependency
                .dependencyProvider();
        if (dependentFilesProviderClass == null)
            return null;

        //checking if we can create this class
        if (dependentFilesProviderClass.isInterface()
                || Modifier.isAbstract(dependentFilesProviderClass.getModifiers()))
            throw new JCloudScaleException("Class " + clazz.getName()
                    + "is anotated with @FileDependency and has class " + dependentFilesProviderClass.getName()
                    + " as dependency provider. However, dependency provider class is either abstract or interface.");

        if (dependentFilesProviderClass.getEnclosingClass() != null
                && !Modifier.isStatic(dependentFilesProviderClass.getModifiers()))
            throw new JCloudScaleException("Class " + clazz.getName()
                    + "is anotated with @FileDependency and has class " + dependentFilesProviderClass.getName()
                    + " as dependency provider. However, dependency provider class is internal and not static. The class has to be static in this case.");

        Constructor<? extends IFileDependencyProvider> constructor = null;
        try {
            constructor = dependentFilesProviderClass.getDeclaredConstructor();
        } catch (NoSuchMethodException ex) {
            throw new JCloudScaleException(ex, "Class " + clazz.getName()
                    + "is anotated with @FileDependency and has class " + dependentFilesProviderClass.getName()
                    + " as dependency provider. However, dependency provider class cannot be created as it has no parameterless constructor.");
        }

        try {
            if (!constructor.isAccessible())
                constructor.setAccessible(true);

            IFileDependencyProvider provider = constructor.newInstance();

            for (DependentFile dependentFile : provider.getDependentFiles()) {
                File file = RemoteClassLoaderUtils.getRelativePathFile(dependentFile.filePath);
                if (!file.exists()) {
                    log.severe("Class " + clazz.getName() + " set file " + dependentFile.filePath
                            + " as required, but the file is missing.");
                    continue;
                }

                //               ContentType contentType = dependentFile.accessType == FileAccess.ReadOnly ? 
                //                     ContentType.ROFILE : ContentType.RWFILE;
                ContentType contentType = ContentType.ROFILE;

                files.add(new ClassLoaderFile(file.getPath(), file.lastModified(), file.length(), contentType));
            }
        } catch (Exception ex) {
            log.severe("Dependent files provider " + dependentFilesProviderClass.getName() + " for class "
                    + clazz.getName() + " threw exception during execution:" + ex.toString());
            throw new JCloudScaleException(ex,
                    "Dependent files provider " + dependentFilesProviderClass.getName() + " for class "
                            + clazz.getName() + " threw exception during execution.");
        }
    }

    return files;
}