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_Frames.java

@Test
public void test_Doc() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    for (Method m : A7_Frames.class.getMethods()) {
        if (m.getReturnType() == TA_Frame.class) {
            Object descr = ((TA_Frame) m.invoke("")).getDescription();
            StrBuilder doc = ((TA_Frame) 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();
        }/* w w  w.j  a  va  2s . com*/
    }
}

From source file:com.free.exception.ExceptionHelper.java

/**
 * <p>/*from   w w  w  . j a  va  2  s.c om*/
 * Finds a <code>Throwable</code> by method name.
 * </p>
 * 
 * @param throwable
 *          the exception to examine
 * @param methodName
 *          the name of the method to find and invoke
 * @return the wrapped exception, or <code>null</code> if not found
 */
private static Throwable getCauseUsingMethodName(Throwable throwable, String methodName) {
    Method method = null;
    try {
        method = throwable.getClass().getMethod(methodName, (Class[]) null);
    } catch (NoSuchMethodException ignored) {
    } catch (SecurityException ignored) {
    }

    if (method != null && Throwable.class.isAssignableFrom(method.getReturnType())) {
        try {
            return (Throwable) method.invoke(throwable, EMPTY_OBJECT_ARRAY);
        } catch (IllegalAccessException ignored) {
        } catch (IllegalArgumentException ignored) {
        } catch (InvocationTargetException ignored) {
        }
    }
    return null;
}

From source file:com.nridge.core.base.field.data.DataBeanBag.java

private static DataField reflectMethod(Object anObject, BeanField aBeanField, Method aMethod)
        throws NSException, IllegalAccessException, InvocationTargetException {
    String fieldValue;/*from w ww  . j a va 2  s . c o m*/
    DataField dataField;
    com.nridge.core.base.field.Field.Type fieldType;

    if (anObject == null)
        throw new NSException("Object is null");
    String fieldName = aBeanField.name();
    if (StringUtils.isEmpty(fieldName))
        throw new NSException("Field name not identified in annotation.");

    String fieldTitle = aBeanField.title();
    if (StringUtils.isEmpty(fieldTitle))
        fieldTitle = com.nridge.core.base.field.Field.nameToTitle(fieldName);
    String fieldTypeString = aBeanField.type();
    if (StringUtils.isEmpty(fieldTypeString)) {
        Class<?> methodReturnType = aMethod.getReturnType();
        if ((StringUtils.endsWith(methodReturnType.getName(), "Integer"))
                || (StringUtils.endsWith(methodReturnType.getName(), "int"))) {
            fieldType = com.nridge.core.base.field.Field.Type.Integer;
            fieldValue = aMethod.invoke(anObject).toString();
            dataField = new DataField(fieldType, fieldName, fieldTitle, fieldValue);
        } else if ((StringUtils.endsWith(methodReturnType.getName(), "Float"))
                || (StringUtils.endsWith(methodReturnType.getName(), "float"))) {
            fieldType = com.nridge.core.base.field.Field.Type.Float;
            fieldValue = aMethod.invoke(anObject).toString();
            dataField = new DataField(fieldType, fieldName, fieldTitle, fieldValue);
        } else if ((StringUtils.endsWith(methodReturnType.getName(), "Double"))
                || (StringUtils.endsWith(methodReturnType.getName(), "double"))) {
            fieldType = com.nridge.core.base.field.Field.Type.Double;
            fieldValue = aMethod.invoke(anObject).toString();
            dataField = new DataField(fieldType, fieldName, fieldTitle, fieldValue);
        } else if ((StringUtils.endsWith(methodReturnType.getName(), "Boolean"))
                || (StringUtils.endsWith(methodReturnType.getName(), "boolean"))) {
            fieldType = com.nridge.core.base.field.Field.Type.Boolean;
            fieldValue = aMethod.invoke(anObject).toString();
            dataField = new DataField(fieldType, fieldName, fieldTitle, fieldValue);
        } else if (StringUtils.endsWith(methodReturnType.getName(), "Date")) {
            fieldType = com.nridge.core.base.field.Field.Type.Date;
            Date fieldDate = (Date) aMethod.invoke(anObject);
            fieldValue = com.nridge.core.base.field.Field.dateValueFormatted(fieldDate, null);
            dataField = new DataField(fieldType, fieldName, fieldTitle, fieldValue);
        } else {
            fieldType = com.nridge.core.base.field.Field.Type.Text;
            Object methodReturnObject = aMethod.invoke(anObject);
            if (methodReturnObject instanceof String[]) {
                String[] fieldValues = (String[]) methodReturnObject;
                dataField = new DataField(fieldType, fieldName, fieldTitle);
                dataField.setMultiValueFlag(true);
                dataField.setValues(fieldValues);
            } else if (methodReturnObject instanceof Collection) {
                ArrayList<String> fieldValues = (ArrayList<String>) methodReturnObject;
                dataField = new DataField(fieldType, fieldName, fieldTitle);
                dataField.setMultiValueFlag(true);
                dataField.setValues(fieldValues);
            } else {
                fieldValue = aMethod.invoke(anObject).toString();
                dataField = new DataField(fieldType, fieldName, fieldTitle, fieldValue);
            }
        }
    } else {
        fieldType = com.nridge.core.base.field.Field.stringToType(fieldTypeString);
        Object methodReturnObject = aMethod.invoke(anObject);
        if (methodReturnObject instanceof String[]) {
            String[] fieldValues = (String[]) methodReturnObject;
            dataField = new DataField(fieldType, fieldName, fieldTitle);
            dataField.setMultiValueFlag(true);
            dataField.setValues(fieldValues);
        } else if (methodReturnObject instanceof Collection) {
            ArrayList<String> fieldValues = (ArrayList<String>) methodReturnObject;
            dataField = new DataField(fieldType, fieldName, fieldTitle);
            dataField.setMultiValueFlag(true);
            dataField.setValues(fieldValues);
        } else {
            fieldValue = methodReturnObject.toString();
            dataField = new DataField(fieldType, fieldName, fieldTitle, fieldValue);
        }
    }

    return dataField;
}

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

