Skip to content

Commit 0b869b4

Browse files
committed
Rename "KeepRefinements" to "Unqualified"
1 parent 6965f10 commit 0b869b4

File tree

3 files changed

+34
-31
lines changed

3 files changed

+34
-31
lines changed

modules/core/src/main/scala/derevo/Derevo.scala

+31-28
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ class Derevo(val c: blackbox.Context) {
99
type Newtype = NewtypeP[Tree]
1010
type NameAndTypes = NameAndTypesP[Tree, c.Type]
1111

12-
val CompositeSymbol = typeOf[composite].typeSymbol
13-
val DelegatingSymbol = typeOf[delegating].typeSymbol
14-
val PhantomSymbol = typeOf[phantom].typeSymbol
15-
val PassTypeArgsSymbol = typeOf[PassTypeArgs].typeSymbol
16-
val KeepRefinementsSymbol = typeOf[KeepRefinements].typeSymbol
12+
val CompositeSymbol = typeOf[composite].typeSymbol
13+
val DelegatingSymbol = typeOf[delegating].typeSymbol
14+
val PhantomSymbol = typeOf[phantom].typeSymbol
15+
val PassTypeArgsSymbol = typeOf[PassTypeArgs].typeSymbol
16+
val UnqualifiedSymbol = typeOf[Unqualified].typeSymbol
1717

1818
val instanceDefs = Vector(
1919
)
@@ -224,25 +224,25 @@ class Derevo(val c: blackbox.Context) {
224224
def fixFirstTypeParam = {
225225
val nothingT = c.typeOf[Nothing]
226226

227-
c.typecheck(mode.call.duplicate, silent = true, withMacrosDisabled = true) match {
228-
case q"$method[$nothing, ..$remainingTpes](..$args)" if nothing.tpe == nothingT =>
229-
q"$method[$outTyp, ..$remainingTpes](..$args)"
230-
case q"$method[$nothing, ..$remainingTpes]" if nothing.tpe == nothingT =>
231-
q"$method[$outTyp, ..$remainingTpes]"
232-
case EmptyTree =>
233-
mode.call match {
234-
case q"$method(..$args)" =>
235-
q"$method[$outTyp](..$args)"
236-
case q"$method" =>
237-
q"$method[$outTyp]"
238-
case _ => tree
239-
}
240-
case _ => tree
227+
c.typecheck(mode.call.duplicate, silent = true, withMacrosDisabled = true) match {
228+
case q"$method[$nothing, ..$remainingTpes](..$args)" if nothing.tpe == nothingT =>
229+
q"$method[$outTyp, ..$remainingTpes](..$args)"
230+
case q"$method[$nothing, ..$remainingTpes]" if nothing.tpe == nothingT =>
231+
q"$method[$outTyp, ..$remainingTpes]"
232+
case EmptyTree =>
233+
mode.call match {
234+
case q"$method(..$args)" =>
235+
q"$method[$outTyp](..$args)"
236+
case q"$method" =>
237+
q"$method[$outTyp]"
238+
case _ => tree
239+
}
240+
case _ => tree
241+
}
241242
}
242-
}
243243

244244
if (allTparams.isEmpty || allTparams.length <= mode.drop) {
245-
if (mode.keepRefinements) {
245+
if (mode.unqualified) {
246246
q"""
247247
@java.lang.SuppressWarnings(scala.Array("org.wartremover.warts.All", "scalafix:All", "all"))
248248
implicit val $tn = $fixFirstTypeParam
@@ -272,7 +272,7 @@ class Derevo(val c: blackbox.Context) {
272272
}
273273
else Nil
274274

275-
if (mode.keepRefinements) {
275+
if (mode.unqualified) {
276276
q"""
277277
@java.lang.SuppressWarnings(scala.Array("org.wartremover.warts.All", "scalafix:All", "all"))
278278
implicit def $tn[..$tparams](implicit ..$implicits) = $fixFirstTypeParam
@@ -320,12 +320,15 @@ class Derevo(val c: blackbox.Context) {
320320
val mangledName = obj.toString.replaceAll("[^\\w]", "_")
321321
val name = c.freshName(mangledName)
322322

323-
val call = extractCall(tree, newType)
323+
val call = extractCall(tree, newType)
324324
val tcheckedObj = c.typecheck(obj, silent = true)
325325
if (tcheckedObj.isEmpty) {
326-
c.warning(c.enclosingPosition, s"Could not typecheck `$obj`, will try unqualified mode. If you are using local import for derivation object - replace it with package-level import")
326+
c.warning(
327+
c.enclosingPosition,
328+
s"Could not typecheck `$obj`, will try unqualified mode. If you are using local import for derivation object - replace it with package-level import"
329+
)
327330

328-
return new NameAndTypes(call, name, NoType, NoType, NoType, 0, false, true,false)
331+
return List(new NameAndTypes(call, name, NoType, NoType, NoType, 0, false, true, false))
329332
}
330333

331334
val objTyp = tcheckedObj.tpe
@@ -351,12 +354,12 @@ class Derevo(val c: blackbox.Context) {
351354
case _ => false
352355
}
353356

354-
val keepRefinements = objTyp.baseType(KeepRefinementsSymbol) match {
357+
val unqualified = objTyp.baseType(UnqualifiedSymbol) match {
355358
case TypeRef(_, _, _) => true
356359
case _ => false
357360
}
358361

359-
nt.map(_.copy(passArgs = passArgs, keepRefinements = keepRefinements))
362+
nt.map(_.copy(passArgs = passArgs, unqualified = unqualified))
360363
}
361364

362365
trait DerivationMatcher {
@@ -410,7 +413,7 @@ object Derevo {
410413
newtype: typ,
411414
drop: Int,
412415
cascade: Boolean,
413-
keepRefinements: Boolean = false,
416+
unqualified: Boolean = false,
414417
passArgs: Boolean = false,
415418
)
416419
}

modules/core/src/main/scala/derevo/package.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ package derevo {
99

1010
/** */
1111
trait PassTypeArgs
12-
trait KeepRefinements
12+
trait Unqualified
1313

1414
class delegating(to: String, args: Any*) extends StaticAnnotation
1515
class phantom extends StaticAnnotation

modules/tests/src/main/scala/derevo/tests/Refinement.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import derevo._
44

55
trait Trait[T]
66

7-
object refinedTrait extends Derivation[Trait] with KeepRefinements {
7+
object refinedTrait extends Derivation[Trait] with Unqualified {
88
def apply[T, A](a: A): Trait[T] { type Refinement = A } = new Trait[T] { type Refinement = A }
99
def singleTparam[T](dummy: Int): Trait[T] { type Refinement = String } = new Trait[T] { type Refinement = String }
1010
}
1111

12-
object refinedTraitWithInstanceMethod extends Derivation[Trait] with KeepRefinements {
12+
object refinedTraitWithInstanceMethod extends Derivation[Trait] with Unqualified {
1313
def instance[T]: Trait[T] { type Refinement = String } = new Trait[T] { type Refinement = String }
1414
}
1515

0 commit comments

Comments
 (0)