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

public static void main(String[] args) {
    try {//from   ww  w .jav  a2  s . c  om
        Class<?> clazz = Class.forName("X");
        X x = (X) clazz.newInstance();
        Class[] argTypes = { String.class };
        Method method = clazz.getMethod("objectMethod", argTypes);

        System.out.println(method.getDeclaringClass());

    } catch (Exception e) {
        System.err.println(e);
    }
}

From source file:Main.java

private static boolean isGroovyObjectMethod(Method method) {
    return method.getDeclaringClass().getName().equals("groovy.lang.GroovyObject");
}

From source file:Main.java

public static String getQualifiedMethodName(Method method) {
    return (new StringBuilder()).append(method.getDeclaringClass().getName()).append(".")
            .append(method.getName()).toString();
}

From source file:Main.java

public static Method[] getSelfMethod(Object o) {
    Class c = o.getClass();//from   w  w w.  java  2s.  c om
    Method[] ms = o.getClass().getMethods();
    List list = new ArrayList();
    for (Method m : ms) {
        int mod = m.getModifiers();
        if (m.getDeclaringClass().equals(c) && Modifier.isPublic(mod) && !Modifier.isStatic(mod)) {
            list.add(m);
        }

    }
    return (Method[]) list.toArray(new Method[0]);
}

From source file:com.github.tddts.jet.util.SpringUtil.java

public static Method getMethod(JoinPoint joinPoint) throws NoSuchMethodException {
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Method method = signature.getMethod();

    if (method.getDeclaringClass().isInterface()) {
        method = joinPoint.getTarget().getClass().getDeclaredMethod(joinPoint.getSignature().getName(),
                method.getParameterTypes());
    }//from  ww  w  .j  av  a2  s  . c  o m

    return method;
}

From source file:org.codehaus.groovy.grails.plugins.springsecurity.acl.ProxyUtils.java

/**
 * Finds the method in the unproxied superclass if proxied.
 * @param method  the method/*from w  w w .j  av a2s  . c  o  m*/
 * @return  the method in the unproxied class
 */
public static Method unproxy(final Method method) {
    Class<?> clazz = method.getDeclaringClass();

    if (!AopUtils.isCglibProxyClass(clazz)) {
        return method;
    }

    return ReflectionUtils.findMethod(unproxy(clazz), method.getName(), method.getParameterTypes());
}

From source file:cherry.example.web.util.ViewNameUtil.java

public static String fromMethodCall(Object invocationInfo) {

    MethodInvocationInfo info = (MethodInvocationInfo) invocationInfo;
    Method method = info.getControllerMethod();
    Class<?> type = method.getDeclaringClass();

    UriComponentsBuilder ucb = UriComponentsBuilder.newInstance();
    String typePath = getMappedPath(type.getAnnotation(RequestMapping.class));
    if (StringUtils.isNotEmpty(typePath)) {
        ucb.path(typePath);//from   w ww  . ja  v  a 2s .c  om
    }

    String methodPath = getMappedPath(method.getAnnotation(RequestMapping.class));
    if (StringUtils.isNotEmpty(methodPath)) {
        ucb.pathSegment(methodPath);
    }

    String path = ucb.build().getPath();
    if (path.startsWith("/")) {
        return path.substring(1);
    }
    return path;
}

From source file:it.tidalwave.northernwind.aspect.DebugProfilingAspect.java

@Nonnull
private static <T extends Annotation> T getAnnotation(final @Nonnull ProceedingJoinPoint pjp,
        final @Nonnull Class<T> annotationClass) throws NoSuchMethodException {
    final MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
    Method method = methodSignature.getMethod();

    if (method.getDeclaringClass().isInterface()) // FIXME && annotation inheritance -- FIXME also ancestor class
    {/* w w w . j  a v  a 2 s.c o m*/
        final String methodName = pjp.getSignature().getName();
        method = pjp.getTarget().getClass().getDeclaredMethod(methodName, method.getParameterTypes());
    }

    return method.getAnnotation(annotationClass);
}

From source file:net.mindengine.galen.reports.GalenTestInfo.java

public static GalenTestInfo fromMethod(Method method) {
    String name = method.getDeclaringClass().getName() + "#" + method.getName();
    return GalenTestInfo.fromString(name);
}

From source file:grails.plugin.springsecurity.acl.util.ProxyUtils.java

/**
 * Finds the method in the unproxied superclass if proxied.
 * @param method  the method//from w w w .  java 2 s  . c o m
 * @return  the method in the unproxied class
 */
public static Method unproxy(final Method method) {
    Class<?> clazz = method.getDeclaringClass();

    if (!isProxy(clazz)) {
        return method;
    }

    return ReflectionUtils.findMethod(unproxy(clazz), method.getName(), method.getParameterTypes());
}