Skip to content

Commit 33845a5

Browse files
committed
expose & fix scalameta deprecations
1 parent 0501523 commit 33845a5

File tree

20 files changed

+258
-138
lines changed

20 files changed

+258
-138
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

+10-5
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,23 @@ 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, _)
21-
if denot.isVar =>
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(
21+
Term.ParamClause(
22+
Term.Param(_, _, Some(tpe), _) :: Nil,
23+
None
24+
) :: Nil,
25+
_
26+
) if denot.isVar =>
2227
// Workaround for https://github.com/scalameta/scalameta/issues/1100
2328
tpe
2429
case x =>

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

+44-24
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,25 @@ class PrettyType private (
216216
toMods(info),
217217
Name(""),
218218
paramss.iterator
219-
.map(params => params.symbols.smap(toTermParam))
219+
.map(params =>
220+
Term.ParamClause(params.symbols.smap(toTermParam))
221+
)
220222
.toList
221223
)
222224
} else {
223225
Decl.Def(
224226
toMods(info),
225227
Term.Name(info.displayName),
226-
tparams.smap(toTypeParam),
227-
paramss.iterator
228-
.map(params => params.symbols.smap(toTermParam))
229-
.toList,
228+
List(
229+
Member.ParamClauseGroup(
230+
tparams.smap(toTypeParam),
231+
paramss.iterator
232+
.map(params =>
233+
Term.ParamClause(params.symbols.smap(toTermParam))
234+
)
235+
.toList
236+
)
237+
),
230238
toType(ret)
231239
)
232240
}
@@ -267,7 +275,7 @@ class PrettyType private (
267275
Defn.Trait(
268276
toMods(info),
269277
Type.Name(info.displayName),
270-
tparams.smap(toTypeParam),
278+
Type.ParamClause(tparams.smap(toTypeParam)),
271279
Ctor.Primary(Nil, Name(""), Seq.empty[Term.ParamClause]),
272280
Template(
273281
Nil,
@@ -279,7 +287,8 @@ class PrettyType private (
279287
!i.isVarSetter
280288
) toStat(i)
281289
else Nil
282-
}
290+
},
291+
Nil
283292
)
284293
)
285294
case k.OBJECT =>
@@ -290,7 +299,8 @@ class PrettyType private (
290299
Nil,
291300
inits,
292301
Self(Name(""), None),
293-
objectDecls
302+
objectDecls,
303+
Nil
294304
)
295305
)
296306
case k.PACKAGE_OBJECT =>
@@ -301,35 +311,44 @@ class PrettyType private (
301311
Nil,
302312
inits,
303313
Self(Name(""), None),
304-
objectDecls
314+
objectDecls,
315+
Nil
305316
)
306317
)
307318
case k.CLASS =>
308319
val ctor: Ctor.Primary = declarations
309320
.collectFirst {
310321
case i if i.kind.isConstructor && i.is(p.PRIMARY) =>
311322
toTree(i) match {
312-
case ctor @ Ctor.Primary(_, _, Nil :: Nil)
313-
if !info.is(p.CASE) =>
323+
case ctor @ Ctor.Primary.After_4_6_0(
324+
_,
325+
_,
326+
Term.ParamClause(Nil, _)
327+
) if !info.is(p.CASE) =>
314328
// Remove redudant () for non-case classes: class Foo
315329
ctor.copy(paramss = Nil)
316330
case e: Ctor.Primary => e
317331
}
318332
}
319333
.getOrElse {
320-
Ctor.Primary(Nil, Name(""), Seq.empty[Term.ParamClause])
334+
Ctor.Primary.After_4_6_0(
335+
Nil,
336+
Name(""),
337+
Seq.empty[Term.ParamClause]
338+
)
321339
}
322340

323341
// FIXME: Workaround for https://github.com/scalameta/scalameta/issues/1492
324-
val isCtorName = ctor.paramss.flatMap(_.map(_.name.value)).toSet
342+
val isCtorName =
343+
ctor.paramClauses.flatMap(_.values).map(_.name.value).toSet
325344
def isSyntheticMember(m: s.SymbolInformation): Boolean =
326345
(isCaseClass && isCaseClassMethod(m.displayName)) ||
327346
isCtorName(m.displayName)
328347

