aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorJon Pretty <jon.pretty@propensive.com>2017-10-31 11:11:58 +0100
committerJon Pretty <jon.pretty@propensive.com>2017-10-31 11:11:58 +0100
commit88f36a7a552246e210266a7ae82a2e480718512e (patch)
tree1bce74641f237d081f3d18fc7e5897ecfb2441b8 /core
parent7b776425828d27b3112ad5bddafaa7564c326536 (diff)
downloadmagnolia-88f36a7a552246e210266a7ae82a2e480718512e.tar.gz
magnolia-88f36a7a552246e210266a7ae82a2e480718512e.tar.bz2
magnolia-88f36a7a552246e210266a7ae82a2e480718512e.zip
Support nontrivial type constructors
Diffstat (limited to 'core')
-rw-r--r--core/src/main/scala/magnolia.scala22
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))