
io.scalaland.enumz.internal.JavaEnumMacros.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of enumz_2.13 Show documentation
Show all versions of enumz_2.13 Show documentation
Common type class interface for various enums implementations
The newest version!
package io.scalaland.enumz.internal
import io.scalaland.enumz.Enum
import scala.reflect.macros.blackbox.*
private[enumz] object JavaEnumMacros {
def `enum`[E <: java.lang.Enum[E]: c.WeakTypeTag](c: Context): c.Expr[Enum[E]] = {
import c.universe.*
val valueType = implicitly[c.WeakTypeTag[E]].tpe.dealias
val objectName = valueType.typeSymbol.companion.name.toTermName
c.Expr[Enum[E]](
q"""
new io.scalaland.enumz.Enum[$valueType] {
lazy val values: Vector[$valueType] = $objectName.values.toVector
def getName(enum: $valueType): String = enum.name
}
"""
)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy