diff options
author | Jon Pretty <jon.pretty@propensive.com> | 2017-10-31 11:11:58 +0100 |
---|---|---|
committer | Jon Pretty <jon.pretty@propensive.com> | 2017-10-31 11:11:58 +0100 |
commit | 88f36a7a552246e210266a7ae82a2e480718512e (patch) | |
tree | 1bce74641f237d081f3d18fc7e5897ecfb2441b8 /core/src/main/scala | |
parent | 7b776425828d27b3112ad5bddafaa7564c326536 (diff) | |
download | magnolia-88f36a7a552246e210266a7ae82a2e480718512e.tar.gz magnolia-88f36a7a552246e210266a7ae82a2e480718512e.tar.bz2 magnolia-88f36a7a552246e210266a7ae82a2e480718512e.zip |
Support nontrivial type constructors
Diffstat (limited to 'core/src/main/scala')
-rw-r--r-- | core/src/main/scala/magnolia.scala | 22 |
1 files changed, 3 insertions, 19 deletions
diff --git a/core/src/main/scala/magnolia.scala b/core/src/main/scala/magnolia.scala index ae582e4..c2b280f 100644 --- a/core/src/main/scala/magnolia.scala +++ b/core/src/main/scala/magnolia.scala @@ -30,30 +30,14 @@ trait JoinContext[Tc[_], T] { object Magnolia { import CompileTimeState._ - type Construct[Call[_], T] = ((Call[R] => R) forSome { type R }) => T - def generic[T: c.WeakTypeTag](c: whitebox.Context): c.Tree = { import c.universe._ import scala.util.{Try, Success, Failure} - def javaClassName(sym: Symbol): String = - if(sym.owner.isPackage) sym.fullName - else if(sym.owner.isModuleClass) s"${javaClassName(sym.owner)}$$${sym.name}" - else s"${javaClassName(sym.owner)}.${sym.name}" - - def getModule[M](tpe: Type): M = { - val typeName = javaClassName(tpe.typeSymbol) + val typeConstructor: c.Type = + c.prefix.tree.tpe.member(TypeName("Typeclass")).asType.toType.typeConstructor - try { - val cls = Class.forName(s"$typeName$$") - cls.getField("MODULE$").get(cls).asInstanceOf[M] - } catch { - case e: ClassNotFoundException => - c.abort(c.enclosingPosition, s"""Class "${typeName}" could not be found. This usually means you are trying to use an interpolator in the same compilation unit as the one in which you defined it. Please try compiling interpolators first, separately from the code using them.""") - } - } - - val typeConstructor: c.Type = c.prefix.tree.tpe.companion.typeConstructor + println(typeConstructor) def findType(key: Type): Option[TermName] = recursionStack(c.enclosingPosition).frames.find(_.genericType == key).map(_.termName(c)) |