Example usage for java.lang.reflect Method getReturnType

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

Introduction

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

Prototype

public Class<?> getReturnType() 

Source Link

Document

Returns a Class object that represents the formal return type of the method represented by this Method object.

Usage

From source file:de.vandermeer.asciithemes.a7.Test_A7_NumberingSchemes.java

@Test
public void test_Doc() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    for (Method m : A7_NumberingSchemes.class.getMethods()) {
        if (m.getReturnType() == TA_Numbering.class) {
            Object descr = ((TA_Numbering) m.invoke("")).getDescription();
            StrBuilder doc = ((TA_Numbering) m.invoke("")).toDoc();
            System.out.println(m.getName() + " = " + descr);
            System.out.println();
            System.out.println("----");
            System.out.println(doc);
            System.out.println("----");
            System.out.println();
            System.out.println();
        }/*from  w ww.  ja  v  a 2s  . c  o  m*/
    }
}

From source file:de.vandermeer.asciithemes.u8.Test_U8_NumberingSchemes.java

@Test
public void test_Doc() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    for (Method m : U8_NumberingSchemes.class.getMethods()) {
        if (m.getReturnType() == TA_Numbering.class) {
            Object descr = ((TA_Numbering) m.invoke("")).getDescription();
            StrBuilder doc = ((TA_Numbering) m.invoke("")).toDoc();
            System.out.println(m.getName() + " = " + descr);
            System.out.println();
            System.out.println("----");
            System.out.println(doc);
            System.out.println("----");
            System.out.println();
            System.out.println();
        }//from ww w.  j  a  v  a  2s.com
    }
}

From source file:com.github.drinkjava2.jbeanbox.springsrc.ReflectionUtils.java

/**
 * Get the unique set of declared methods on the leaf class and all superclasses. Leaf class methods are included
 * first and while traversing the superclass hierarchy any methods found with signatures matching a method already
 * included are filtered out.//from w  w w  .  j av a 2  s. c o  m
 * 
 * @param leafClass
 *            the class to introspect
 */
public static Method[] getUniqueDeclaredMethods(Class<?> leafClass) {
    final List<Method> methods = new ArrayList<Method>(32);
    doWithMethods(leafClass, new MethodCallback() {
        public void doWith(Method method) {
            boolean knownSignature = false;
            Method methodBeingOverriddenWithCovariantReturnType = null;
            for (Method existingMethod : methods) {
                if (method.getName().equals(existingMethod.getName())
                        && Arrays.equals(method.getParameterTypes(), existingMethod.getParameterTypes())) {
                    // Is this a covariant return type situation?
                    if (existingMethod.getReturnType() != method.getReturnType()
                            && existingMethod.getReturnType().isAssignableFrom(method.getReturnType())) {
                        methodBeingOverriddenWithCovariantReturnType = existingMethod;
                    } else {
                        knownSignature = true;
                    }
                    break;
                }
            }
            if (methodBeingOverriddenWithCovariantReturnType != null) {
                methods.remove(methodBeingOverriddenWithCovariantReturnType);
            }
            if (!knownSignature && !isCglibRenamedMethod(method)) {
                methods.add(method);
            }
        }
    });
    return methods.toArray(new Method[methods.size()]);
}

From source file:com.jxva.exception.ExceptionUtil.java

/**
 * <p>Checks whether this <code>Throwable</code> class can store a cause.</p>
 *
 * <p>This method does <b>not</b> check whether it actually does store a cause.<p>
 *
 * @param throwable  the <code>Throwable</code> to examine, may be null
 * @return boolean <code>true</code> if nested otherwise <code>false</code>
 * @since 2.0/* ww w  . j  ava2  s .  c  o  m*/
 */
