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:org.agiso.core.i18n.util.I18nUtils.java

private static String findGetterFieldCode(Class<?> c, String field, boolean reflectionCheck)
        throws IntrospectionException {
    for (PropertyDescriptor pd : Introspector.getBeanInfo(c).getPropertyDescriptors()) {
        if (pd.getName().equals(field)) {
            final Method g = pd.getReadMethod();
            if (g != null) {
                // Jeli jest adnotacja I18n na metodzie odczytujcej pole, to pobieranie
                // pobieranie jej klucza (okrelonego przez 'value') lub klucza domylnego:
                if (g.isAnnotationPresent(I18n.class)) {
                    if (g.getAnnotation(I18n.class).value().length() > 0) {
                        return g.getAnnotation(I18n.class).value();
                    } else {
                        return g.getDeclaringClass().getName() + CODE_SEPARATOR + field;
                    }/*from   w w  w.ja va 2s .  c  o  m*/
                } else if (reflectionCheck) {
                    // Pole nie jest opisane adnotacj I18n. Jeli do wyszukania maj by
                    // wykorzystane mechanizmy refleksji, to sprawdzamy interfejsy i nadklas:
                    for (Class<?> i : c.getInterfaces()) {
                        String i18nCode = findGetterFieldCode(i, field, false);
                        if (i18nCode != null) {
                            return i18nCode;
                        }
                    }
                    Class<?> s = c.getSuperclass();
                    if (s != null) {
                        return findGetterFieldCode(s, field, true);
                    }
                }
            }
        }
    }
    if (reflectionCheck) {
        for (Class<?> i : c.getInterfaces()) {
            String i18nCode = findGetterFieldCode(i, field, false);
            if (i18nCode != null) {
                return i18nCode;
            }
        }
    }

    return null;
}

From source file:org.arrow.model.definition.AbstractEventPublisherIntroduction.java

/**
 * {@inheritDoc}//  w  ww . ja  v  a  2s .  c om
 */
@Override
protected Object doProceed(MethodInvocation mi) throws Throwable {

    Method method = mi.getMethod();
    Class<?> dc = method.getDeclaringClass();
    if (dc.isAssignableFrom(Executable.class) && method.getName().equals("execute")) {
        Execution execution = (Execution) mi.getArguments()[0];
        ExecutionService service = (ExecutionService) mi.getArguments()[1];

        Logger.getLogger(getClass()).info("publish event");
        publishEvent(execution, service);
    }

    return mi.proceed();
}

From source file:grails.plugin.cache.web.filter.ExpressionEvaluator.java

protected String toString(Method method, String expression) {
    return method.getDeclaringClass().getName() + '#' + method + '#' + expression;
}

From source file:de.bund.bva.pliscommon.serviceapi.core.serviceimpl.ReflectiveExceptionMappingSource.java

/**
 * Liefert die Methodensignatur als String.
 * //w  w  w.j av a2  s. com
 * @param method
 *            die Methode
 * @return die Methodensignatur als String.
 */
protected String getMethodSignatureString(Method method) {
    return method.getDeclaringClass().getName() + "." + method.getName();
}

From source file:grails.plugin.cache.web.filter.LazyParamAwareEvaluationContext.java

protected String toString(Method m) {
    return m.getDeclaringClass().getName() + '#' + m;
}

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

static Method mostDerived(Method meth1, Method meth2) {
    if (meth1 == null)
        return meth2;
    if (meth2 == null)
        return meth1;

    Class cls2 = meth2.getDeclaringClass();
    Class cls1 = meth1.getDeclaringClass();

    if (cls1.equals(cls2)) {
        Class ret1 = meth1.getReturnType();
        Class ret2 = meth2.getReturnType();
        if (ret1.isAssignableFrom(ret2))
            return meth2;
        else if (ret2.isAssignableFrom(ret1))
            return meth1;
        else/*from   ww w .  j  a  va 2s  .c  o m*/
            throw new IllegalArgumentException(
                    _loc.get("most-derived-unrelated-same-type", meth1, meth2).getMessage());
    } else {
        if (cls1.isAssignableFrom(cls2))
            return meth2;
        else if (cls2.isAssignableFrom(cls1))
            return meth1;
        else
            throw new IllegalArgumentException(_loc.get("most-derived-unrelated", meth1, meth2).getMessage());
    }
}

From source file:org.arrow.model.definition.conditional.introduction.ConditionalEventPublisherIntroduction.java

/**
 * {@inheritDoc}//  w  ww . j  av a  2s.  c o  m
 */
@Override
protected Object doProceed(MethodInvocation mi) throws Throwable {

    Method method = mi.getMethod();
    Class<?> dc = method.getDeclaringClass();
    if (dc.isAssignableFrom(Execution.class) && method.getName().equals("execute")) {
        Execution execution = (Execution) mi.getArguments()[0];
        ExecutionService service = (ExecutionService) mi.getArguments()[1];
        publishConditionalEvent(execution, service);
    }

    return mi.proceed();
}

From source file:org.hawkular.services.rest.test.AbstractTestBase.java

@BeforeMethod
public void beforeTest(Method method) {
    String tenantId = method.getDeclaringClass().getSimpleName() + "." + method.getName() + "."
            + random.nextInt();/*from w w w  .j  ava  2s .  c  om*/
    this.testClient = newClient(tenantId);
}

From source file:com.drillmap.crm.repository.extensions.invoker.CrudRepositoryInvoker.java

private boolean isRedeclaredMethod(Method method) {
    return !method.getDeclaringClass().equals(CrudRepository.class);
}

From source file:org.docksidestage.dbflute.svflute.GodHandableControllerInterceptor.java

protected String buildActionDisp(HandlerMethod handlerMethod) {
    final Method method = handlerMethod.getMethod();
    final Class<?> declaringClass = method.getDeclaringClass();
    return declaringClass.getSimpleName() + "." + method.getName() + "()";
}