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:com.icfcc.cache.interceptor.AbstractFallbackCacheOperationSource.java

private Collection<CacheOperation> computeCacheOperations(Method method, Class<?> targetClass) {
    // Don't allow no-public methods as required.
    if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) {
        return null;
    }/*  w  w  w.j a  v  a  2  s  .  c om*/

    // The method may be on an interface, but we need attributes from the target class.
    // If the target class is null, the method will be unchanged.
    Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
    // If we are dealing with method with generic parameters, find the original method.
    specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);

    // First try is the method in the target class.
    Collection<CacheOperation> opDef = findCacheOperations(specificMethod);
    if (opDef != null) {
        return opDef;
    }

    // Second try is the caching operation on the target class.
    opDef = findCacheOperations(specificMethod.getDeclaringClass());
    if (opDef != null) {
        return opDef;
    }

    if (specificMethod != method) {
        // Fall back is to look at the original method.
        opDef = findCacheOperations(method);
        if (opDef != null) {
            return opDef;
        }
        // Last fall back is the class of the original method.
        return findCacheOperations(method.getDeclaringClass());
    }
    return null;
}

From source file:io.silverware.microservices.providers.cdi.internal.RestInterface.java

@SuppressWarnings("checkstyle:JavadocMethod")
public void listMethods(final RoutingContext routingContext) {
    String microserviceName = routingContext.request().getParam("microservice");
    Bean bean = gatewayRegistry.get(microserviceName);

    if (bean == null) {
        routingContext.response().setStatusCode(503).end("Resource not available");
    } else {/*from  w w w  .j a  va 2  s.  c  om*/
        JsonArray methods = new JsonArray();

        for (final Method m : bean.getBeanClass().getDeclaredMethods()) {
            if (Modifier.isPublic(m.getModifiers())) {
                JsonObject method = new JsonObject();
                method.put("methodName", m.getName());
                JsonArray params = new JsonArray();
                for (Class c : m.getParameterTypes()) {
                    params.add(c.getName());
                }
                method.put("parameters", params);
                method.put("returns", m.getReturnType().getName());

                methods.add(method);
            }
        }

        routingContext.response().end(methods.encodePrettily());
    }
}

From source file:com.evolveum.midpoint.repo.sql.query.definition.ClassDefinitionParser.java

private void updateEntityDefinition(EntityDefinition entity) {
    LOGGER.trace("### {}", new Object[] { entity.getJpaName() });
    addVirtualDefinitions(entity);/*from   w  w  w.j a  va2s  .  c o  m*/
    Method[] methods = entity.getJpaType().getMethods();

    entity.setEmbedded(entity.getJpaType().getAnnotation(Embeddable.class) != null);

    for (Method method : methods) {
        String methodName = method.getName();
        if (Modifier.isStatic(method.getModifiers()) || "getClass".equals(methodName)
                || !methodName.startsWith("is") && !methodName.startsWith("get")) {
            //it's not getter for property
            continue;
        }

        if (method.isAnnotationPresent(Transient.class)) {
            continue;
        }

        LOGGER.trace("# {}", new Object[] { methodName });

        QName jaxbName = getJaxbName(method);
        Class jaxbType = getJaxbType(method);
        String jpaName = getJpaName(method);
        Definition definition = createDefinition(jaxbName, jaxbType, jpaName, method);
        entity.addDefinition(definition);
    }
}

From source file:org.apache.tapestry.enhance.DefaultComponentClassEnhancer.java

/**
 *  Searches the class for abstract methods, returning the first found.
 *  Records non-abstract methods in the implementedMethods set.
 * /*from ww  w .j  a v  a2  s .  c om*/
 **/

private Method checkForAbstractMethods(Class current, Set implementedMethods) {
    boolean debug = LOG.isDebugEnabled();

    if (debug)
        LOG.debug("Searching for abstract methods in " + current);

    Method[] methods = current.getDeclaredMethods();

    for (int i = 0; i < methods.length; i++) {
        Method m = methods[i];

        if (debug)
            LOG.debug("Checking " + m);

        boolean isAbstract = Modifier.isAbstract(m.getModifiers());

        MethodSignature s = new MethodSignature(m);

        if (isAbstract) {
            if (implementedMethods.contains(s))
                continue;

            return m;
        }

        implementedMethods.add(s);
    }

    return null;
}

From source file:com.laxser.blitz.web.impl.module.ControllerRef.java