public static boolean isNestedThrowable(Throwable throwable) {
    if (throwable == null) {
        return false;
    }

    if (throwable instanceof Nestable) {
        return true;
    } else if (throwable instanceof SQLException) {
        return true;
    } else if (throwable instanceof InvocationTargetException) {
        return true;
    } else if (isThrowableNested()) {
        return true;
    }

    Class<? extends Throwable> cls = throwable.getClass();
    synchronized (CAUSE_METHOD_NAMES) {
        for (int i = 0, isize = CAUSE_METHOD_NAMES.length; i < isize; i++) {
            try {
                Method method = cls.getMethod(CAUSE_METHOD_NAMES[i]);
                if (method != null && Throwable.class.isAssignableFrom(method.getReturnType())) {
                    return true;
                }
            } catch (NoSuchMethodException ignored) {
                // exception ignored
            } catch (SecurityException ignored) {
                // exception ignored
            }
        }
    }

    try {
        Field field = cls.getField("detail");
        if (field != null) {
            return true;
        }
    } catch (NoSuchFieldException ignored) {
        // exception ignored
    } catch (SecurityException ignored) {
        // exception ignored
    }

    return false;
}

From source file:net.easysmarthouse.service.scripting.ScriptDecoratorPointcut.java

@Override
public boolean matches(Method method, Class<?> type) {
    Class<?> returnType = method.getReturnType();
    if (returnType == Device.class) {
        return true;
    }/*from   ww  w . j a  va 2  s  . co  m*/

    if (Collection.class.isAssignableFrom(returnType)) {
        Type genericReturnType = method.getGenericReturnType();
        if (genericReturnType instanceof ParameterizedType) {
            ParameterizedType listType = (ParameterizedType) genericReturnType;
            Type[] actualTypeArgs = listType.getActualTypeArguments();

            if (actualTypeArgs != null && actualTypeArgs.length != 0) {
                Class<?> listClass = (Class<?>) actualTypeArgs[0];
                if (listClass == Device.class) {
                    return true;
                }
            }
        }
    }

    return false;
}

From source file:pl.bristleback.server.bristle.conf.resolver.action.client.ClientActionResolver.java

private ClientActionSender resolveActionResponse(Method actionMethod) {
    return responseStrategies.getStrategy(actionMethod.getReturnType());
}

From source file:com.taobao.rpc.doclet.RPCAPIInfoHelper.java

public static RPCAPIInfo getAPIInfo(String realPath, Method method) {
    RPCAPIInfo apiInfo = new RPCAPIInfo();

    ClassInfo classInfo = RPCAPIDocletUtil.getClassInfo(method.getDeclaringClass().getName());
    MethodInfo methodInfo = null;/*from   w w  w  .j  a  v a 2  s  . co m*/

    if (classInfo != null) {
        methodInfo = classInfo.getMethodInfo(method.getName());
    }

    if (methodInfo != null) {

        apiInfo.setComment(methodInfo.getComment());
    }

    Annotation[][] parameterAnnotations = method.getParameterAnnotations();

    Security securityAnnotation = method.getAnnotation(Security.class);
    ResourceMapping resourceMapping = method.getAnnotation(ResourceMapping.class);

    Object returnType = null;

    returnType = buildTypeStructure(method.getReturnType(), method.getGenericReturnType(), null);

    boolean checkCSRF = false;
    if (securityAnnotation != null) {
        checkCSRF = securityAnnotation.checkCSRF();
    }

    apiInfo.setPattern(realPath.replaceAll("///", "/"));
    apiInfo.setCheckCSRF(checkCSRF);
    apiInfo.setResponseMimes(StringUtils.arrayToDelimitedString(resourceMapping.produces(), ","));
    apiInfo.setHttpMethod(StringUtils.arrayToDelimitedString(resourceMapping.method(), ","));

    List<RPCAPIInfo.Parameter> parameters = new ArrayList<RPCAPIInfo.Parameter>();

    RPCAPIInfo.Parameter parameter = null;
    LocalVariableTableParameterNameDiscoverer nameDiscoverer = new LocalVariableTableParameterNameDiscoverer();
    String[] paramNames = nameDiscoverer.getParameterNames(method);
    int i = 0;

    Class<?>[] parameterTypes = method.getParameterTypes();

    Type[] genericParameterTypes = method.getGenericParameterTypes();

    Class<?> paramType = null;

    Type genericType;

    for (int k = 0; k < parameterTypes.length; k++) {

        paramType = parameterTypes[k];
        genericType = genericParameterTypes[k];

        Annotation[] pAnnotations = parameterAnnotations[i];

        if (HttpServletRequest.class.isAssignableFrom(paramType)
                || HttpServletResponse.class.isAssignableFrom(paramType)
                || ErrorContext.class.isAssignableFrom(paramType)) {
            continue;
        } // end if

        String realParamName = paramNames[k];

        if (pAnnotations.length == 0) {

            parameter = apiInfo.new Parameter();
            parameter.setName(realParamName);
            parameter.setType(buildTypeStructure(paramType, genericType, null));
            parameters.add(parameter);

            setParameterComment(parameter, realParamName, methodInfo);

            continue;
        } // end if

        for (Annotation annotation : pAnnotations) {
            parameter = apiInfo.new Parameter();
            setParameterComment(parameter, realParamName, methodInfo);

            if (annotation instanceof RequestParam) {
                RequestParam requestParam = (RequestParam) annotation;
                parameter.setName(requestParam.name());
                parameter.setType(buildTypeStructure(paramType, genericType, null));
                if (!StringUtil.isBlank(requestParam.defaultValue())) {
                    parameter.setDefaultValue(requestParam.defaultValue().trim());
                }
                parameters.add(parameter);
            } else if (annotation instanceof PathParam) {
                PathParam pathParam = (PathParam) annotation;
                parameter.setName(pathParam.name());
                parameter.setType(buildTypeStructure(paramType, genericType, null));
                if (!StringUtil.isBlank(pathParam.defaultValue())) {
                    parameter.setDefaultValue(pathParam.defaultValue().trim());
                }
                parameters.add(parameter);
            } else if (annotation instanceof JsonParam) {
                JsonParam pathParam = (JsonParam) annotation;
                parameter.setName(pathParam.value());
                parameter.setType(buildTypeStructure(paramType, genericType, null));
                parameters.add(parameter);
            } else if (annotation instanceof RequestParams) {
                parameter.setName(realParamName);
                parameter.setType(buildTypeStructure(paramType, genericType, null));
                parameters.add(parameter);
            } else if (annotation instanceof File) {
                File file = (File) annotation;
                parameter.setName(file.value());
                parameter.setType("");
                parameters.add(parameter);
            } // end if
        } // end for
        i++;
    } // end for
    apiInfo.setParmeters(parameters);
    apiInfo.setReturnType(returnType);
    return apiInfo;
}

