Search in sources :

Example 1 with ContainerKind

use of spoon.reflect.meta.ContainerKind in project spoon by INRIA.

the class MetamodelProperty method getItemValueType.

private static CtTypeReference<?> getItemValueType(CtTypeReference<?> valueType) {
    ContainerKind valueContainerType = containerKindOf(valueType.getActualClass());
    if (valueContainerType == ContainerKind.SINGLE) {
        return null;
    }
    CtTypeReference<?> itemValueType;
    if (valueContainerType == ContainerKind.MAP) {
        if (String.class.getName().equals(valueType.getActualTypeArguments().get(0).getQualifiedName()) == false) {
            throw new SpoonException("Unexpected container of type: " + valueType.toString());
        }
        itemValueType = valueType.getActualTypeArguments().get(1);
    } else {
        // List or Set
        itemValueType = valueType.getActualTypeArguments().get(0);
    }
    if (itemValueType instanceof CtTypeParameterReference) {
        itemValueType = ((CtTypeParameterReference) itemValueType).getBoundingType();
        if (itemValueType == null) {
            itemValueType = valueType.getFactory().Type().OBJECT;
        }
    }
    return itemValueType;
}
Also used : CtTypeParameterReference(spoon.reflect.reference.CtTypeParameterReference) SpoonException(spoon.SpoonException) ContainerKind(spoon.reflect.meta.ContainerKind)

Aggregations

SpoonException (spoon.SpoonException)1 ContainerKind (spoon.reflect.meta.ContainerKind)1 CtTypeParameterReference (spoon.reflect.reference.CtTypeParameterReference)1