net.jbock.validate.OptionValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jbock-compiler Show documentation
Show all versions of jbock-compiler Show documentation
jbock annotation processor
package net.jbock.validate;
import io.jbock.simple.Inject;
import io.jbock.util.Either;
import net.jbock.annotated.Items;
import net.jbock.annotated.Option;
import net.jbock.common.ValidationFailure;
import net.jbock.convert.Mapping;
import net.jbock.convert.MappingFinder;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import static io.jbock.util.Either.left;
import static io.jbock.util.Either.right;
import static io.jbock.util.Eithers.allFailures;
import static io.jbock.util.Eithers.toOptionalList;
import static java.lang.Character.isWhitespace;
import static javax.lang.model.type.TypeKind.BOOLEAN;
final class OptionValidator {
private final MappingFinder mappingFinder;
@Inject
OptionValidator(MappingFinder mappingFinder) {
this.mappingFinder = mappingFinder;
}
Either, List>> wrapOptions(
Items items) {
return items.namedOptions().stream()
.map(this::checkOptionNames)
.collect(allFailures())
.filter(this::validateUniqueOptionNames)
.flatMap(sourceOptions -> sourceOptions.stream()
.map(this::wrapOption)
.collect(allFailures()));
}
private Either> wrapOption(
Option option) {
return checkNullary(option)
.map(mappingFinder::findNullaryMapping)
.orElseGet(() -> mappingFinder.findMapping(option));
}
private Optional