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

net.jbock.annotated.Parameter Maven / Gradle / Ivy

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

import net.jbock.common.SnakeName;

import javax.lang.model.element.ExecutableElement;
import java.lang.annotation.Annotation;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.function.Supplier;

import static net.jbock.common.Constants.optionalString;
import static net.jbock.common.Suppliers.memoize;

public final class Parameter extends Item {

    private final Supplier paramLabel = memoize(() -> parameterParamLabel()
            .orElseGet(() -> SnakeName.create(simpleName())
                    .snake('_')
                    .toUpperCase(Locale.ROOT)));

    private final net.jbock.Parameter parameter;

    Parameter(
            ExecutableElement method,
            net.jbock.Parameter parameter,
            String enumName) {
        super(method, enumName);
        this.parameter = parameter;
    }

    @Override
    public Optional descriptionKey() {
        return optionalString(parameter.descriptionKey());
    }

    @Override
    public List description() {
        return List.of(parameter.description());
    }

    @Override
    Annotation annotation() {
        return parameter;
    }

    @Override
    public String paramLabel() {
        return paramLabel.get();
    }

    @Override
    public boolean isParameter() {
        return true;
    }

    @Override
    public boolean isVarargsParameter() {
        return false;
    }

    public int index() {
        return parameter.index();
    }

    private Optional parameterParamLabel() {
        return optionalString(parameter.paramLabel());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy