@@ -310,7 +310,7 @@ object Consumer {
310
310
*/
311
311
implicit def consumer [T ]: Consumer [T ] = macro consumerImpl[T ]
312
312
313
- def consumerImpl [T : c.WeakTypeTag ](c : blackbox. Context ): c.Expr [Consumer [T ]] = {
313
+ def consumerImpl [T : c.WeakTypeTag ](c : Context ): c.Expr [Consumer [T ]] = {
314
314
import c .universe ._
315
315
316
316
val primitiveMap =
@@ -333,7 +333,8 @@ object Consumer {
333
333
val nullNodeDefault = reify(NullNode ).tree
334
334
335
335
def buildValue (_tpe : Type , reader : c.Expr [Any ], methodSuffix : String = " " , args : List [Tree ] = Nil , default : Tree = nullNodeDefault): (Tree , Tree ) = {
336
- val tpe = _tpe.dealias
336
+ // TODO: put in separate file for 2.10, 2.11 support, was _tpe.dealias
337
+ val tpe = _tpe.normalize
337
338
val t = appliedType(weakTypeOf[Consumer [Any ]].typeConstructor, tpe :: Nil )
338
339
c.inferImplicitValue(t) match {
339
340
case EmptyTree => c.abort(c.enclosingPosition, s " Couldn't find a muster.input.Consumer[ ${t.typeSymbol.name.decodedName.toString}], try bringing an implicit value for ${tpe.typeSymbol.name.decodedName.toString} in scope by importing one or defining one. " )
@@ -342,17 +343,17 @@ object Consumer {
342
343
val rdrOpt : Tree = {
343
344
if (helper.isPrimitive(tpe)) {
344
345
val nm = primitiveMap(tpe)
345
- Apply (Select (reader.tree, TermName (s " read ${nm}${methodSuffix}Opt " )), args)
346
+ Apply (Select (reader.tree, newTermName (s " read ${nm}${methodSuffix}Opt " )), args)
346
347
} else if (helper.isOption(tpe)) {
347
348
val agType = helper.resolveInnerOptionType(tpe)
348
349
val nm = primitiveMap(agType)
349
- Apply (Select (reader.tree, TermName (s " read ${nm}${methodSuffix}Opt " )), args)
350
+ Apply (Select (reader.tree, newTermName (s " read ${nm}${methodSuffix}Opt " )), args)
350
351
} else if (helper.isSeq(tpe) || helper.isSet(tpe))
351
- Apply (Select (reader.tree, TermName (s " readArray ${methodSuffix}Opt " )), args)
352
+ Apply (Select (reader.tree, newTermName (s " readArray ${methodSuffix}Opt " )), args)
352
353
else if (helper.isEnum(tpe)) {
353
- Apply (Select (reader.tree, TermName (s " readString ${methodSuffix}Opt " )), args)
354
+ Apply (Select (reader.tree, newTermName (s " readString ${methodSuffix}Opt " )), args)
354
355
} else
355
- Apply (Select (reader.tree, TermName (s " readObject ${methodSuffix}Opt " )), args)
356
+ Apply (Select (reader.tree, newTermName (s " readObject ${methodSuffix}Opt " )), args)
356
357
}
357
358
358
359
(rdrOpt, resolved)
@@ -362,24 +363,24 @@ object Consumer {
362
363
def setterDef (returnType : Type , reader : c.Expr [Any ], fieldName : Tree , defVal : Tree = EmptyTree ): Tree = {
363
364
val t = appliedType(weakTypeOf[Consumer [Any ]].typeConstructor, returnType :: Nil )
364
365
val (definition, resolved) = buildValue(returnType, reader, " Field" , List (fieldName), defVal)
365
- val fn = c.freshName (" consumer$" )
366
- val vn = TermName (fn)
366
+ val fn = c.fresh (" consumer$" )
367
+ val vn = newTermName (fn)
367
368
val v = ValDef (Modifiers (), vn, TypeTree (t), resolved)
368
- val cn = c.freshName (" node$" )
369
+ val cn = c.fresh (" node$" )
369
370
370
371
defVal match {
371
372
case EmptyTree =>
372
- val noDefault = Apply (Select (definition, TermName (" getOrElse" )), nullNodeDefault :: Nil )
373
- val ce = c.Expr [AstNode [_]](Ident (TermName (cn)))
374
- val ct : Tree = ValDef (Modifiers (), TermName (cn), TypeTree (weakTypeOf[AstNode [_]]), noDefault)
375
- Block (v :: ct :: Nil , Apply (Select (Ident (vn), TermName (" consume" )), ce.tree :: Nil ))
373
+ val noDefault = Apply (Select (definition, newTermName (" getOrElse" )), nullNodeDefault :: Nil )
374
+ val ce = c.Expr [AstNode [_]](Ident (newTermName (cn)))
375
+ val ct : Tree = ValDef (Modifiers (), newTermName (cn), TypeTree (weakTypeOf[AstNode [_]]), noDefault)
376
+ Block (v :: ct :: Nil , Apply (Select (Ident (vn), newTermName (" consume" )), ce.tree :: Nil ))
376
377
case defTree =>
377
- val ce = c.Expr [Option [AstNode [_]]](Ident (TermName (cn)))
378
- val ct : Tree = ValDef (Modifiers (), TermName (cn), TypeTree (weakTypeOf[Option [AstNode [_]]]), definition)
378
+ val ce = c.Expr [Option [AstNode [_]]](Ident (newTermName (cn)))
379
+ val ct : Tree = ValDef (Modifiers (), newTermName (cn), TypeTree (weakTypeOf[Option [AstNode [_]]]), definition)
379
380
// val cons = Apply(Select(Ident(vn), TermName("consume")), ce.tree :: Nil)
380
381
val res = reify(
381
382
ce.splice match {
382
- case Some (n) => c.Expr (Apply (Select (Ident (vn), TermName (" consume" )), Ident (TermName (" n" )) :: Nil )).splice
383
+ case Some (n) => c.Expr (Apply (Select (Ident (vn), newTermName (" consume" )), Ident (newTermName (" n" )) :: Nil )).splice
383
384
case _ => c.Expr (defTree).splice
384
385
})
385
386
Block (v :: ct :: Nil , res.tree)
@@ -401,7 +402,7 @@ object Consumer {
401
402
! (sym.isParamWithDefault || sym.typeSignature <:< typeOf[Option [_]])
402
403
}
403
404
404
- val expr = c.Expr [Set [String ]](Apply (Select (Ident (TermName (" Set" )), TermName (" apply" )),
405
+ val expr = c.Expr [Set [String ]](Apply (Select (Ident (newTermName (" Set" )), newTermName (" apply" )),
405
406
ctors.flatten.filter(isRequired).map(sym => Literal (Constant (sym.name.decodedName.toString)))
406
407
))
407
408
@@ -416,11 +417,11 @@ object Consumer {
416
417
417
418
418
419
419
- val ctors : List [MethodSymbol ] = tpe.member(termNames .CONSTRUCTOR )
420
+ val ctors : List [MethodSymbol ] = tpe.member(nme .CONSTRUCTOR )
420
421
.asTerm.alternatives // List of constructors
421
422
.map(_.asMethod) // method symbols
422
- .sortBy(- _.paramLists .flatten.size)
423
- val ifExprsAndParams = ctors.map(ctor => ctorCheckingExpr(ctor.paramLists )).zip(ctors.map(_.asMethod.paramLists ))
423
+ .sortBy(- _.paramss .flatten.size)
424
+ val ifExprsAndParams = ctors.map(ctor => ctorCheckingExpr(ctor.paramss )).zip(ctors.map(_.asMethod.paramss ))
424
425
425
426
ifElseTreeBuilder(ifExprsAndParams)
426
427
}
@@ -433,14 +434,14 @@ object Consumer {
433
434
// Change out the types if it has type parameters
434
435
val pTpe = pSym.typeSignature.substituteTypes(sym.asClass.typeParams, tpeArgs)
435
436
val fieldName = Literal (Constant (pSym.name.decodedName.toString))
436
- val pTnm = TermName (pSym.name.decodedName.toString)
437
+ val pTnm = newTermName (pSym.name.decodedName.toString)
437
438
438
439
// If param has defaults, try to find the val in map, or call
439
440
// default evaluation from its companion object
440
441
// is the sym.companionSymbol.isTerm the best way to check for NoSymbol?
441
442
// is there a way to get teh default values for the overloaded constructors?
442
- val tree = if (pSym.asTerm.isParamWithDefault && sym.companion .isTerm) {
443
- val defVal = Select (Ident (sym.companion ), TermName (" $lessinit$greater$default$" + (index + 1 ).toString))
443
+ val tree = if (pSym.asTerm.isParamWithDefault && sym.companionSymbol .isTerm) {
444
+ val defVal = Select (Ident (sym.companionSymbol ), newTermName (" $lessinit$greater$default$" + (index + 1 ).toString))
444
445
// val defValG = Apply(Select(New(weakTypeOf[ConstantNode[_]])))
445
446
setterDef(pTpe, reader, fieldName, defVal)
446
447
} else {
@@ -449,13 +450,13 @@ object Consumer {
449
450
(ValDef (Modifiers (), pTnm, TypeTree (pTpe), tree), Ident (pTnm))
450
451
})
451
452
452
- Block (params.flatMap(_.map(_._1)), params.foldLeft(Select (New (Ident (sym)), termNames .CONSTRUCTOR ): Tree ) { (ct, args) =>
453
+ Block (params.flatMap(_.map(_._1)), params.foldLeft(Select (New (Ident (sym)), nme .CONSTRUCTOR ): Tree ) { (ct, args) =>
453
454
Apply (ct, args.map(_._2))
454
455
})
455
456
}
456
457
457
- val on = c.freshName (" consumed$" )
458
- val ot = TermName (on)
458
+ val on = c.fresh (" consumed$" )
459
+ val ot = newTermName (on)
459
460
val otr : Tree = ValDef (Modifiers (), ot, TypeTree (tpe), pickConstructorTree(reify(reader.splice.keySet)))
460
461
461
462
val setterBlocks : List [Tree ] = {
@@ -464,7 +465,7 @@ object Consumer {
464
465
val stripped = pSym.name.decodedName.toString.replaceFirst(" ^set" , " " ).replaceFirst(" _=$" , " " )
465
466
val name = if (needsLower) stripped(0 ).toLower + stripped.substring(1 ) else stripped
466
467
val paramType = {
467
- val tp = pSym.asMethod.paramLists .head.head
468
+ val tp = pSym.asMethod.paramss .head.head
468
469
tp.typeSignatureIn(tpe)
469
470
}
470
471
Apply (Select (Ident (ot), pSym.name), setterDef(paramType, reader, Literal (Constant (name))) :: Nil )
@@ -484,7 +485,7 @@ object Consumer {
484
485
new Consumer [T ] {
485
486
def consume (node : AstNode [_]): T = {
486
487
node match {
487
- case obj : ObjectNode => c.Expr [T ](buildObject(thisType, c.Expr [ObjectNode ](Ident (TermName (" obj" ))))).splice
488
+ case obj : ObjectNode => c.Expr [T ](buildObject(thisType, c.Expr [ObjectNode ](Ident (newTermName (" obj" ))))).splice
488
489
case NullNode | UndefinedNode => null .asInstanceOf [T ]
489
490
case x => throw new MappingException (s " Got a ${x.getClass.getSimpleName} and expected an ObjectNode " )
490
491
}
0 commit comments