@@ -225,11 +225,22 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
225
225
// terms dont give us terms https://github.com/scalameta/scalameta/issues/1212
226
226
// if we have a simple identifier, we can look at his definition at query it's type
227
227
// this should be improved in future version of scalameta
228
- def isTpe (symbol : Symbol , tree : Tree , ctx : RuleCtx ): Boolean =
229
- ctx.index.denotation(tree).map(_.names.headOption.exists(_.symbol == symbol)).getOrElse(false )
228
+ object TypeMatcher {
229
+ def apply (symbol : Symbol )(implicit index : SemanticdbIndex ): TypeMatcher =
230
+ new TypeMatcher (symbol)(index)
231
+ }
232
+
233
+ final class TypeMatcher (symbol : Symbol )(implicit index : SemanticdbIndex ) {
234
+ def unapply (tree : Tree ): Option [Unit ] = {
235
+ val typeMatches =
236
+ index.denotation(tree)
237
+ .map(_.names.headOption.exists(_.symbol == symbol))
238
+ .getOrElse(false )
239
+ if (typeMatches) Some (()) else None
240
+ }
241
+ }
230
242
231
- def isCollectionSet (tree : Tree , ctx : RuleCtx ): Boolean =
232
- isTpe(Symbol (" _root_.scala.collection.Set#" ), tree, ctx)
243
+ val CollectionSet : TypeMatcher = TypeMatcher (Symbol (" _root_.scala.collection.Set#" ))
233
244
234
245
def replaceSetMapPlusMinus (ctx : RuleCtx ): Patch = {
235
246
def rewriteOp (op : Tree , rhs : Tree , doubleOp : String , col0 : String ): Patch = {
@@ -247,10 +258,10 @@ case class Scalacollectioncompat_newcollections(index: SemanticdbIndex)
247
258
}
248
259
249
260
ctx.tree.collect {
250
- case Term .ApplyInfix (lhs , op @ setPlus(_), Nil , List (rhs)) if isCollectionSet(lhs, ctx ) =>
261
+ case Term .ApplyInfix (CollectionSet (_) , op @ setPlus(_), Nil , List (rhs)) =>
251
262
rewriteOp(op, rhs, " +" , " Set" )
252
263
253
- case Term .ApplyInfix (lhs , op @ setMinus(_), Nil , List (rhs)) if isCollectionSet(lhs, ctx ) =>
264
+ case Term .ApplyInfix (CollectionSet (_) , op @ setMinus(_), Nil , List (rhs)) =>
254
265
rewriteOp(op, rhs, " -" , " Set" )
255
266
256
267
case Term .ApplyInfix (lhs, op @ mapPlus(_), Nil , List (rhs)) =>
0 commit comments