329348
Defn.Class(
330349
toMods(info),
331350
Type.Name(info.displayName),
332-
tparams.smap(toTypeParam),
351+
Type.ParamClause(tparams.smap(toTypeParam)),
333352
ctor,
334353
Template(
335354
Nil,
@@ -342,7 +361,8 @@ class PrettyType private (
342361
!isSyntheticMember(i)
343362
) toStat(i)
344363
else Nil
345-
}
364+
},
365+
Nil
346366
)
347367
)
348368
case _ =>
@@ -353,14 +373,14 @@ class PrettyType private (
353373
Defn.Type(
354374
toMods(info),
355375
Type.Name(info.displayName),
356-
typeParameters.smap(toTypeParam),
376+
Type.ParamClause(typeParameters.smap(toTypeParam)),
357377
toType(lo)
358378
)
359379
} else {
360380
Decl.Type(
361381
toMods(info),
362382
Type.Name(info.displayName),
363-
typeParameters.smap(toTypeParam),
383+
Type.ParamClause(typeParameters.smap(toTypeParam)),
364384
toTypeBounds(lo, hi)
365385
)
366386
}
@@ -389,7 +409,7 @@ class PrettyType private (
389409
case _ =>
390410
tpe
391411
}
392-
Init(
412+
Init.After_4_6_0(
393413
toType(fixed),
394414
Name.Anonymous(),
395415
// Can't support term arguments
@@ -518,14 +538,14 @@ class PrettyType private (
518538
def targs: List[Type] =
519539
typeArguments.iterator.map {
520540
case TypeExtractors.Wildcard() =>
521-
Type.Placeholder(Type.Bounds(None, None))
541+
Type.Wildcard(Type.Bounds(None, None))
522542
case targ =>
523543
toType(targ)
524544
}.toList
525545
symbol match {
526546
case TypeExtractors.FunctionN() if typeArguments.lengthCompare(0) > 0 =>
527547
val params :+ res = targs
528-
Type.Function(params, res)
548+
Type.Function(Type.FuncParamClause(params), res)
529549
case TypeExtractors.TupleN() if typeArguments.lengthCompare(1) > 0 =>
530550
Type.Tuple(targs)
531551
case _ =>
@@ -548,7 +568,7 @@ class PrettyType private (
548568
case (name: Type.Name, Seq(lhs, rhs))
549569
if !Character.isJavaIdentifierPart(name.value.head) =>
550570
Type.ApplyInfix(lhs, name, rhs)
551-
case (q, targs) => Type.Apply(q, targs)
571+
case (q, targs) => Type.Apply(q, Type.ArgClause(targs))
552572
}
553573
}
554574
case s.SingleType(_, symbol) =>
@@ -634,7 +654,7 @@ class PrettyType private (
634654
Defn.Type(
635655
Nil,
636656
universalName,
637-
typeParameters.smap(toTypeParam),
657+
Type.ParamClause(typeParameters.smap(toTypeParam)),
638658
toType(underlying)
639659
) :: Nil
640660
),
@@ -681,7 +701,7 @@ class PrettyType private (
681701
Type.Param(
682702
Nil,
683703
Name(""),
684-
Nil,
704+
Type.ParamClause(Nil),
685705
Type.Bounds(None, None),
686706
Nil,
687707
Nil
@@ -698,7 +718,7 @@ class PrettyType private (
698718
Type.Param(
699719
toMods(info),
700720
name = Type.Name(info.displayName),
701-
tparams = tparams,
721+
tparamClause = Type.ParamClause(tparams),
702722
tbounds = bounds,
703723
// TODO: re-sugar context and view bounds https://github.com/scalacenter/scalafix/issues/759
704724
vbounds = Nil,

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ package scalafix.internal.v1
33
import scala.meta.Position
44
import scala.meta.Term
55
import scala.meta.Tree
6+
import scala.meta.Type
67

78
import scalafix.internal.util.PositionSyntax._
89

910
object PositionSearch {
1011
def find(tree: Tree, pos: Position): Option[Tree] = {
1112
val extrapos = tree match {
12-
case Term.ApplyInfix(lhs, op, Nil, _) =>
13+
case Term.ApplyInfix.After_4_6_0(lhs, op, Type.ArgClause(Nil), _) =>
1314
List(Position.Range(lhs.pos.input, lhs.pos.start, op.pos.end))
1415
case _ =>
1516
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)