private boolean quicklyPass(List<Method> pastMethods, Method method, Class<?> controllerClass) {
    // public, not static, not abstract, @Ignored
    if (!Modifier.isPublic(method.getModifiers()) || Modifier.isAbstract(method.getModifiers())
            || Modifier.isStatic(method.getModifiers()) || method.isAnnotationPresent(Ignored.class)) {
        if (logger.isDebugEnabled()) {
            logger.debug("ignores method of controller " + controllerClass.getName() + "." + method.getName()
                    + "  [@ignored?not public?abstract?static?]");
        }/*from   ww w .j a v a 2  s  . c o  m*/
        return true;
    }
    // ?(?)?????
    for (Method past : pastMethods) {
        if (past.getName().equals(method.getName())) {
            if (Arrays.equals(past.getParameterTypes(), method.getParameterTypes())) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.weibo.api.motan.config.AbstractConfig.java

private boolean isConfigMethod(Method method) {
    boolean checkMethod = (method.getName().startsWith("get") || method.getName().startsWith("is"))
            && !"isDefault".equals(method.getName()) && Modifier.isPublic(method.getModifiers())
            && method.getParameterTypes().length == 0 && isPrimitive(method.getReturnType());

    if (checkMethod) {
        ConfigDesc configDesc = method.getAnnotation(ConfigDesc.class);
        if (configDesc != null && configDesc.excluded()) {
            return false;
        }/*from  ww w. j av a2s . c om*/
    }
    return checkMethod;
}

From source file:org.apache.openjpa.enhance.PCSubclassValidator.java

private void checkMethodIsSubclassable(Method meth, FieldMetaData fmd) {
    String className = fmd.getDefiningMetaData().getDescribedType().getName();
    if (!(Modifier.isProtected(meth.getModifiers()) || Modifier.isPublic(meth.getModifiers())))
        addError(loc.get("subclasser-private-accessors-unsupported", className, meth.getName()), fmd);
    if (Modifier.isFinal(meth.getModifiers()))
        addError(loc.get("subclasser-final-methods-not-allowed", className, meth.getName()), fmd);
    if (Modifier.isNative(meth.getModifiers()))
        addContractViolation(loc.get("subclasser-native-methods-not-allowed", className, meth.getName()), fmd);
    if (Modifier.isStatic(meth.getModifiers()))
        addError(loc.get("subclasser-static-methods-not-supported", className, meth.getName()), fmd);
}

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

private static synchronized Method[] getPublicDeclaredMethods(Class clz) {
    // Looking up Class.getDeclaredMethods is relatively expensive,
    // so we cache the results.
    final Class fclz = clz;
    Method[] result = (Method[]) declaredMethodCache.get(fclz);
    if (result != null) {
        return result;
    }/*from   www  . j  a v a 2 s.  co  m*/

    // We have to raise privilege for getDeclaredMethods
    result = (Method[]) AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            try {

                return fclz.getDeclaredMethods();

            } catch (SecurityException ex) {
                // this means we're in a limited security environment
                // so let's try going through the public methods
                // and null those those that are not from the declaring
                // class
                Method[] methods = fclz.getMethods();
                for (int i = 0, size = methods.length; i < size; i++) {
                    Method method = methods[i];
                    if (!(fclz.equals(method.getDeclaringClass()))) {
                        methods[i] = null;
                    }
                }
                return methods;
            }
        }
    });

    // Null out any non-public methods.
    for (int i = 0; i < result.length; i++) {
        Method method = result[i];
        if (method != null) {
            int mods = method.getModifiers();
            if (!Modifier.isPublic(mods)) {
                result[i] = null;
            }
        }
    }

    // Add it to the cache.
    declaredMethodCache.put(clz, result);
    return result;
}

From source file:com.opensource.frameworks.processframework.utils.MethodInvoker.java

/**
 * Invoke the specified method.//w ww  .  j  av a 2  s.  c om
 * <p>The invoker needs to have been prepared before.
 * @return the object (possibly null) returned by the method invocation,
 * or <code>null</code> if the method has a void return type
 * @throws InvocationTargetException if the target method threw an exception
 * @throws IllegalAccessException if the target method couldn't be accessed
 * @see #prepare
 */
public Object invoke() throws InvocationTargetException, IllegalAccessException {
    // In the static case, target will simply be <code>null</code>.
    Object targetObject = getTargetObject();
    Method preparedMethod = getPreparedMethod();
    if (targetObject == null && !Modifier.isStatic(preparedMethod.getModifiers())) {
        throw new IllegalArgumentException("Target method must not be non-static without a target");
    }
    ReflectionUtils.makeAccessible(preparedMethod);
    return preparedMethod.invoke(targetObject, getArguments());
}

From source file:com.developmentsprint.spring.breaker.annotations.AbstractFallbackCircuitBreakerAttributeSource.java

/**
 * Same signature as {@link #getCircuitBreakerAttribute}, but doesn't cache the result. {@link #getCircuitBreakerAttribute} is effectively a caching
 * decorator for this method./*from  w  w w . ja v a2s.  co m*/
 * 
 * @see #getCircuitBreakerAttribute(Method, Class)
 */
private CircuitBreakerAttribute computeCircuitBreakerAttribute(Method method, Class<?> targetClass) {
    // Don't allow no-public methods as required.
    if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) {
        return null;
    }

    // Ignore CGLIB subclasses - introspect the actual user class.
    Class<?> userClass = ClassUtils.getUserClass(targetClass);

    // The method may be on an interface, but we need attributes from the target class.
    // If the target class is null, the method will be unchanged.
    Method specificMethod = ClassUtils.getMostSpecificMethod(method, userClass);

    // If we are dealing with method with generic parameters, find the original method.
    specificMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);

    // First try is the method in the target class.
    CircuitBreakerAttribute cbAttribute = findCircuitBreakerAttribute(specificMethod);
    if (cbAttribute != null) {
        return cbAttribute;
    }

    // Second try is the circuit breaker attribute on the target class.
    cbAttribute = findCircuitBreakerAttribute(specificMethod.getDeclaringClass());
    if (cbAttribute != null) {
        return cbAttribute;
    }

    if (specificMethod != method) {
        // Fallback is to look at the original method.
        cbAttribute = findCircuitBreakerAttribute(method);
        if (cbAttribute != null) {
            return cbAttribute;
        }
        // Last fallback is the class of the original method.
        return findCircuitBreakerAttribute(method.getDeclaringClass());
    }
    return null;
}