Search in sources :

Example 1 with ThriftContainer

use of net.morimekta.providence.util.ThriftContainer in project providence by morimekta.

the class JField method getProvider.

public String getProvider() throws GeneratorException {
    String container = field.getAnnotationValue("container");
    String containerProvider = "provider";
    if (container != null) {
        ThriftContainer containerType = ThriftContainer.forName(container);
        switch(containerType) {
            case DEFAULT:
                containerProvider = "provider";
                break;
            case SORTED:
                containerProvider = "sortedProvider";
                break;
            case ORDERED:
                containerProvider = "orderedProvider";
                break;
            default:
                break;
        }
    }
    switch(field.getType()) {
        case ENUM:
        case MESSAGE:
            return String.format(Locale.US, "%s.provider()", helper.getFieldType(field.getDescriptor()));
        case LIST:
            PList<?> lType = (PList<?>) field.getDescriptor();
            return String.format(Locale.US, "%s.provider(%s)", PList.class.getName(), helper.getProviderName(lType.itemDescriptor()));
        case SET:
            PSet<?> sType = (PSet<?>) field.getDescriptor();
            return String.format(Locale.US, "%s.%s(%s)", PSet.class.getName(), containerProvider, helper.getProviderName(sType.itemDescriptor()));
        case MAP:
            PMap<?, ?> mType = (PMap<?, ?>) field.getDescriptor();
            return String.format(Locale.US, "%s.%s(%s,%s)", PMap.class.getName(), containerProvider, helper.getProviderName(mType.keyDescriptor()), helper.getProviderName(mType.itemDescriptor()));
        default:
            if (!(field.getDescriptor() instanceof PPrimitive)) {
                throw new IllegalArgumentException("Unhandled type group " + field.getType());
            }
            return String.format(Locale.US, "%s.%s.provider()", PPrimitive.class.getName(), field.getDescriptor().getName().toUpperCase(Locale.US));
    }
}
Also used : ThriftContainer(net.morimekta.providence.util.ThriftContainer) PList(net.morimekta.providence.descriptor.PList) PSet(net.morimekta.providence.descriptor.PSet) PMap(net.morimekta.providence.descriptor.PMap) PPrimitive(net.morimekta.providence.descriptor.PPrimitive)

Aggregations

PList (net.morimekta.providence.descriptor.PList)1 PMap (net.morimekta.providence.descriptor.PMap)1 PPrimitive (net.morimekta.providence.descriptor.PPrimitive)1 PSet (net.morimekta.providence.descriptor.PSet)1 ThriftContainer (net.morimekta.providence.util.ThriftContainer)1