Skip to content

Commit 02fb451

Browse files
committed
Reformat code
1 parent 5551e43 commit 02fb451

File tree

34 files changed

+970
-671
lines changed

34 files changed

+970
-671
lines changed

.scalafmt.conf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
version = 2.7.5
2-
maxColumn = 120
1+
version = 3.0.7
2+
maxColumn = 120
3+
runner.dialect = scala3
4+
fileOverride {
5+
"glob:**/scala-2/**" {
6+
runner.dialect = scala213
7+
}
8+
}

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,15 @@ lazy val macrosAkkaTests = projectMatrix
171171
.dependsOn(macrosAkka, testUtil)
172172
.jvmPlatform(scalaVersions = scala2)
173173

174-
lazy val macrosAutoCats = projectMatrix
174+
lazy val macrosAutoCats = projectMatrix
175175
.in(file("macrosAutoCats"))
176176
.settings(commonSettings)
177177
.settings(libraryDependencies ++= Seq(catsEffect, cats))
178178
.dependsOn(macros)
179179
.jvmPlatform(scalaVersions = scala2)
180180
.jsPlatform(scalaVersions = scala2)
181181

182-
lazy val macrosAutoCatsTests = projectMatrix
182+
lazy val macrosAutoCatsTests = projectMatrix
183183
.in(file("macrosAutoCatsTests"))
184184
.settings(testSettings)
185185
.settings(libraryDependencies ++= Seq(scalatest, catsEffect, tagging))

