Example usage for java.lang.reflect Field getAnnotatedType

List of usage examples for java.lang.reflect Field getAnnotatedType

Introduction

In this page you can find the example usage for java.lang.reflect Field getAnnotatedType.

Prototype

public AnnotatedType getAnnotatedType() 

Source Link

Document

Returns an AnnotatedType object that represents the use of a type to specify the declared type of the field represented by this Field.

Usage

From source file:com.adobe.acs.commons.util.impl.ReflectionUtilTest.java

@Test
public void testTestClazz() {

    for (Field field : TestClazz.class.getDeclaredFields()) {

        Type type = field.getAnnotatedType().getType();
        switch (field.getName()) {
        case "stringList":
            assertTrue(isListType(type));
            assertSame(String.class, getClassOrGenericParam(type));
            assertTrue(isAssignableFrom(type, new ArrayList<String>().getClass()));
            break;
        case "integerSet":
            assertTrue(isSetType(type));
            assertSame(Integer.class, getClassOrGenericParam(type));
            assertTrue(isAssignableFrom(type, new HashSet<String>().getClass()));
            break;
        case "longCollection":
            assertTrue(isCollectionType(type));
            assertSame(Long.class, getClassOrGenericParam(type));
            assertTrue(isAssignableFrom(type, new ArrayList<Long>().getClass()));
            break;
        case "floatArray":
            assertTrue(isArray(type));/*from w  w  w . j  av a2s.  c  om*/
            assertSame(Float.class, getClassOrGenericParam(type));
            assertTrue(isAssignableFrom(type, Float[].class));
            break;
        case "atomicInteger":
            assertFalse(isListType(type));
            assertFalse(isSetType(type));
            assertFalse(isCollectionType(type));
            assertFalse(isArray(type));
            assertTrue(isAssignableFrom(type, Number.class));
            assertSame(AtomicInteger.class, getClassOrGenericParam(type));
            break;
        default:
            break;
        }

    }

}