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