@Test
public void test_Doc() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    for (Method m : A7_Checklists.class.getMethods()) {
        if (m.getReturnType() == TA_Checklist.class) {
            Object descr = ((TA_Checklist) m.invoke("")).getDescription();
            StrBuilder doc = ((TA_Checklist) 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();
        }//ww  w  . j a  va 2  s.co m
    }
}

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

@Test
public void test_Doc() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    for (Method m : A7_Frames_Doc.class.getMethods()) {
        if (m.getReturnType() == TA_Frame.class) {
            Object descr = ((TA_Frame) m.invoke("")).getDescription();
            StrBuilder doc = ((TA_Frame) 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  w  w .  ja  v  a  2  s.  c  o m
    }
}

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

@Test
public void test_Doc() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    for (Method m : U8_Checklists.class.getMethods()) {
        if (m.getReturnType() == TA_Checklist.class) {
            Object descr = ((TA_Checklist) m.invoke("")).getDescription();
            StrBuilder doc = ((TA_Checklist) 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();
        }/* www .  j  ava 2  s .c o  m*/
    }
}

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

@Test
public void test_Doc() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    for (Method m : A7_CheckedItems.class.getMethods()) {
        if (m.getReturnType() == TA_CheckedItem.class) {
            Object descr = ((TA_CheckedItem) m.invoke("")).getDescription();
            StrBuilder doc = ((TA_CheckedItem) 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  w w.  j av a  2 s  .  c om
    }
}

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

@Test
public void test_Doc() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    for (Method m : A7_ItemizeLists.class.getMethods()) {
        if (m.getReturnType() == TA_ItemizeList.class) {
            Object descr = ((TA_ItemizeList) m.invoke("")).getDescription();
            StrBuilder doc = ((TA_ItemizeList) 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  2  s. c  o m
    }
}

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

@Test
public void test_Doc() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    for (Method m : A7_Lines_String.class.getMethods()) {
        if (m.getReturnType() == TA_Line_String.class) {
            Object descr = ((TA_Line_String) m.invoke("")).getDescription();
            StrBuilder doc = ((TA_Line_String) 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();
        }/*ww w  .j  av  a2s  . co m*/
    }
}

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

@Test
public void test_Doc() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    for (Method m : U8_CheckedItems.class.getMethods()) {
        if (m.getReturnType() == TA_CheckedItem.class) {
            Object descr = ((TA_CheckedItem) m.invoke("")).getDescription();
            StrBuilder doc = ((TA_CheckedItem) 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 w  w. j  ava2  s  .  c o m*/
    }
}