in scalafix/rules/src/main/scala/fix/v0_12_0/FixPubsubSpecializations.scala [141:188]
override def fix(implicit doc: SemanticDocument): Patch = {
doc.tree.collect {
case t @ q"$fn[$tp](..$args)" if PubSubIO.matches(fn.symbol) =>
// PubsubIO[T](args)
val io = buildPubsubIO(tp, tp.symbol, args)
Patch.replaceTree(t, io.syntax)
case t @ q"$qual.$fn[$tp](..$args)"
// PubsubIO.$fn[T](args)
if PubSubIO.matches(qual.symbol) && PubSubIOFns.contains(fn.value) =>
val renamedFn = Term.Name(PubSubIOFns(fn.value))
Patch.replaceTree(t, q"$qual.$renamedFn[$tp](..$args)".syntax)
case t @ q"$qual.readString(..$args)" if PubSubIO.matches(qual.symbol) =>
// PubsubIO.readString(args)
Patch.replaceTree(t, q"$qual.string(..$args)".syntax)
case t @ q"$qual.saveAsPubsub(..$args)" if expectedType(SCollPubsubOps)(qual) =>
scollType(qual) match {
case Some(tpSym) =>
val (ioArgs, paramArgs) = splitArgs(args)
val tp = Type.Name(tpSym.displayName) // may require import, but best effort
val io = buildPubsubIO(tp, tpSym, ioArgs)
val params = q"PubsubIO.WriteParam(..$paramArgs)"
Patch.replaceTree(t, q"$qual.write($io)($params)".syntax)
case None =>
// We did not managed to extract the type from the SCollection
Patch.empty
}
case t @ q"$qual.saveAsPubsubWithAttributes[$tp](..$args)"
if expectedType(SCollPubsubOps)(qual) =>
val (ioArgs, paramArgs) = splitArgs(args)
val io = q"PubsubIO.withAttributes[$tp](..$ioArgs)"
val params = q"PubsubIO.WriteParam(..$paramArgs)"
Patch.replaceTree(t, q"$qual.write($io)($params)".syntax)
case t @ q"$qual.pubsubSubscription[$tp](..$args)" if expectedType(SCtxOubSubOps)(qual) =>
val io = buildPubsubIO(tp, tp.symbol, args)
Patch.replaceTree(t, q"$qual.read($io)($ReadParamSub)".syntax)
case t @ q"$qual.pubsubSubscriptionWithAttributes[$tp](..$args)"
if expectedType(SCtxOubSubOps)(qual) =>
val io = q"PubsubIO.withAttributes[$tp](..$args)"
Patch.replaceTree(t, q"$qual.read($io)($ReadParamSub)".syntax)
case t @ q"$qual.pubsubTopic[$tp](..$args)" if expectedType(SCtxOubSubOps)(qual) =>
val io = buildPubsubIO(tp, tp.symbol, args)
Patch.replaceTree(t, q"$qual.read($io)($ReadParamTopic)".syntax)
case t @ q"$qual.pubsubTopicWithAttributes[$tp](..$args)"
if expectedType(SCtxOubSubOps)(qual) =>
val io = q"PubsubIO.withAttributes[$tp](..$args)"
Patch.replaceTree(t, q"$qual.read($io)($ReadParamTopic)".syntax)
}.asPatch
}