![JAR search and dependency download from the Maven repository](/logo.png)
scalikejdbc.EntityUtil.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scalikejdbc-syntax-support-macro_2.10 Show documentation
Show all versions of scalikejdbc-syntax-support-macro_2.10 Show documentation
scalikejdbc-syntax-support-macro
package scalikejdbc
import scala.language.experimental.macros
import scala.reflect.macros.blackbox.Context
import scalikejdbc.MacroCompatible._
private[scalikejdbc] object EntityUtil {
private[scalikejdbc] def constructorParams[A: c.WeakTypeTag](c: Context)(macroName: String, excludes: c.Expr[String]*) = {
import c.universe._
val A = weakTypeTag[A].tpe
val declarations = decls(c)(A)
val ctor = declarations.collectFirst { case m: MethodSymbol if m.isPrimaryConstructor => m }.getOrElse {
c.abort(c.enclosingPosition, s"Could not find the primary constructor for $A. type $A must be a class, not trait or type parameter")
}
val allParams = paramLists(c)(ctor).head
val excludeStrs: Set[String] = excludes.map(_.tree).flatMap {
case q"${ value: String }" => Some(value)
case m => {
c.error(c.enclosingPosition, s"You must use String literal values for field names to exclude from #$macroName's targets. $m could not resolve at compile time.")
None
}
}.toSet
val paramsStrs: Set[String] = allParams.map(_.name.decodedName.toString).toSet
excludeStrs.foreach { ex =>
if (!paramsStrs(ex)) c.error(c.enclosingPosition, s"$ex does not found in ${weakTypeTag[A].tpe}")
}
allParams.filterNot(f => excludeStrs(f.name.decodedName.toString))
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy