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

net.jbock.writing.OptionStatesMethod Maven / Gradle / Ivy

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

import io.jbock.javapoet.ClassName;
import io.jbock.javapoet.CodeBlock;
import io.jbock.javapoet.MethodSpec;
import io.jbock.javapoet.ParameterSpec;
import io.jbock.simple.Inject;
import net.jbock.annotated.Option;
import net.jbock.convert.Mapping;
import net.jbock.parse.OptionState;
import net.jbock.parse.OptionStateModeFlag;
import net.jbock.parse.OptionStateNonRepeatable;
import net.jbock.parse.OptionStateRepeatable;

import java.util.EnumMap;
import java.util.Map;
import java.util.function.Supplier;

import static javax.lang.model.element.Modifier.PRIVATE;
import static net.jbock.common.Constants.mapOf;
import static net.jbock.common.Suppliers.memoize;

final class OptionStatesMethod extends HasCommandRepresentation {

    @Inject
    OptionStatesMethod(CommandRepresentation commandRepresentation) {
        super(commandRepresentation);
    }

    private final Supplier define = memoize(() -> {
        ParameterSpec result = ParameterSpec.builder(
                mapOf(optType(), ClassName.get(OptionState.class)), "result").build();
        CodeBlock.Builder code = CodeBlock.builder();
        if (namedOptions().isEmpty()) {
            code.addStatement("$T $N = $T.of()", result.type, result, Map.class);
        } else {
            code.addStatement("$T $N = new $T<>($T.class)", result.type, result, EnumMap.class, sourceElement().optionEnumType());
        }
        for (Mapping




© 2015 - 2024 Weber Informatics LLC | Privacy Policy