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

net.javols.coerce.collectorabsent.MapperAttempt Maven / Gradle / Ivy

There is a newer version: 1.3.0.3
Show newest version
package net.javols.coerce.collectorabsent;

import com.squareup.javapoet.CodeBlock;
import com.squareup.javapoet.ParameterSpec;
import net.javols.coerce.BasicInfo;
import net.javols.coerce.Coercion;
import net.javols.coerce.MapperClassValidator;
import net.javols.coerce.Skew;
import net.javols.coerce.either.Either;

import javax.lang.model.element.TypeElement;
import javax.lang.model.type.TypeMirror;
import java.util.function.Function;

class MapperAttempt {

  private final CodeBlock extractExpr;
  private final ParameterSpec constructorParam;
  private final Skew skew;
  private final TypeMirror testType;
  private final TypeElement mapperClass;

  MapperAttempt(TypeMirror testType, CodeBlock extractExpr, ParameterSpec constructorParam, Skew skew, TypeElement mapperClass) {
    this.testType = testType;
    this.extractExpr = extractExpr;
    this.constructorParam = constructorParam;
    this.skew = skew;
    this.mapperClass = mapperClass;
  }

  Either findCoercion(BasicInfo basicInfo) {
    return new MapperClassValidator(basicInfo::failure, basicInfo.tool(), testType, mapperClass).checkReturnType()
        .map(Function.identity(), mapExpr ->
            new Coercion(mapExpr, extractExpr, skew, constructorParam));
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy