@@ -26,6 +26,28 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
26
26
close <- ctx.matchingParens.close(open)
27
27
} yield (open, close)
28
28
29
+ // terms dont give us terms https://github.com/scalameta/scalameta/issues/1212
30
+ // if we have a simple identifier, we can look at his definition at query it's type
31
+ // this should be improved in future version of scalameta
32
+ object TypeMatcher {
33
+ def apply (symbols : Symbol * )(implicit index : SemanticdbIndex ): TypeMatcher =
34
+ new TypeMatcher (symbols : _* )(index)
35
+ }
36
+
37
+ final class TypeMatcher (symbols : Symbol * )(implicit index : SemanticdbIndex ) {
38
+ def unapply (tree : Tree ): Boolean = {
39
+ index.denotation(tree)
40
+ .map(_.names.headOption.exists(n => symbols.exists(_ == n.symbol)))
41
+ .getOrElse(false )
42
+ }
43
+ }
44
+
45
+ val CollectionMap : TypeMatcher = TypeMatcher (
46
+ Symbol (" _root_.scala.collection.immutable.Map#" ),
47
+ Symbol (" _root_.scala.collection.mutable.Map#" ),
48
+ Symbol (" _root_.scala.Predef.Map#" )
49
+ )
50
+
29
51
def replaceSymbols (ctx : RuleCtx ): Patch = {
30
52
ctx.replaceSymbols(
31
53
" scala.collection.LinearSeq" -> " scala.collection.immutable.List" ,
@@ -290,7 +312,7 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
290
312
291
313
def replaceMapZip (ctx : RuleCtx ): Patch = {
292
314
ctx.tree.collect {
293
- case ap @ Term .Apply (Term .Select (_ , mapZip(_)), List (_)) =>
315
+ case ap @ Term .Apply (Term .Select (CollectionMap () , mapZip(_)), List (_)) =>
294
316
ctx.addRight(ap, " .toMap" )
295
317
}.asPatch
296
318
}
0 commit comments