forked from scalacenter/scalafix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package scalafix.rewrite | ||
|
||
import scala.{meta => m} | ||
import scalafix.util.Patch | ||
import scalafix.util.Whitespace | ||
import scalafix.util.logger | ||
|
||
case object Xor2Either extends Rewrite { | ||
override def rewrite(ast: m.Tree, ctx: RewriteCtx): Seq[Patch] = { | ||
import scala.meta._ | ||
val semantic = getSemanticApi(ctx) | ||
ast.collect { | ||
case t: m.Type.Ref | ||
if semantic | ||
.desugared(t: m.Type)(m.parsers.Parse.parseType) | ||
.exists(_.syntax.contains("Xor")) => | ||
logger.elem(t.syntax, semantic.desugared(t: Type)) | ||
val tok = t.tokens.head | ||
Seq( | ||
Patch(tok, tok, tok.syntax + "BANANA") | ||
) | ||
}.flatten | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
rewrites = [Xor2Either] | ||
<<< ONLY xor 1 | ||
import cats.data.Xor | ||
trait A { | ||
val r: Xor[Int, String] | ||
} | ||
>>> | ||
trait A { | ||
val r: Either[Int, String] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package cats.data | ||
|
||
sealed abstract class Xor[+A, +B] extends Product with Serializable | ||
|
||
object Xor { | ||
final case class Left[+A](a: A) extends (A Xor Nothing) | ||
final case class Right[+B](b: B) extends (Nothing Xor B) | ||
} |