All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.jbock.context.OptEnum Maven / Gradle / Ivy

There is a newer version: 5.18
Show newest version
package net.jbock.context;

import com.squareup.javapoet.TypeSpec;
import net.jbock.annotated.AnnotatedOption;
import net.jbock.common.EnumName;
import net.jbock.convert.Mapping;
import net.jbock.processor.SourceElement;

import javax.inject.Inject;
import java.util.List;

import static javax.lang.model.element.Modifier.PRIVATE;

/**
 * Defines the inner class *Parser.Opt.
 *
 * @see GeneratedClass
 */
@ContextScope
public class OptEnum {

    private final List> options;
    private final SourceElement sourceElement;

    @Inject
    OptEnum(List> options,
            SourceElement sourceElement) {
        this.options = options;
        this.sourceElement = sourceElement;
    }

    TypeSpec define() {
        TypeSpec.Builder spec = TypeSpec.enumBuilder(sourceElement.optionEnumType());
        for (Mapping option : options) {
            EnumName enumName = option.enumName();
            String enumConstant = enumName.enumConstant();
            spec.addEnumConstant(enumConstant);
        }
        return spec.addModifiers(PRIVATE)
                .build();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy