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:com.glaf.core.util.ReflectUtils.java

/**
 * get method desc. "(I)I", "()V", "(Ljava/lang/String;Z)V"
 * /*from   w w  w .  java2s .  c o m*/
 * @param m
 *            method.
 * @return desc.
 */
public static String getDescWithoutMethodName(Method m) {
    StringBuilder ret = new StringBuilder();
    ret.append('(');
    Class<?>[] parameterTypes = m.getParameterTypes();
    for (int i = 0; i < parameterTypes.length; i++)
        ret.append(getDesc(parameterTypes[i]));
    ret.append(')').append(getDesc(m.getReturnType()));
    return ret.toString();
}

From source file:com.glaf.core.util.ReflectUtils.java

/**
 * get method desc. int do(int arg1) => "do(I)I" void do(String arg1,boolean
 * arg2) => "do(Ljava/lang/String;Z)V"
 * //www.ja va2s .c o m
 * @param m
 *            method.
 * @return desc.
 */
public static String getDesc(final Method m) {
    StringBuilder ret = new StringBuilder(m.getName()).append('(');
    Class<?>[] parameterTypes = m.getParameterTypes();
    for (int i = 0; i < parameterTypes.length; i++)
        ret.append(getDesc(parameterTypes[i]));
    ret.append(')').append(getDesc(m.getReturnType()));
    return ret.toString();
}

From source file:de.vandermeer.asciiparagraph.AsciiParagraph.java

/**
  * Adds text to the paragraph.//from  w  w w .j  av  a 2s  .  c o m
  * The method uses reflection to look for a method render without any parameters.
  * If found, the result of this method will be used as text.
  * Otherwise the object's toString method is used. 
  * @param text text to be added to the paragraph
  * @return self to allow chaining
  * throws NullPointerException if the argument was null
  * throws IllegalArgumentException if the argument was blank
  */
 public AsciiParagraph addText(Object text) {
     Validate.notNull(text);

     if (text instanceof String) {
         return this.addText((String) text);
     }

     try {
         Class<? extends Object> clazz = text.getClass();
         Method method = clazz.getMethod("render", new Class[0]);
         Class<?> returnType = method.getReturnType();
         if (returnType.isAssignableFrom(String.class)) {
             String append = (String) method.invoke(text);
             return this.addText(append);
         }
     } catch (Exception ignore) {
         //         ignore.printStackTrace();
     }

     return this.addText(text.toString());
 }

From source file:org.jsonschema2pojo.integration.MediaIT.java

@Test
public void shouldCreateStringSetterWithoutEncoding() throws SecurityException, NoSuchMethodException {
    Method setter = classWithMediaProperties.getDeclaredMethod("setUnencoded", String.class);

    assertThat("unencoded setter has return type void", setter.getReturnType(), equalToType(Void.TYPE));
}

From source file:net.firejack.platform.core.validation.MatchProcessor.java

@Override
public List<ValidationMessage> validate(Method readMethod, String property, Object value, ValidationMode mode)
        throws RuleValidationException {
    Match matchAnnotation = readMethod.getAnnotation(Match.class);
    if (matchAnnotation != null && StringUtils.isNotBlank(matchAnnotation.expression())) {
        Class<?> returnType = readMethod.getReturnType();
        if (returnType == String.class) {
            Pattern pattern = getCachedPatterns().get(matchAnnotation.expression());
            if (pattern == null) {
                try {
                    pattern = Pattern.compile(matchAnnotation.expression());
                    getCachedPatterns().put(matchAnnotation.expression(), pattern);
                } catch (PatternSyntaxException e) {
                    logger.error(e.getMessage(), e);
                    throw new ImproperValidationArgumentException(
                            "Pattern expression should have correct syntax.");
                }/*from w  w  w. jav a  2 s  .  c om*/
            }
            List<ValidationMessage> messages = null;
            if (value != null) {
                String sValue = (String) value;
                if (StringUtils.isNotBlank(sValue) && !pattern.matcher(sValue).matches()) {
                    messages = new ArrayList<ValidationMessage>();
                    messages.add(new ValidationMessage(property, matchAnnotation.msgKey(),
                            matchAnnotation.parameterName()));
                }
            }
            return messages;
        }

    }
    return null;
}

From source file:org.jsonschema2pojo.integration.MediaIT.java

@Test
public void shouldCreateByteArrayGetter() throws SecurityException, NoSuchMethodException {
    Method getter = classWithMediaProperties.getDeclaredMethod("getMinimalBinary");

    assertThat("the minimal binary getter has return type byte[]", getter.getReturnType(),
            equalToType(BYTE_ARRAY));//from ww  w.  j ava  2 s  .  c  o m
}

From source file:net.sf.jasperreports.export.PropertiesDefaultsConfigurationFactory.java

/**
 * //from   w  w  w. j av a 2  s. com
 */
protected Object getPropertyValue(Method method) {
    Object value = null;
    ExporterProperty exporterProperty = method.getAnnotation(ExporterProperty.class);
    if (exporterProperty != null) {
        value = getPropertyValue(jasperReportsContext, exporterProperty, method.getReturnType());
    }
    return value;
}

From source file:com.snaplogic.snaps.uniteller.BaseService.java

/**
 * @param UFSResponseObj//from w w  w . ja v a 2  s  .c  o m
 * @return Map
 * @throws IllegalAccessException
 * @throws IllegalArgumentException
 * @throws InvocationTargetException
 */
public Map<String, Object> processResponseObj(Object UFSResponseObj)
        throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    Map<String, Object> map = new HashMap<String, Object>();
    /* Preparing the map to write the values to output */
    if (UFSResponseObj != null) {
        Class<? extends Object> UFSResponse = UFSResponseObj.getClass();
        for (Method method : findGetters(UFSResponse)) {
            if (method.getReturnType().isPrimitive() || method.getReturnType().isAssignableFrom(String.class)
                    || method.getReturnType().isAssignableFrom(Calendar.class)) {
                map.put(method.getName().substring(3), method.invoke(UFSResponseObj));
            } else {
                log.debug(method.toGenericString());
                map.put(method.getName().substring(3), processNestedResponseObj(method.invoke(UFSResponseObj)));
            }
        }
    }
    return map;
}

From source file:org.jsonschema2pojo.integration.MediaIT.java

@Test
public void shouldCreateByteArrayGetterWithAnyEncoding() throws SecurityException, NoSuchMethodException {
    Method getter = classWithMediaProperties.getDeclaredMethod("getAnyBinaryEncoding");

    assertThat("any binary encoding getter has return type byte[]", getter.getReturnType(),
            equalToType(BYTE_ARRAY));/*from ww  w  .  j ava 2 s.c om*/
}

From source file:org.jsonschema2pojo.integration.MediaIT.java

@Test
public void shouldCreateByteArraySetter() throws SecurityException, NoSuchMethodException {
    Method setter = classWithMediaProperties.getDeclaredMethod("setMinimalBinary", BYTE_ARRAY);

    assertThat("the minimal binary setter has return type void", setter.getReturnType(),
            equalToType(Void.TYPE));
}