net.jbock.context.UnixClustering 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.context;
import com.squareup.javapoet.TypeName;
import net.jbock.annotated.AnnotatedOption;
import net.jbock.convert.Mapping;
import net.jbock.processor.SourceElement;
import javax.inject.Inject;
import java.util.List;
import static com.squareup.javapoet.TypeName.VOID;
import static java.util.stream.Collectors.toList;
import static net.jbock.common.Constants.STRING;
@ContextScope
public class UnixClustering {
private final boolean unixClusteringSupported;
@Inject
UnixClustering(
SourceElement sourceElement,
List> options) {
this.unixClusteringSupported = sourceElement.unixClustering()
&& hasEnoughUnixNames(options);
}
private static boolean hasEnoughUnixNames(List> options) {
List> unixOptions = options.stream()
.filter(option -> option.sourceMethod().hasUnixName())
.collect(toList());
return unixOptions.size() >= 2 && unixOptions.stream().anyMatch(Mapping::modeFlag);
}
boolean unixClusteringSupported() {
return unixClusteringSupported;
}
TypeName readMethodReturnType() {
return unixClusteringSupported ? STRING : VOID;
}
}