io.github.pidoveproject.showdown.protocol.messagePrefix.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scala-showdown-api_3 Show documentation
Show all versions of scala-showdown-api_3 Show documentation
A Scala wrapper of Pokemon Showdown's API
The newest version!
package io.github.pidoveproject.showdown.protocol
import scala.annotation.StaticAnnotation
import scala.quoted.*
case class messagePrefix(prefix: String) extends StaticAnnotation
object messagePrefix:
inline def getMessagePrefix[T]: Option[String] = ${ getMessagePrefixImpl[T] }
def getMessagePrefixImpl[T: Type](using Quotes): Expr[Option[String]] =
import quotes.reflect.*
val repr = TypeRepr.of[T]
val typeSymbol = repr.typeSymbol
val annotationRepr = TypeRepr.of[messagePrefix]
val annotationSymbol = annotationRepr.typeSymbol
typeSymbol.getAnnotation(annotationSymbol).map(_.asExpr) match
case Some('{ new `messagePrefix`($prefix: String) }) => '{ Some($prefix) }
case _ => '{ None }