net.jbock.convert.match.ListMatcher 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.convert.match;
import net.jbock.annotated.Item;
import net.jbock.common.SafeElements;
import net.jbock.common.TypeTool;
import javax.lang.model.type.TypeMirror;
import java.util.Optional;
import static net.jbock.model.Multiplicity.REPEATABLE;
final class ListMatcher extends Matcher {
private final SafeElements elements;
private final TypeTool tool;
ListMatcher(
TypeTool tool) {
this.elements = tool.elements();
this.tool = tool;
}
@Override
Optional> tryMatch(M item) {
if (item.isParameter()) {
return Optional.empty(); // Not a VarargsParameter, so definitely not repeatable.
}
TypeMirror returnType = item.returnType();
return elements.getTypeElement("java.util.List")
.flatMap(utilList -> tool.getSingleTypeArgument(returnType, utilList))
.map(typeArg -> Match.create(typeArg, REPEATABLE, item));
}
}