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

scala.meta.internal.tokens.branch.scala Maven / Gradle / Ivy

Go to download

Bag of private and public helpers used in scala.meta's APIs and implementations

The newest version!
package scala.meta.internal.tokens

import scala.annotation.StaticAnnotation
import scala.language.experimental.macros
import scala.reflect.macros.whitebox.Context

class branch extends StaticAnnotation {
  def macroTransform(annottees: Any*): Any = macro BranchNamerMacros.impl
}

class BranchNamerMacros(val c: Context) extends TokenNamerMacroHelpers {
  import c.universe._

  def impl(annottees: Tree*): Tree = annottees.transformAnnottees(new ImplTransformer {
    override def transformTrait(cdef: ClassDef, mdef: ModuleDef): List[ImplDef] =
      transformImpl(cdef, mdef)
    override def transformClass(cdef: ClassDef, mdef: ModuleDef): List[ImplDef] =
      transformImpl(cdef, mdef)

    private def transformImpl(cdef: ClassDef, mdef: ModuleDef): List[ImplDef] = {
      val ClassDef(mods, name, tparams, template) = cdef
      val mods1 = mods
        .mapAnnotations(_ :+ q"new $TokenMetadataModule.branch" :+ q"new $AdtPackage.branch")
      val cdef1 = ClassDef(mods1, name, tparams, template)

      val ModuleDef(mmods, mname, Template(mparents, mself, mstats)) = mdef
      val mstats1 = mstats ++ getClassifierBoilerplate(cdef, true)
      val mdef1 = ModuleDef(mmods, mname, Template(mparents, mself, mstats1))

      List(cdef1, mdef1)
    }
  })
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy