From 6680df27d1b503862cc8e55be258d198d92bbd16 Mon Sep 17 00:00:00 2001 From: Laurence Warne Date: Sun, 12 Nov 2023 14:31:26 +0000 Subject: [PATCH 1/2] Add isAtomic to ScalafixPatch interface --- .gitignore | 3 +++ .../interfaces/ScalafixPatchImpl.scala | 3 +++ .../scalafix/interfaces/ScalafixPatch.java | 8 +++++++ .../interfaces/ScalafixArgumentsSuite.scala | 22 +++++++++++++++++++ 4 files changed, 36 insertions(+) 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..763f25297 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("isAtmoic() 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( From 5163ead94cfe212a8dffabb4aaa6e0234180974f Mon Sep 17 00:00:00 2001 From: Brice Jaglin Date: Thu, 16 Nov 2023 15:07:49 +0100 Subject: [PATCH 2/2] fix typo --- .../src/main/java/scalafix/interfaces/ScalafixPatch.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scalafix-interfaces/src/main/java/scalafix/interfaces/ScalafixPatch.java b/scalafix-interfaces/src/main/java/scalafix/interfaces/ScalafixPatch.java index 763f25297..65f8a271b 100644 --- a/scalafix-interfaces/src/main/java/scalafix/interfaces/ScalafixPatch.java +++ b/scalafix-interfaces/src/main/java/scalafix/interfaces/ScalafixPatch.java @@ -14,6 +14,6 @@ default ScalafixTextEdit[] textEdits() { * @return True if this patch is atomic, else false. */ default boolean isAtomic() { - throw new UnsupportedOperationException("isAtmoic() is not implemented"); + throw new UnsupportedOperationException("isAtomic() is not implemented"); } }