@@ -75,9 +75,8 @@
Loading
75 75
    val To = weakTypeOf[To]
76 76
77 77
    val srcName = freshTermName(From)
78 -
    val srcPrefixTree = Ident(TermName(srcName.decodedName.toString))
79 78
80 -
    expandTransformerTree(srcPrefixTree, config)(From, To) match {
79 +
    genTransformerTree(srcName, config)(From, To) match {
81 80
82 81
      case Right(transformerTree) =>
83 82
        config.wrapperType match {
@@ -113,12 +112,25 @@
Loading
113 112
    }
114 113
  }
115 114
115 +
  def genTransformerTree(
116 +
      srcName: TermName,
117 +
      config: TransformerConfig
118 +
  )(From: Type, To: Type): Either[Seq[DerivationError], Tree] = {
119 +
    val srcPrefixTree = Ident(TermName(srcName.decodedName.toString))
120 +
121 +
    resolveTransformerBody(srcPrefixTree, config)(From, To).map {
122 +
      case TransformerBodyTree(tree, false) if config.wrapperType.isDefined =>
123 +
        q"${config.wrapperSupportInstance}.pure[$To]($tree)"
124 +
      case TransformerBodyTree(tree, _) => tree
125 +
    }
126 +
  }
127 +
116 128
  def expandTransformerTree(
117 129
      srcPrefixTree: Tree,
118 130
      config: TransformerConfig
119 131
  )(From: Type, To: Type): Either[Seq[DerivationError], Tree] = {
120 132
121 -
    resolveImplicitTransformer(srcPrefixTree, config)(From, To)
133 +
    resolveImplicitTransformer(config)(From, To)
122 134
      .map(localImplicitTree => Right(localImplicitTree.callTransform(srcPrefixTree)))
123 135
      .getOrElse {
124 136
        deriveTransformerTree(srcPrefixTree, config)(From, To)
@@ -732,44 +744,44 @@
Loading
732 744
      srcPrefixTree: Tree,
733 745
      config: TransformerConfig
734 746
  )(From: Type, To: Type): Either[Seq[DerivationError], TransformerBodyTree] = {
747 +
    resolveTransformerBody(srcPrefixTree, config.rec)(From, To)
748 +
  }
735 749
736 -
    val recConfig = config.rec
737 -
    val recConfigNoWrapper = recConfig.copy(wrapperType = None)
738 -
750 +
  def resolveTransformerBody(
751 +
      srcPrefixTree: Tree,
752 +
      config: TransformerConfig
753 +
  )(From: Type, To: Type): Either[Seq[DerivationError], TransformerBodyTree] = {
739 754
    if (config.wrapperType.isDefined) {
740 -
      val implicitTransformerF = resolveImplicitTransformer(srcPrefixTree, recConfig)(From, To)
741 -
      val implicitTransformer = resolveImplicitTransformer(srcPrefixTree, recConfigNoWrapper)(From, To)
755 +
      val implicitTransformerF = resolveImplicitTransformer(config)(From, To)
756 +
      val implicitTransformer = findLocalImplicitTransformer(From, To, None)
742 757
743 758
      (implicitTransformerF, implicitTransformer) match {
744 759
        case (Some(localImplicitTreeF), Some(localImplicitTree)) =>
745 760
          c.abort(
746 761
            c.enclosingPosition,
747 762
            s"""Ambiguous implicits while resolving Chimney recursive transformation:
748 -
              |
749 -
              |TransformerF[${config.wrapperType.get}, $From, $To]: $localImplicitTreeF
750 -
              |Transformer[$From, $To]: $localImplicitTree
751 -
              |
752 -
              |Please eliminate ambiguity from implicit scope or use withFieldComputed/withFieldComputedF to decide which one should be used
753 -
              |""".stripMargin
763 +
               |
764 +
               |TransformerF[${config.wrapperType.get}, $From, $To]: $localImplicitTreeF
765 +
               |Transformer[$From, $To]: $localImplicitTree
766 +
               |
767 +
               |Please eliminate ambiguity from implicit scope or use withFieldComputed/withFieldComputedF to decide which one should be used
768 +
               |""".stripMargin
754 769
          )
755 770
        case (Some(localImplicitTreeF), None) =>
756 771
          Right(TransformerBodyTree(localImplicitTreeF.callTransform(srcPrefixTree), isWrapped = true))
757 772
        case (None, Some(localImplicitTree)) =>
758 773
          Right(TransformerBodyTree(localImplicitTree.callTransform(srcPrefixTree), isWrapped = false))
759 774
        case (None, None) =>
760 -
          deriveTransformerTree(srcPrefixTree, recConfig)(From, To)
775 +
          deriveTransformerTree(srcPrefixTree, config)(From, To)
761 776
            .map(tree => TransformerBodyTree(tree, isWrapped = true))
762 777
      }
763 778
    } else {
764 -
      expandTransformerTree(srcPrefixTree, recConfig)(From, To)
779 +
      expandTransformerTree(srcPrefixTree, config)(From, To)
765 780
        .map(tree => TransformerBodyTree(tree, isWrapped = false))
766 781
    }
767 782
  }
768 783
769 -
  def resolveImplicitTransformer(
770 -
      srcPrefixTree: Tree,
771 -
      config: TransformerConfig
772 -
  )(From: Type, To: Type): Option[Tree] = {
784 +
  def resolveImplicitTransformer(config: TransformerConfig)(From: Type, To: Type): Option[Tree] = {
773 785
    if (config.definitionScope.contains((From, To))) {
774 786
      None
775 787
    } else {
Files Coverage
chimney/src/main/scala/io/scalaland/chimney 99.55%
Project Totals (25 files) 99.55%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading