@@ -8,6 +8,28 @@ import scala.meta._
8
8
case class Scalacollectioncompat_newcollections (index : SemanticdbIndex )
9
9
extends SemanticRule (index, " Scalacollectioncompat_newcollections" ) {
10
10
11
+ // terms dont give us terms https://github.com/scalameta/scalameta/issues/1212
12
+ // if we have a simple identifier, we can look at his definition at query it's type
13
+ // this should be improved in future version of scalameta
14
+ object TypeMatcher {
15
+ def apply (symbols : Symbol * )(implicit index : SemanticdbIndex ): TypeMatcher =
16
+ new TypeMatcher (symbols : _* )(index)
17
+ }
18
+
19
+ final class TypeMatcher (symbols : Symbol * )(implicit index : SemanticdbIndex ) {
20
+ def unapply (tree : Tree ): Boolean = {
21
+ index.denotation(tree)
22
+ .map(_.names.headOption.exists(n => symbols.exists(_ == n.symbol)))
23
+ .getOrElse(false )
24
+ }
25
+ }
26
+
27
+ val CollectionMap : TypeMatcher = TypeMatcher (
28
+ Symbol (" _root_.scala.collection.immutable.Map#" ),
29
+ Symbol (" _root_.scala.collection.mutable.Map#" ),
30
+ Symbol (" _root_.scala.Predef.Map#" )
31
+ )
32
+
11
33
def replaceSymbols (ctx : RuleCtx ): Patch = {
12
34
ctx.replaceSymbols(
13
35
" scala.Stream" -> " scala.LazyList" ,
@@ -245,7 +267,7 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
245
267
246
268
def replaceMapZip (ctx : RuleCtx ): Patch = {
247
269
ctx.tree.collect {
248
- case ap @ Term .Apply (Term .Select (_ , mapZip(_)), List (_)) =>
270
+ case ap @ Term .Apply (Term .Select (CollectionMap () , mapZip(_)), List (_)) =>
249
271
ctx.addRight(ap, " .toMap" )
250
272
251
273
}.asPatch
0 commit comments