def impl[T: c.WeakTypeTag]()

in cassovary-collections/src/main/scala/com/twitter/cassovary/collections/CSeq.scala [109:155]


    def impl[T: c.WeakTypeTag](c: scala.reflect.macros.blackbox.Context): c.Expr[CSeqFactory[T]] = {
      import c.universe._

      val sym = c.weakTypeOf[T]
      val className = internal.reificationSupport.freshTypeName("CSeq" + sym.toString + "$")
      val arrayWrapperName = internal.reificationSupport.freshTypeName("CSeq" + sym.toString +
        "ArrayWrapper$")
      val factoryClassName = internal.reificationSupport.freshTypeName("CFactory" + sym.toString
        + "$")

      val clazz = q"""
        class $className(underlying: CSeq[$sym], from: Int, until: Int)
            extends com.twitter.cassovary.collections.CSeq[$sym] {
          override def apply(idx: Int) = {
            if (idx >= length) {
              throw new IndexOutOfBoundsException(idx.toString)
            } else {
              underlying.apply(from + idx)
            }
          }

          override def length: Int = until - from
        }

        class $arrayWrapperName(underlying: Array[$sym])
            extends com.twitter.cassovary.collections.CSeq[$sym] {
          override def apply(idx: Int) = underlying.apply(idx)

          override def length = underlying.length
        }

        class $factoryClassName
            extends com.twitter.cassovary.collections.CSeqFactory[$sym] {
          override def ofDim(n: Int): CSeq[$sym] = new $arrayWrapperName(Array.ofDim[$sym](n))

          override def empty: CSeq[$sym] = new $arrayWrapperName(Array[$sym]())

          override def fromCSeq(arr: CSeq[$sym], from: Int, until: Int): CSeq[$sym] =
            new $className(arr, from, until)

          override def fromArray(arr: Array[$sym]): CSeq[$sym] = new $arrayWrapperName(arr)
        }
        new $factoryClassName()
      """

      c.Expr[CSeqFactory[T]](clazz)
    }