Example usage for java.lang.reflect Method getDeclaringClass

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

Introduction

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

Prototype

@Override
public Class<?> getDeclaringClass() 

Source Link

Document

Returns the Class object representing the class or interface that declares the method represented by this object.

Usage

From source file:io.github.resilience4j.circuitbreaker.configure.CircuitBreakerAspect.java

@Around(value = "matchAnnotatedClassOrMethod(backendMonitored)", argNames = "proceedingJoinPoint, backendMonitored")
public Object circuitBreakerAroundAdvice(ProceedingJoinPoint proceedingJoinPoint,
        CircuitBreaker backendMonitored) throws Throwable {
    Method method = ((MethodSignature) proceedingJoinPoint.getSignature()).getMethod();
    String methodName = method.getDeclaringClass().getName() + "#" + method.getName();
    if (backendMonitored == null) {
        backendMonitored = getBackendMonitoredAnnotation(proceedingJoinPoint);
    }/*from   w  w  w. java 2s  .  co m*/
    String backend = backendMonitored.name();
    io.github.resilience4j.circuitbreaker.CircuitBreaker circuitBreaker = getOrCreateCircuitBreaker(methodName,
            backend);
    return handleJoinPoint(proceedingJoinPoint, circuitBreaker, methodName);
}

From source file:com.metaparadigm.jsonrpc.JSONRPCBridge.java

private static ClassData analyzeClass(Class clazz) {
    log.info("analyzing " + clazz.getName());
    Method methods[] = clazz.getMethods();
    ClassData cd = new ClassData();
    cd.clazz = clazz;//from  w w w .java  2 s  .  c  o m

    // Create temporary method map
    HashMap staticMethodMap = new HashMap();
    HashMap methodMap = new HashMap();
    for (int i = 0; i < methods.length; i++) {
        Method method = methods[i];
        if (method.getDeclaringClass() == Object.class)
            continue;
        int mod = methods[i].getModifiers();
        if (!Modifier.isPublic(mod))
            continue;
        Class param[] = method.getParameterTypes();

        // don't count locally resolved args
        int argCount = 0;
        synchronized (localArgResolverMap) {
            for (int n = 0; n < param.length; n++) {
                HashSet resolvers = (HashSet) localArgResolverMap.get(param[n]);
                if (resolvers != null)
                    continue;
                argCount++;
            }
        }

        MethodKey mk = new MethodKey(method.getName(), argCount);
        ArrayList marr = (ArrayList) methodMap.get(mk);
        if (marr == null) {
            marr = new ArrayList();
            methodMap.put(mk, marr);
        }
        marr.add(method);
        if (Modifier.isStatic(mod)) {
            marr = (ArrayList) staticMethodMap.get(mk);
            if (marr == null) {
                marr = new ArrayList();
                staticMethodMap.put(mk, marr);
            }
            marr.add(method);
        }
    }
    cd.methodMap = new HashMap();
    cd.staticMethodMap = new HashMap();
    // Convert ArrayLists to arrays
    Iterator i = methodMap.entrySet().iterator();
    while (i.hasNext()) {
        Map.Entry entry = (Map.Entry) i.next();
        MethodKey mk = (MethodKey) entry.getKey();
        ArrayList marr = (ArrayList) entry.getValue();
        if (marr.size() == 1) {
            cd.methodMap.put(mk, marr.get(0));
        } else {
            cd.methodMap.put(mk, marr.toArray(new Method[0]));
        }
    }
    i = staticMethodMap.entrySet().iterator();
    while (i.hasNext()) {
        Map.Entry entry = (Map.Entry) i.next();
        MethodKey mk = (MethodKey) entry.getKey();
        ArrayList marr = (ArrayList) entry.getValue();
        if (marr.size() == 1) {
            cd.staticMethodMap.put(mk, marr.get(0));
        } else {
            cd.staticMethodMap.put(mk, marr.toArray(new Method[0]));
        }
    }
    return cd;
}

From source file:net.ymate.platform.cache.impl.DefaultKeyGenerator.java

public Serializable generateKey(Method method, Object[] params) throws Exception {
    // [className:methodName:{serializeStr}]
    StringBuilder __keyGenBuilder = new StringBuilder();
    __keyGenBuilder.append("[").append(method.getDeclaringClass().getName()).append(":")
            .append(method.getName()).append("{");
    String _paramsB64 = Base64.encodeBase64String(__serializer.serialize(params));
    __keyGenBuilder.append(_paramsB64).append("}]");
    return DigestUtils.md5Hex(__keyGenBuilder.toString());
}

From source file:com.laidians.utils.ClassUtils.java

/**
 * Given a method, which may come from an interface, and a target class used
 * in the current reflective invocation, find the corresponding target method
 * if there is one. E.g. the method may be <code>IFoo.bar()</code> and the
 * target class may be <code>DefaultFoo</code>. In this case, the method may be
 * <code>DefaultFoo.bar()</code>. This enables attributes on that method to be found.
 * <p><b>NOTE:</b> In contrast to {@link org.springframework.aop.support.AopUtils#getMostSpecificMethod},
 * this method does <i>not</i> resolve Java 5 bridge methods automatically.
 * Call {@link org.springframework.core.BridgeMethodResolver#findBridgedMethod}
 * if bridge method resolution is desirable (e.g. for obtaining metadata from
 * the original method definition)./*from w w  w  . jav  a 2  s .  com*/
 * @param method the method to be invoked, which may come from an interface
 * @param targetClass the target class for the current invocation.
 * May be <code>null</code> or may not even implement the method.
 * @return the specific target method, or the original method if the
 * <code>targetClass</code> doesn't implement it or is <code>null</code>
 */
public static Method getMostSpecificMethod(Method method, Class<?> targetClass) {
    Method specificMethod = null;
    if (method != null && isOverridable(method, targetClass) && targetClass != null
            && !targetClass.equals(method.getDeclaringClass())) {
        specificMethod = ReflectionUtils.findMethod(targetClass, method.getName(), method.getParameterTypes());
    }
    return (specificMethod != null ? specificMethod : method);
}

From source file:de.hybris.platform.converters.impl.AbstractConverter.java

@Override
public void afterPropertiesSet() throws Exception {
    if (targetClass == null) {
        final Class<? extends AbstractConverter> cl = this.getClass();
        final Method createTargetMethod = ReflectionUtils.findMethod(cl, "createTarget");
        if (AbstractConverter.class.equals(createTargetMethod.getDeclaringClass())) {
            throw new IllegalStateException("Converter '" + myBeanName
                    + "' doesn't have a targetClass property nor does it override createTarget()!");
        }/*from  w ww. j a v a 2  s . c o m*/
    }
}

From source file:ome.tools.hibernate.EventMethodInterceptor.java

public Object invoke(MethodInvocation arg0) throws Throwable {
    Object[] args = arg0.getArguments();
    Method method = arg0.getMethod();

    if (verbose && method.getName().startsWith("on")) {
        log(String.format("%s.%s called.", method.getDeclaringClass().getName(), method.getName()));
    }// w ww  .j a  v a 2  s. c o  m

    return action.call(arg0);
}

From source file:de.otto.jsonhome.generator.ResourceLinkGenerator.java

/**
 * Analyses a method of a controller and returns the fully qualified URI of the link-relation type.
 *
 * If the neither the method, nor the controller is annotated with Rel, null is returned.
 *
 * The Rel of the method is overriding the Rel of the Controller.
 *
 * @param method the method//from   w  ww  .  j a v a2s  .  c o m
 * @return URI of the link-relation type, or null
 */
protected URI relationTypeFrom(final Method method) {
    final Rel controllerRel = findAnnotation(method.getDeclaringClass(), Rel.class);
    final Rel methodRel = findAnnotation(method, Rel.class);
    if (controllerRel == null && methodRel == null) {
        return null;
    } else {
        final String linkRelationType = methodRel != null ? methodRel.value() : controllerRel.value();
        if (linkRelationType.startsWith("http://")) {
            return create(linkRelationType);
        } else {
            return normalized(relationTypeBaseUri).withPathSegment(linkRelationType).toUri();
        }
    }
}

From source file:org.apache.ode.utils.LoggingInterceptor.java

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    try {/*from  www. java 2 s .c  om*/
        if (method.getDeclaringClass() == DataSource.class && "getConnection".equals(method.getName())) {
            Connection conn = (Connection) method.invoke(_delegate, args);
            print("getConnection (tx=" + conn.getTransactionIsolation() + ")");
            return Proxy.newProxyInstance(_delegate.getClass().getClassLoader(),
                    new Class[] { Connection.class }, new LoggingInterceptor<Connection>(conn, _log));
        } else if (method.getDeclaringClass() == Connection.class
                && Statement.class.isAssignableFrom(method.getReturnType())) {
            Statement stmt = (Statement) method.invoke(_delegate, args);
            print(method, args);
            return Proxy.newProxyInstance(_delegate.getClass().getClassLoader(),
                    new Class[] { method.getReturnType() }, new LoggingInterceptor<Statement>(stmt, _log));
        } else {
            print(method, args);
            return method.invoke(_delegate, args);
        }
    } catch (InvocationTargetException e) {
        throw e.getTargetException();
    }
}

From source file:org.apache.hadoop.hive.ql.exec.MapredContext.java

private boolean needConfigure(Object func) {
    try {//from  w w  w .  java  2s .  com
        Method initMethod = func.getClass().getMethod("configure", MapredContext.class);
        return initMethod.getDeclaringClass() != GenericUDF.class
                && initMethod.getDeclaringClass() != GenericUDAFEvaluator.class
                && initMethod.getDeclaringClass() != GenericUDTF.class;
    } catch (Exception e) {
        return false;
    }
}

From source file:com.github.jasonruckman.sidney.generator.BeanBuilder.java

private Accessors.FieldAccessor accessor(Method method) {
    PropertyDescriptor descriptor = BeanUtils.findPropertyForMethod(method);
    Class<?> declaringClass = method.getDeclaringClass();
    Field field = Fields.getFieldByName(declaringClass, descriptor.getName());
    return Accessors.newAccessor(field);
}