Skip to content

Commit 5e77b05

Browse files
committed
expose & fix scalameta deprecations
1 parent 0501523 commit 5e77b05

File tree

13 files changed

+95
-66
lines changed

13 files changed

+95
-66
lines changed

docs/developers/tutorial.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ To fix this bug, we first match function call nodes `Term.Apply` and pattern
181181
match only `Lit.Boolean` that appear in argument position
182182

183183
```scala
184-
case Term.Apply(_, args) =>
184+
case Term.Apply.After_4_6_0(_, args) =>
185185
args.collect {
186186
case t @ Lit.Boolean(_) =>
187187
Patch.addLeft(t, "isSuccess = ")
@@ -206,8 +206,8 @@ is to produce `finish(isError = true)`.
206206
To fix this bug, we start by capturing the called method into a variable `fun`
207207

208208
```diff
209-
- case Term.Apply(_, args) =>
210-
+ case Term.Apply(fun, args) =>
209+
- case Term.Apply.After_4_6_0(_, args) =>
210+
+ case Term.Apply.After_4_6_0(fun, args) =>
211211
```
212212

213213
We update the call to `args.collect` to include the index of the argument
@@ -284,7 +284,7 @@ class NamedLiteralArguments
284284
extends SemanticRule("NamedLiteralArguments") {
285285
override def fix(implicit doc: SemanticDocument): Patch = {
286286
doc.tree.collect {
287-
case Term.Apply(fun, args) =>
287+
case Term.Apply.After_4_6_0(fun, args) =>
288288
args.zipWithIndex.collect {
289289
case (t @ Lit.Boolean(_), i) =>
290290
fun.symbol.info match {
@@ -384,7 +384,7 @@ Next, we write the same pattern matching logic as in `NamedLiteralArguments`
384384

385385
```scala
386386
doc.tree.collect {
387-
case Term.Apply(_, args) =>
387+
case Term.Apply.After_4_6_0(_, args) =>
388388
args.collect {
389389
case t @ Lit.Boolean(_) =>
390390
// ....
@@ -581,7 +581,7 @@ class NoLiteralArguments(config: NoLiteralArgumentsConfig)
581581
override def fix(implicit doc: SyntacticDocument): Patch = {
582582
doc.tree
583583
.collect {
584-
case Term.Apply(_, args) =>
584+
case Term.Apply.After_4_6_0(_, args) =>
585585
args.collect {
586586
case t: Lit if config.isDisabled(t) =>
587587
Patch.lint(LiteralArgument(t))

project/ScalafixBuild.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys {
8686
"-encoding",
8787
"UTF-8",
8888
"-feature",
89-
"-unchecked"
89+
"-unchecked",
90+
"-Wconf:cat=deprecation&origin=scala\\.meta\\..*:error",
9091
)
9192
)
9293

scalafix-core/src/main/scala/scalafix/internal/patch/EscapeHatch.scala

+24-4
Original file line numberDiff line numberDiff line change
@@ -242,19 +242,39 @@ object EscapeHatch {
242242
def unapply(mods: List[Mod]): Option[List[Term]] =
243243
mods.collectFirst {
244244
case Mod.Annot(
245-
Init(
245+
Init.After_4_6_0(
246246
Type.Name(SuppressWarnings),
247247
_,
248-
List(Term.Apply(Term.Name("Array"), args) :: Nil)
248+
List(
249+
Term.ArgClause(
250+
List(
251+
Term.Apply.After_4_6_0(
252+
Term.Name("Array"),
253+
Term.ArgClause(args, None)
254+
)
255+
),
256+
None
257+
)
258+
)
249259
)
250260
) =>
251261
args
252262

253263
case Mod.Annot(
254-
Init(
264+
Init.After_4_6_0(
255265
Type.Select(_, Type.Name(SuppressWarnings)),
256266
_,
257-
List(Term.Apply(Term.Name("Array"), args) :: Nil)
267+
List(
268+
Term.ArgClause(
269+
List(
270+
Term.Apply.After_4_6_0(
271+
Term.Name("Array"),
272+
Term.ArgClause(args, None)
273+
)
274+
),
275+
None
276+
)
277+
)
258278
)
259279
) =>
260280
args

scalafix-core/src/main/scala/scalafix/internal/patch/ReplaceSymbolOps.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ object ReplaceSymbolOps {
8888
object Identifier {
8989
def unapply(tree: Tree): Option[(Name, Symbol)] = tree match {
9090
case n: Name => n.symbol.map(s => n -> s)
91-
case Init(n: Name, _, _) => n.symbol.map(s => n -> s)
91+
case Init.After_4_6_0(n: Name, _, _) => n.symbol.map(s => n -> s)
9292
case _ => None
9393
}
9494
}

scalafix-core/src/main/scala/scalafix/internal/util/DenotationOps.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ import scalafix.v0._
77

88
object DenotationOps {
99
val defaultDialect: Dialect =
10-
dialects.Scala212.copy(allowTypeLambdas = true)
10+
dialects.Scala212.withAllowTypeLambdas(true)
1111

1212
def resultType(
1313
symbol: Symbol,
1414
denot: Denotation,
1515
dialect: Dialect
1616
): Option[Type] = {
1717
def getDeclType(tpe: Type): Type = tpe match {
18-
case Type.Method(_, tpe) if denot.isMethod => tpe
19-
case Type.Lambda(_, tpe) if denot.isMethod => getDeclType(tpe)
20-
case Type.Method((Term.Param(_, _, Some(tpe), _) :: Nil) :: Nil, _)
18+
case Type.Method.After_4_6_0(_, tpe) if denot.isMethod => tpe
19+
case Type.Lambda.After_4_6_0(_, tpe) if denot.isMethod => getDeclType(tpe)
20+
case Type.Method.After_4_6_0(Term.ParamClause(Term.Param(_, _, Some(tpe), _) :: Nil, None) :: Nil, _)
2121
if denot.isVar =>
2222
// Workaround for https://github.com/scalameta/scalameta/issues/1100
2323
tpe

scalafix-core/src/main/scala/scalafix/internal/util/PrettyType.scala

+31-23
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,21 @@ class PrettyType private (
216216
toMods(info),
217217
Name(""),
218218
paramss.iterator
219-
.map(params => params.symbols.smap(toTermParam))
219+
.map(params => Term.ParamClause(params.symbols.smap(toTermParam)))
220220
.toList
221221
)
222222
} else {
223223
Decl.Def(
224224
toMods(info),
225225
Term.Name(info.displayName),
226-
tparams.smap(toTypeParam),
227-
paramss.iterator
228-
.map(params => params.symbols.smap(toTermParam))
229-
.toList,
226+
List(
227+
Member.ParamClauseGroup(
228+
tparams.smap(toTypeParam),
229+
paramss.iterator
230+
.map(params => Term.ParamClause(params.symbols.smap(toTermParam)))
231+
.toList,
232+
)
233+
),
230234
toType(ret)
231235
)
232236
}
@@ -267,7 +271,7 @@ class PrettyType private (
267271
Defn.Trait(
268272
toMods(info),
269273
Type.Name(info.displayName),
270-
tparams.smap(toTypeParam),
274+
Type.ParamClause(tparams.smap(toTypeParam)),
271275
Ctor.Primary(Nil, Name(""), Seq.empty[Term.ParamClause]),
272276
Template(
273277
Nil,
@@ -279,7 +283,8 @@ class PrettyType private (
279283
!i.isVarSetter
280284
) toStat(i)
281285
else Nil
282-
}
286+
},
287+
Nil
283288
)
284289
)
285290
case k.OBJECT =>
@@ -290,7 +295,8 @@ class PrettyType private (
290295
Nil,
291296
inits,
292297
Self(Name(""), None),
293-
objectDecls
298+
objectDecls,
299+
Nil
294300
)
295301
)
296302
case k.PACKAGE_OBJECT =>
@@ -301,35 +307,36 @@ class PrettyType private (
301307
Nil,
302308
inits,
303309
Self(Name(""), None),
304-
objectDecls
310+
objectDecls,
311+
Nil
305312
)
306313
)
307314
case k.CLASS =>
308315
val ctor: Ctor.Primary = declarations
309316
.collectFirst {
310317
case i if i.kind.isConstructor && i.is(p.PRIMARY) =>
311318
toTree(i) match {
312-
case ctor @ Ctor.Primary(_, _, Nil :: Nil)
319+
case ctor @ Ctor.Primary.After_4_6_0(_, _, Nil :: Nil)
313320
if !info.is(p.CASE) =>
314321
// Remove redudant () for non-case classes: class Foo
315322
ctor.copy(paramss = Nil)
316323
case e: Ctor.Primary => e
317324
}
318325
}
319326
.getOrElse {
320-
Ctor.Primary(Nil, Name(""), Seq.empty[Term.ParamClause])
327+
Ctor.Primary.After_4_6_0(Nil, Name(""), Seq.empty[Term.ParamClause])
321328
}
322329

323330
// FIXME: Workaround for https://github.com/scalameta/scalameta/issues/1492
324-
val isCtorName = ctor.paramss.flatMap(_.map(_.name.value)).toSet
331+
val isCtorName = ctor.paramClauses.flatMap(_.values).map(_.name.value).toSet
325332
def isSyntheticMember(m: s.SymbolInformation): Boolean =
326333
(isCaseClass && isCaseClassMethod(m.displayName)) ||
327334
isCtorName(m.displayName)
328335

329336
Defn.Class(
330337
toMods(info),
331338
Type.Name(info.displayName),
332-
tparams.smap(toTypeParam),
339+
Type.ParamClause(tparams.smap(toTypeParam)),
333340
ctor,
334341
Template(
335342
Nil,
@@ -342,7 +349,8 @@ class PrettyType private (
342349
!isSyntheticMember(i)
343350
) toStat(i)
344351
else Nil
345-
}
352+
},
353+
Nil
346354
)
347355
)
348356
case _ =>
@@ -353,14 +361,14 @@ class PrettyType private (
353361
Defn.Type(
354362
toMods(info),
355363
Type.Name(info.displayName),
356-
typeParameters.smap(toTypeParam),
364+
Type.ParamClause(typeParameters.smap(toTypeParam)),
357365
toType(lo)
358366
)
359367
} else {
360368
Decl.Type(
361369
toMods(info),
362370
Type.Name(info.displayName),
363-
typeParameters.smap(toTypeParam),
371+
Type.ParamClause(typeParameters.smap(toTypeParam)),
364372
toTypeBounds(lo, hi)
365373
)
366374
}
@@ -389,7 +397,7 @@ class PrettyType private (
389397
case _ =>
390398
tpe
391399
}
392-
Init(
400+
Init.After_4_6_0(
393401
toType(fixed),
394402
Name.Anonymous(),
395403
// Can't support term arguments
@@ -518,14 +526,14 @@ class PrettyType private (
518526
def targs: List[Type] =
519527
typeArguments.iterator.map {
520528
case TypeExtractors.Wildcard() =>
521-
Type.Placeholder(Type.Bounds(None, None))
529+
Type.Wildcard(Type.Bounds(None, None))
522530
case targ =>
523531
toType(targ)
524532
}.toList
525533
symbol match {
526534
case TypeExtractors.FunctionN() if typeArguments.lengthCompare(0) > 0 =>
527535
val params :+ res = targs
528-
Type.Function(params, res)
536+
Type.Function(Type.FuncParamClause(params), res)
529537
case TypeExtractors.TupleN() if typeArguments.lengthCompare(1) > 0 =>
530538
Type.Tuple(targs)
531539
case _ =>
@@ -548,7 +556,7 @@ class PrettyType private (
548556
case (name: Type.Name, Seq(lhs, rhs))
549557
if !Character.isJavaIdentifierPart(name.value.head) =>
550558
Type.ApplyInfix(lhs, name, rhs)
551-
case (q, targs) => Type.Apply(q, targs)
559+
case (q, targs) => Type.Apply(q, Type.ArgClause(targs))
552560
}
553561
}
554562
case s.SingleType(_, symbol) =>
@@ -634,7 +642,7 @@ class PrettyType private (
634642
Defn.Type(
635643
Nil,
636644
universalName,
637-
typeParameters.smap(toTypeParam),
645+
Type.ParamClause(typeParameters.smap(toTypeParam)),
638646
toType(underlying)
639647
) :: Nil
640648
),
@@ -681,7 +689,7 @@ class PrettyType private (
681689
Type.Param(
682690
Nil,
683691
Name(""),
684-
Nil,
692+
Type.ParamClause(Nil),
685693
Type.Bounds(None, None),
686694
Nil,
687695
Nil
@@ -698,7 +706,7 @@ class PrettyType private (
698706
Type.Param(
699707
toMods(info),
700708
name = Type.Name(info.displayName),
701-
tparams = tparams,
709+
tparamClause = Type.ParamClause(tparams),
702710
tbounds = bounds,
703711
// TODO: re-sugar context and view bounds https://github.com/scalacenter/scalafix/issues/759
704712
vbounds = Nil,

scalafix-core/src/main/scala/scalafix/internal/v1/PositionSearch.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import scalafix.internal.util.PositionSyntax._
99
object PositionSearch {
1010
def find(tree: Tree, pos: Position): Option[Tree] = {
1111
val extrapos = tree match {
12-
case Term.ApplyInfix(lhs, op, Nil, _) =>
12+
case Term.ApplyInfix.After_4_6_0(lhs, op, Nil, _) =>
1313
List(Position.Range(lhs.pos.input, lhs.pos.start, op.pos.end))
1414
case _ =>
1515
List()

scalafix-core/src/main/scala/scalafix/internal/v1/TreePos.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ object TreePos {
6161
case t: Pat.Interpolate => symbolImpl(t.prefix)
6262
case Defn.Val(_, p :: Nil, _, _) => symbolImpl(p)
6363
case Decl.Val(_, p :: Nil, _) => symbolImpl(p)
64-
case Defn.Var(_, p :: Nil, _, _) => symbolImpl(p)
64+
case Defn.Var.After_4_7_2(_, p :: Nil, _, _) => symbolImpl(p)
6565
case Decl.Var(_, p :: Nil, _) => symbolImpl(p)
6666
case t: Importee.Rename => symbolImpl(t.name)
6767
case t: Importee.Name => symbolImpl(t.name)

scalafix-core/src/main/scala/scalafix/util/TreeOps.scala

+11-11
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,23 @@ object TreeExtractors {
2424

2525
object Mods {
2626
def unapply(tree: Tree): Option[List[Mod]] = tree match {
27-
case Ctor.Primary(mods, _, _) => Some(mods)
28-
case Ctor.Secondary(mods, _, _, _, _) => Some(mods)
29-
case Decl.Def(mods, _, _, _, _) => Some(mods)
30-
case Decl.Type(mods, _, _, _) => Some(mods)
27+
case Ctor.Primary.After_4_6_0(mods, _, _) => Some(mods)
28+
case Ctor.Secondary.After_4_6_0(mods, _, _, _, _) => Some(mods)
29+
case Decl.Def.After_4_6_0(mods, _, _, _) => Some(mods)
30+
case Decl.Type.After_4_6_0(mods, _, _, _) => Some(mods)
3131
case Decl.Val(mods, _, _) => Some(mods)
3232
case Decl.Var(mods, _, _) => Some(mods)
33-
case Defn.Class(mods, _, _, _, _) => Some(mods)
34-
case Defn.Def(mods, _, _, _, _, _) => Some(mods)
35-
case Defn.Macro(mods, _, _, _, _, _) => Some(mods)
33+
case Defn.Class.After_4_6_0(mods, _, _, _, _) => Some(mods)
34+
case Defn.Def.After_4_7_3(mods, _, _, _, _) => Some(mods)
35+
case Defn.Macro.After_4_7_3(mods, _, _, _, _) => Some(mods)
3636
case Defn.Object(mods, _, _) => Some(mods)
37-
case Defn.Trait(mods, _, _, _, _) => Some(mods)
38-
case Defn.Type(mods, _, _, _) => Some(mods)
37+
case Defn.Trait.After_4_6_0(mods, _, _, _, _) => Some(mods)
38+
case Defn.Type.After_4_6_0(mods, _, _, _, _) => Some(mods)
3939
case Defn.Val(mods, _, _, _) => Some(mods)
40-
case Defn.Var(mods, _, _, _) => Some(mods)
40+
case Defn.Var.After_4_7_2(mods, _, _, _) => Some(mods)
4141
case Pkg.Object(mods, _, _) => Some(mods)
4242
case Term.Param(mods, _, _, _) => Some(mods)
43-
case Type.Param(mods, _, _, _, _, _) => Some(mods)
43+
case Type.Param.After_4_6_0(mods, _, _, _, _, _) => Some(mods)
4444
case _ => None
4545
}
4646
}

0 commit comments

Comments
 (0)