macros/src/main/scala-2/com/softwaremill/macwire/MacwireMacros.scala

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,29 @@ import scala.reflect.macros.blackbox
77
object MacwireMacros {
88
private val log = new Logger()
99

10-
def wire_impl[T: c.WeakTypeTag](c: blackbox.Context): c.Expr[T] =
10+
def wire_impl[T: c.WeakTypeTag](c: blackbox.Context): c.Expr[T] =
1111
wire(c)(DependencyResolver.throwErrorOnResolutionFailure[c.type, c.universe.Type, c.universe.Tree](c, log))
1212

1313
def wireRec_impl[T: c.WeakTypeTag](c: blackbox.Context): c.Expr[T] = {
1414
import c.universe._
1515

1616
def isWireable(tpe: Type): Boolean = {
1717
val name = tpe.typeSymbol.fullName
18-
19-
!name.startsWith("java.lang.") && !name.startsWith("scala.")
18+
19+
!name.startsWith("java.lang.") && !name.startsWith("scala.")
2020
}
21-
22-
val dependencyResolver = new DependencyResolver[c.type, Type, Tree](c, log)(tpe =>
21+
22+
val dependencyResolver = new DependencyResolver[c.type, Type, Tree](c, log)(tpe =>
2323
if (!isWireable(tpe)) c.abort(c.enclosingPosition, s"Cannot find a value of type: [${tpe}]")
2424
else c.Expr[T](q"wireRec[$tpe]").tree
2525
)
26-
26+
2727
wire(c)(dependencyResolver)
2828
}
2929

30-
def wire[T: c.WeakTypeTag](c: blackbox.Context)(dependencyResolver: DependencyResolver[c.type, c.universe.Type, c.universe.Tree]): c.Expr[T] = {
30+
def wire[T: c.WeakTypeTag](
31+
c: blackbox.Context
32+
)(dependencyResolver: DependencyResolver[c.type, c.universe.Type, c.universe.Tree]): c.Expr[T] = {
3133
import c.universe._
3234

3335
val constructorCrimper = new ConstructorCrimper[c.type, T](c, log)
@@ -44,7 +46,9 @@ object MacwireMacros {
4446
else s"Target type not supported for wiring: $targetType. Please file a bug report with your use-case."
4547
}
4648

47-
val code: Tree = (constructorCrimper.constructorTree(dependencyResolver) orElse companionCrimper.applyTree(dependencyResolver)) getOrElse
49+
val code: Tree = (constructorCrimper.constructorTree(dependencyResolver) orElse companionCrimper.applyTree(
50+
dependencyResolver
51+
)) getOrElse
4852
c.abort(c.enclosingPosition, whatWasWrong)
4953
log(s"Generated code: ${showCode(code)}, ${showRaw(code)}")
5054
c.Expr(code)
@@ -60,16 +64,16 @@ object MacwireMacros {
6064
val (params, fun) = factory match {
6165
// Function with two parameter lists (implicit parameters) (<2.13)
6266
case Block(Nil, Function(p, Apply(Apply(f, _), _))) => (p, f)
63-
case Block(Nil, Function(p, Apply(f, _))) => (p, f)
67+
case Block(Nil, Function(p, Apply(f, _))) => (p, f)
6468
// Function with two parameter lists (implicit parameters) (>=2.13)
6569
case Function(p, Apply(Apply(f, _), _)) => (p, f)
66-
case Function(p, Apply(f, _)) => (p, f)
70+
case Function(p, Apply(f, _)) => (p, f)
6771
// Other types not supported
6872
case _ => c.abort(c.enclosingPosition, s"Not supported factory type: [$factory]")
6973
}
7074

71-
val values = params.map {
72-
case vd@ValDef(_, name, tpt, rhs) => dependencyResolver.resolve(vd.symbol, typeCheckIfNeeded(tpt))
75+
val values = params.map { case vd @ ValDef(_, name, tpt, rhs) =>
76+
dependencyResolver.resolve(vd.symbol, typeCheckIfNeeded(tpt))
7377
}
7478
val code = q"$fun(..$values)"
7579

@@ -99,7 +103,7 @@ object MacwireMacros {
99103
def extractTypeFromNullaryType(tpe: Type) = {
100104
tpe match {
101105
case NullaryMethodType(underlying) => Some(underlying)
102-
case _ => None
106+
case _ => None
103107
}
104108
}
105109

macros/src/main/scala-2/com/softwaremill/macwire/internals/CompanionCrimper.scala

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ private[macwire] class CompanionCrimper[C <: blackbox.Context, T: C#WeakTypeTag]
1212
lazy val companionType: Option[Type] = CompanionCrimper.companionType(c)(targetType)
1313

1414
lazy val applies: Option[List[Symbol]] = CompanionCrimper.applies(c, log)(targetType)
15-
16-
def applyTree(dependencyResolver: DependencyResolverType): Option[Tree] = CompanionCrimper.applyTree[C](c, log)(targetType, dependencyResolver.resolve(_, _))
15+
16+
def applyTree(dependencyResolver: DependencyResolverType): Option[Tree] =
17+
CompanionCrimper.applyTree[C](c, log)(targetType, dependencyResolver.resolve(_, _))
1718

1819
}
1920

@@ -22,35 +23,43 @@ object CompanionCrimper {
2223

2324
private def isCompanionApply[C <: blackbox.Context](c: C)(targetType: c.Type, method: c.Symbol): Boolean =
2425
method.isMethod &&
25-
method.isPublic &&
26-
method.asMethod.returnType <:< targetType &&
27-
method.asMethod.name.decodedName.toString == "apply"
26+
method.isPublic &&
27+
method.asMethod.returnType <:< targetType &&
28+
method.asMethod.name.decodedName.toString == "apply"
2829

2930
private def companionType[C <: blackbox.Context](c: C)(targetType: c.Type): Option[c.Type] = {
3031
import c.universe._
3132

32-
if(targetType.companion == NoType) None else Some(targetType.companion)
33-
}
34-
35-
private def applies[C <: blackbox.Context](c: C, log: Logger)(targetType: c.Type): Option[List[c.Symbol]] = log.withBlock("Looking for apply methods of Companion Object") {
36-
val as: Option[List[c.Symbol]] = companionType(c)(targetType).map(_.members.filter(CompanionCrimper.isCompanionApply(c)(targetType, _)).toList)
37-
as.foreach(x => log.withBlock(s"There are ${x.size} apply methods:" ) { x.foreach(s => log(showApply(c)(s))) })
38-
as
33+
if (targetType.companion == NoType) None else Some(targetType.companion)
3934
}
4035

41-
def applyTree[C <: blackbox.Context](c: C, log: Logger)(targetType: c.Type, resolver: (c.Symbol, c.Type) => c.Tree): Option[c.Tree] = {
36+
private def applies[C <: blackbox.Context](c: C, log: Logger)(targetType: c.Type): Option[List[c.Symbol]] =
37+
log.withBlock("Looking for apply methods of Companion Object") {
38+
val as: Option[List[c.Symbol]] =
39+
companionType(c)(targetType).map(_.members.filter(CompanionCrimper.isCompanionApply(c)(targetType, _)).toList)
40+
as.foreach(x => log.withBlock(s"There are ${x.size} apply methods:") { x.foreach(s => log(showApply(c)(s))) })
41+
as
42+
}
43+
44+
def applyTree[C <: blackbox.Context](
45+
c: C,
46+
log: Logger
47+
)(targetType: c.Type, resolver: (c.Symbol, c.Type) => c.Tree): Option[c.Tree] = {
4248
import c.universe._
4349

44-
lazy val apply: Option[Symbol] = CompanionCrimper.applies(c, log)(targetType).flatMap( _ match {
45-
case applyMethod :: Nil => Some(applyMethod)
46-
case _ => None
47-
})
50+
lazy val apply: Option[Symbol] = CompanionCrimper
51+
.applies(c, log)(targetType)
52+
.flatMap(_ match {
53+
case applyMethod :: Nil => Some(applyMethod)
54+
case _ => None
55+
})
4856

4957
lazy val applySelect: Option[Select] = apply.map(a => Select(Ident(targetType.typeSymbol.companion), a))
5058

5159
lazy val applyParamLists: Option[List[List[Symbol]]] = apply.map(_.asMethod.paramLists)
5260

53-
def wireParams(paramLists: List[List[Symbol]]): List[List[Tree]] = paramLists.map(_.map(p => resolver(p, p.typeSignature)))
61+
def wireParams(paramLists: List[List[Symbol]]): List[List[Tree]] =
62+
paramLists.map(_.map(p => resolver(p, p.typeSignature)))
5463

5564
def applyArgs: Option[List[List[Tree]]] = applyParamLists.map(x => wireParams(x))
5665

macros/src/main/scala-2/com/softwaremill/macwire/internals/ConstructorCrimper.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,22 @@ object ConstructorCrimper {
4444
private def constructor[C <: blackbox.Context](c: C, log: Logger)(targetType: c.Type) = {
4545
import c.universe._
4646

47-
/** In some cases there is one extra (phantom) constructor.
48-
* This happens when extended trait has implicit param:
47+
/** In some cases there is one extra (phantom) constructor. This happens when extended trait has implicit param:
4948
*
5049
* {{{
5150
* trait A { implicit val a = ??? };
5251
* class X extends A
5352
* import scala.reflect.runtime.universe._
5453
* typeOf[X].members.filter(m => m.isMethod && m.asMethod.isConstructor && m.asMethod.isPrimaryConstructor).map(_.asMethod.fullName)
5554
*
56-
* //res1: Iterable[String] = List(X.<init>, A.$init$)
57-
* }}}
55+
* //res1: Iterable[String] = List(X.<init>, A.$init$)
56+
* }}}
5857
*
59-
* The {{{A.$init$}}} is the phantom constructor and we don't want it.
58+
* The {{{A.$init$}}} is the phantom constructor and we don't want it.
6059
*
61-
* In other words, if we don't filter such constructor using this function
62-
* 'wireActor-12-noPublicConstructor.failure' will compile and throw exception during runtime but we want to fail it during compilation time.
60+
* In other words, if we don't filter such constructor using this function
61+
* 'wireActor-12-noPublicConstructor.failure' will compile and throw exception during runtime but we want to fail
62+
* it during compilation time.
6363
*/
6464
def isPhantomConstructor(constructor: Symbol): Boolean = constructor.asMethod.fullName.endsWith("$init$")
6565

macros/src/main/scala-2/com/softwaremill/macwire/internals/DependencyResolver.scala

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,47 @@ import com.softwaremill.macwire.internals.EligibleValuesFinder.Scope.LocalForwar
44

55
import scala.reflect.macros.blackbox
66

7-
class DependencyResolver[C <: blackbox.Context, TypeC <: C#Type, TreeC <: C#Tree](val c: C, debug: Logger)(resolutionFallback: TypeC => TreeC) {
7+
class DependencyResolver[C <: blackbox.Context, TypeC <: C#Type, TreeC <: C#Tree](val c: C, debug: Logger)(
8+
resolutionFallback: TypeC => TreeC
9+
) {
810

911
import c.universe._
1012

1113
private val eligibleValuesFinder = new EligibleValuesFinder[c.type](c, debug)
1214

1315
private lazy val eligibleValues = eligibleValuesFinder.find()
1416

15-
/** Look for a single instance of type `t`.
16-
* If either no instance or multiple instances are found,
17-
* a compilation error is reported and `None` is returned.
17+
/** Look for a single instance of type `t`. If either no instance or multiple instances are found, a compilation error
18+
* is reported and `None` is returned.
1819
*/
1920
def resolve(param: Symbol, t: Type): Tree = {
2021
eligibleValues.findInFirstScope(t).toList match {
2122
case Nil => resolutionFallback(t.asInstanceOf[TypeC]).asInstanceOf[Tree]
2223
case value :: Nil =>
2324
val forwardValues = eligibleValues.findInScope(t, LocalForward)
2425
if (forwardValues.nonEmpty) {
25-
c.warning(c.enclosingPosition, s"Found [$value] for parameter [${param.name}], " +
26-
s"but a forward reference [${forwardValues.mkString(", ")}] was also eligible")
26+
c.warning(
27+
c.enclosingPosition,
28+
s"Found [$value] for parameter [${param.name}], " +
29+
s"but a forward reference [${forwardValues.mkString(", ")}] was also eligible"
30+
)
2731
}
2832
value
2933
case values => c.abort(c.enclosingPosition, s"Found multiple values of type [$t]: [$values]")
3034
}
3135
}
3236

33-
/** @return all the instances of type `t` that are accessible.
37+
/** @return
38+
* all the instances of type `t` that are accessible.
3439
*/
3540
def resolveAll(t: Type): Iterable[Tree] = {
3641
eligibleValues.findInAllScope(t)
3742
}
3843
}
3944

4045
object DependencyResolver {
41-
def throwErrorOnResolutionFailure[C <: blackbox.Context, TypeC <: C#Type, TreeC <: C#Tree](c: C, debug: Logger) =
42-
new DependencyResolver[C, TypeC, TreeC](c, debug)(t => c.abort(c.enclosingPosition, s"Cannot find a value of type: [$t]"))
43-
}
46+
def throwErrorOnResolutionFailure[C <: blackbox.Context, TypeC <: C#Type, TreeC <: C#Tree](c: C, debug: Logger) =
47+
new DependencyResolver[C, TypeC, TreeC](c, debug)(t =>
48+
c.abort(c.enclosingPosition, s"Cannot find a value of type: [$t]")
49+
)
50+
}

0 commit comments

Comments
 (0)