diff --git a/.gitignore b/.gitignore index c1c540652..635d41b5b 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,6 @@ metals.sbt # Scala CLI specific .scala-build/ + +# Emacs Backups +*~ diff --git a/scalafix-cli/src/main/scala/scalafix/internal/interfaces/ScalafixPatchImpl.scala b/scalafix-cli/src/main/scala/scalafix/internal/interfaces/ScalafixPatchImpl.scala index 17c9e3d0e..5ffaf7fb1 100644 --- a/scalafix-cli/src/main/scala/scalafix/internal/interfaces/ScalafixPatchImpl.scala +++ b/scalafix-cli/src/main/scala/scalafix/internal/interfaces/ScalafixPatchImpl.scala @@ -24,4 +24,7 @@ case class ScalafixPatchImpl(patch: Patch)( ): ScalafixTextEdit } .toArray + + override def isAtomic: Boolean = + patch.isInstanceOf[Patch.internal.AtomicPatch] } diff --git a/scalafix-interfaces/src/main/java/scalafix/interfaces/ScalafixPatch.java b/scalafix-interfaces/src/main/java/scalafix/interfaces/ScalafixPatch.java index 3f9111e90..65f8a271b 100644 --- a/scalafix-interfaces/src/main/java/scalafix/interfaces/ScalafixPatch.java +++ b/scalafix-interfaces/src/main/java/scalafix/interfaces/ScalafixPatch.java @@ -8,4 +8,12 @@ public interface ScalafixPatch { default ScalafixTextEdit[] textEdits() { throw new UnsupportedOperationException("textEdits() is not implemented"); } + + /** + * + * @return True if this patch is atomic, else false. + */ + default boolean isAtomic() { + throw new UnsupportedOperationException("isAtomic() is not implemented"); + } } diff --git a/scalafix-tests/integration/src/test/scala/scalafix/tests/interfaces/ScalafixArgumentsSuite.scala b/scalafix-tests/integration/src/test/scala/scalafix/tests/interfaces/ScalafixArgumentsSuite.scala index 4f495bb88..18905db5a 100644 --- a/scalafix-tests/integration/src/test/scala/scalafix/tests/interfaces/ScalafixArgumentsSuite.scala +++ b/scalafix-tests/integration/src/test/scala/scalafix/tests/interfaces/ScalafixArgumentsSuite.scala @@ -18,6 +18,7 @@ import scalafix.interfaces.ScalafixDiagnostic import scalafix.interfaces.ScalafixFileEvaluationError import scalafix.interfaces.ScalafixMainCallback import scalafix.interfaces.ScalafixMainMode +import scalafix.interfaces.ScalafixPatch import scalafix.internal.interfaces.ScalafixArgumentsImpl import scalafix.internal.rule.RemoveUnused import scalafix.internal.rule.RemoveUnusedConfig @@ -572,6 +573,27 @@ class ScalafixArgumentsSuite extends AnyFunSuite with DiffAssertions { ) } + test("ScalafixPatch isAtomic") { + val cwd: Path = StringFS + .string2dir( + """|/src/Main.scala + | + |object Main extends App""".stripMargin, + charset + ) + .toNIO + val src = cwd.resolve("src") + + def patches(rules: List[String]): Array[ScalafixPatch] = { + val run = api.withRules(rules.asJava).withSourceroot(src) + val fileEvaluation = run.evaluate().getFileEvaluations.head + fileEvaluation.getPatches + } + + assert(patches(List("CommentFileAtomic")).forall(_.isAtomic)) + assert(patches(List("CommentFileNonAtomic")).forall(!_.isAtomic)) + } + test("com.github.liancheng::organize-imports is ignored") { val rules = api .withToolClasspath(