From source file:JarClassLoader.java

public void invokeClass(String name, String[] args)
        throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException {
    Class c = loadClass(name);/*from w  w  w.  ja  va 2s  .  co  m*/
    Method m = c.getMethod("main", new Class[] { args.getClass() });
    m.setAccessible(true);
    int mods = m.getModifiers();
    if (m.getReturnType() != void.class || !Modifier.isStatic(mods) || !Modifier.isPublic(mods)) {
        throw new NoSuchMethodException("main");
    }
    try {
        m.invoke(null, new Object[] { args });
    } catch (IllegalAccessException e) {

    }
}

From source file:com.inspiresoftware.lib.dto.geda.interceptor.impl.TransferableUtils.java

private static Map<Occurrence, AdviceConfig> resolveConfiguration(final Method method,
        final Class<?> targetClass, final boolean trySpecific) {

    Method specificMethod = method;
    Transferable annotation = specificMethod.getAnnotation(Transferable.class);

    if (annotation == null && trySpecific) {

        specificMethod = AopUtils.getMostSpecificMethod(method, targetClass);
        annotation = specificMethod.getAnnotation(Transferable.class);

    }/*from   ww  w .  ja  v a2s.  c om*/

    if (annotation == null) {
        return Collections.emptyMap();
    }

    final Map<Occurrence, AdviceConfig> cfg = new HashMap<Occurrence, AdviceConfig>();
    resolveConfiguration(cfg, specificMethod.getName(), specificMethod.getParameterTypes(),
            specificMethod.getReturnType(), annotation);
    return cfg;

}

From source file:org.jdal.aop.DeclareMixinAdvisor.java

/**
 * Create a new advisor for this DeclareMix method.
 * @param method declare mix method/*from ww w.java2  s .c  om*/
 * @param aspectMetadata the aspect metadata
 * @param typePattern type pattern the introduction is restricted to
 */
public DeclareMixinAdvisor(Method method, Object aspect, String typePattern) {
    super(createAspect(method, aspect), method.getReturnType());
    this.typePatterClassFilter.setTypePattern(typePattern);
}