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

net.jbock.coerce.matching.matcher.ListMatcher Maven / Gradle / Ivy

There is a newer version: 4.4.000
Show newest version
package net.jbock.coerce.matching.matcher;

import com.squareup.javapoet.CodeBlock;
import com.squareup.javapoet.ParameterSpec;
import net.jbock.coerce.Skew;
import net.jbock.coerce.matching.UnwrapSuccess;
import net.jbock.compiler.ParameterContext;
import net.jbock.either.Either;

import javax.inject.Inject;
import java.util.List;
import java.util.stream.Collectors;

public class ListMatcher extends Matcher {

  @Inject
  ListMatcher(ParameterContext parameterContext) {
    super(parameterContext);
  }

  @Override
  public Either tryUnwrapReturnType() {
    ParameterSpec constructorParam = constructorParam(returnType());
    return tool().getSingleTypeArgument(returnType(), List.class.getCanonicalName())
        .map(wrapped -> UnwrapSuccess.create(wrapped, constructorParam, 1));
  }

  @Override
  public Skew skew() {
    return Skew.REPEATABLE;
  }

  @Override
  public CodeBlock tailExpr() {
    return CodeBlock.of(".collect($T.toList())", Collectors.class);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy