Skip to content

Commit

Permalink
Run scalafmt & test:scalafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Apr 24, 2018
1 parent aac916b commit 8f4b8ab
Show file tree
Hide file tree
Showing 139 changed files with 3,746 additions and 2,376 deletions.
Expand Up @@ -29,8 +29,9 @@ object ContextUtil {
* Given `myImplicitConversion(someValue).extensionMethod`, where `extensionMethod` is a macro that uses this
* method, the result of this method is `f(<Tree of someValue>)`.
*/
def selectMacroImpl[T: c.WeakTypeTag](c: blackbox.Context)(
f: (c.Expr[Any], c.Position) => c.Expr[T]): c.Expr[T] = {
def selectMacroImpl[T: c.WeakTypeTag](
c: blackbox.Context
)(f: (c.Expr[Any], c.Position) => c.Expr[T]): c.Expr[T] = {
import c.universe._
c.macroApplication match {
case s @ Select(Apply(_, t :: Nil), _) => f(c.Expr[Any](t), s.pos)
Expand Down Expand Up @@ -211,12 +212,14 @@ final class ContextUtil[C <: blackbox.Context](val ctx: C) {
def changeOwner(tree: Tree, prev: Symbol, next: Symbol): Unit =
new ChangeOwnerAndModuleClassTraverser(
prev.asInstanceOf[global.Symbol],
next.asInstanceOf[global.Symbol]).traverse(tree.asInstanceOf[global.Tree])
next.asInstanceOf[global.Symbol]
).traverse(tree.asInstanceOf[global.Tree])

// Workaround copied from scala/async:can be removed once https://github.com/scala/scala/pull/3179 is merged.
private[this] class ChangeOwnerAndModuleClassTraverser(oldowner: global.Symbol,
newowner: global.Symbol)
extends global.ChangeOwnerTraverser(oldowner, newowner) {
private[this] class ChangeOwnerAndModuleClassTraverser(
oldowner: global.Symbol,
newowner: global.Symbol
) extends global.ChangeOwnerTraverser(oldowner, newowner) {
override def traverse(tree: global.Tree): Unit = {
tree match {
case _: global.DefTree => change(tree.symbol.moduleClass)
Expand Down Expand Up @@ -248,7 +251,8 @@ final class ContextUtil[C <: blackbox.Context](val ctx: C) {
* the type constructor `[x] List[x]`.
*/
def extractTC(tcp: AnyRef with Singleton, name: String)(
implicit it: ctx.TypeTag[tcp.type]): ctx.Type = {
implicit it: ctx.TypeTag[tcp.type]
): ctx.Type = {
val itTpe = it.tpe.asInstanceOf[global.Type]
val m = itTpe.nonPrivateMember(global.newTypeName(name))
val tc = itTpe.memberInfo(m).asInstanceOf[ctx.universe.Type]
Expand All @@ -262,8 +266,10 @@ final class ContextUtil[C <: blackbox.Context](val ctx: C) {
* Typically, `f` is a `Select` or `Ident`.
* The wrapper is replaced with the result of `subWrapper(<Type of T>, <Tree of v>, <wrapper Tree>)`
*/
def transformWrappers(t: Tree,
subWrapper: (String, Type, Tree, Tree) => Converted[ctx.type]): Tree = {
def transformWrappers(
t: Tree,
subWrapper: (String, Type, Tree, Tree) => Converted[ctx.type]
): Tree = {
// the main tree transformer that replaces calls to InputWrapper.wrap(x) with
// plain Idents that reference the actual input value
object appTransformer extends Transformer {
Expand Down
Expand Up @@ -26,19 +26,21 @@ sealed trait Converted[C <: blackbox.Context with Singleton] {
}
object Converted {
def NotApplicable[C <: blackbox.Context with Singleton] = new NotApplicable[C]
final case class Failure[C <: blackbox.Context with Singleton](position: C#Position,
message: String)
extends Converted[C] {
final case class Failure[C <: blackbox.Context with Singleton](
position: C#Position,
message: String
) extends Converted[C] {
def isSuccess = false
def transform(f: C#Tree => C#Tree): Converted[C] = new Failure(position, message)
}
final class NotApplicable[C <: blackbox.Context with Singleton] extends Converted[C] {
def isSuccess = false
def transform(f: C#Tree => C#Tree): Converted[C] = this
}
final case class Success[C <: blackbox.Context with Singleton](tree: C#Tree,
finalTransform: C#Tree => C#Tree)
extends Converted[C] {
final case class Success[C <: blackbox.Context with Singleton](
tree: C#Tree,
finalTransform: C#Tree => C#Tree
) extends Converted[C] {
def isSuccess = true
def transform(f: C#Tree => C#Tree): Converted[C] = Success(f(tree), finalTransform)
}
Expand Down
Expand Up @@ -41,9 +41,11 @@ object Instance {
final val MapName = "map"
final val InstanceTCName = "M"

final class Input[U <: Universe with Singleton](val tpe: U#Type,
val expr: U#Tree,
val local: U#ValDef)
final class Input[U <: Universe with Singleton](
val tpe: U#Type,
val expr: U#Tree,
val local: U#ValDef
)
trait Transform[C <: blackbox.Context with Singleton, N[_]] {
def apply(in: C#Tree): C#Tree
}
Expand Down
Expand Up @@ -13,8 +13,9 @@ import macros._

/** A `TupleBuilder` that uses a KList as the tuple representation.*/
object KListBuilder extends TupleBuilder {
def make(c: blackbox.Context)(mt: c.Type,
inputs: Inputs[c.universe.type]): BuilderResult[c.type] =
def make(
c: blackbox.Context
)(mt: c.Type, inputs: Inputs[c.universe.type]): BuilderResult[c.type] =
new BuilderResult[c.type] {
val ctx: c.type = c
val util = ContextUtil[c.type](c)
Expand Down Expand Up @@ -47,15 +48,20 @@ object KListBuilder extends TupleBuilder {
case Nil => revBindings.reverse
}

private[this] def makeKList(revInputs: Inputs[c.universe.type],
klist: Tree,
klistType: Type): Tree =
private[this] def makeKList(
revInputs: Inputs[c.universe.type],
klist: Tree,
klistType: Type
): Tree =
revInputs match {
case in :: tail =>
val next = ApplyTree(
TypeApply(Ident(kcons),
TypeTree(in.tpe) :: TypeTree(klistType) :: TypeTree(mTC) :: Nil),
in.expr :: klist :: Nil)
TypeApply(
Ident(kcons),
TypeTree(in.tpe) :: TypeTree(klistType) :: TypeTree(mTC) :: Nil
),
in.expr :: klist :: Nil
)
makeKList(tail, next, appliedType(kconsTC, in.tpe :: klistType :: mTC :: Nil))
case Nil => klist
}
Expand Down
Expand Up @@ -16,8 +16,9 @@ import macros._
* and `KList` for larger numbers of inputs. This builder cannot handle fewer than 2 inputs.
*/
object MixedBuilder extends TupleBuilder {
def make(c: blackbox.Context)(mt: c.Type,
inputs: Inputs[c.universe.type]): BuilderResult[c.type] = {
def make(
c: blackbox.Context
)(mt: c.Type, inputs: Inputs[c.universe.type]): BuilderResult[c.type] = {
val delegate = if (inputs.size > TupleNBuilder.MaxInputs) KListBuilder else TupleNBuilder
delegate.make(c)(mt, inputs)
}
Expand Down
Expand Up @@ -35,8 +35,9 @@ trait TupleBuilder {
type Inputs[U <: Universe with Singleton] = List[Instance.Input[U]]

/** Constructs a one-time use Builder for Context `c` and type constructor `tcType`. */
def make(c: blackbox.Context)(tcType: c.Type,
inputs: Inputs[c.universe.type]): BuilderResult[c.type]
def make(
c: blackbox.Context
)(tcType: c.Type, inputs: Inputs[c.universe.type]): BuilderResult[c.type]
}

trait BuilderResult[C <: blackbox.Context with Singleton] {
Expand Down
Expand Up @@ -22,8 +22,9 @@ object TupleNBuilder extends TupleBuilder {
final val MaxInputs = 11
final val TupleMethodName = "tuple"

def make(c: blackbox.Context)(mt: c.Type,
inputs: Inputs[c.universe.type]): BuilderResult[c.type] =
def make(
c: blackbox.Context
)(mt: c.Type, inputs: Inputs[c.universe.type]): BuilderResult[c.type] =
new BuilderResult[c.type] {
val util = ContextUtil[c.type](c)
import c.universe._
Expand All @@ -34,8 +35,9 @@ object TupleNBuilder extends TupleBuilder {
val ctx: c.type = c
val representationC: PolyType = {
val tcVariable: Symbol = newTCVariable(util.initialOwner)
val tupleTypeArgs = inputs.map(in =>
internal.typeRef(NoPrefix, tcVariable, in.tpe :: Nil).asInstanceOf[global.Type])
val tupleTypeArgs = inputs.map(
in => internal.typeRef(NoPrefix, tcVariable, in.tpe :: Nil).asInstanceOf[global.Type]
)
val tuple = global.definitions.tupleType(tupleTypeArgs)
internal.polyType(tcVariable :: Nil, tuple.asInstanceOf[Type])
}
Expand All @@ -47,10 +49,12 @@ object TupleNBuilder extends TupleBuilder {
}
def extract(param: ValDef): List[ValDef] = bindTuple(param, Nil, inputs.map(_.local), 1)

def bindTuple(param: ValDef,
revBindings: List[ValDef],
params: List[ValDef],
i: Int): List[ValDef] =
def bindTuple(
param: ValDef,
revBindings: List[ValDef],
params: List[ValDef],
i: Int
): List[ValDef] =
params match {
case (x @ ValDef(mods, name, tpt, _)) :: xs =>
val rhs = select(Ident(param.name), "_" + i.toString)
Expand Down

0 comments on commit 8f4b8ab

Please sign in to comment.