diff --git a/src/main/java/org/openrewrite/java/migrate/io/ReplaceSystemOutWithIOPrint.java b/src/main/java/org/openrewrite/java/migrate/io/ReplaceSystemOutWithIOPrint.java index 543998d3c8..b8960f72fb 100644 --- a/src/main/java/org/openrewrite/java/migrate/io/ReplaceSystemOutWithIOPrint.java +++ b/src/main/java/org/openrewrite/java/migrate/io/ReplaceSystemOutWithIOPrint.java @@ -54,7 +54,6 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu if (!isSystemOutMethod(m)) { return m; } - maybeAddImport("java.io.IO", false); String methodName = m.getName().getSimpleName(); return m.getArguments().isEmpty() ? JavaTemplate.apply( "IO.#{}()", getCursor(), m.getCoordinates().replace(), methodName ) : diff --git a/src/test/java/org/openrewrite/java/migrate/io/ReplaceSystemOutWithIOPrintTest.java b/src/test/java/org/openrewrite/java/migrate/io/ReplaceSystemOutWithIOPrintTest.java index ac44344311..ba8fd79ee5 100644 --- a/src/test/java/org/openrewrite/java/migrate/io/ReplaceSystemOutWithIOPrintTest.java +++ b/src/test/java/org/openrewrite/java/migrate/io/ReplaceSystemOutWithIOPrintTest.java @@ -53,8 +53,6 @@ void test() { } """, """ - import java.io.IO; - class Example { void test() { IO.print("Hello"); @@ -77,8 +75,6 @@ void test() { } """, """ - import java.io.IO; - class Example { void test() { IO.println("Hello"); @@ -103,8 +99,6 @@ void test() { } """, """ - import java.io.IO; - class Example { void test() { IO.println("Hello"); @@ -128,8 +122,6 @@ void test() { } """, """ - import java.io.IO; - class Example { void test() { String message = "Hello World"; @@ -153,8 +145,6 @@ void test() { } """, """ - import java.io.IO; - class Example { void test() { IO.println(); @@ -180,8 +170,6 @@ void test() { } """, """ - import java.io.IO; - class Example { void test() { IO.print("Hello"); @@ -210,8 +198,6 @@ void test() { } """, """ - import java.io.IO; - class Example { void test() { String name = "John"; @@ -261,7 +247,7 @@ void test() { } @Test - void addsImportForRegularClassWithPackage() { + void doesNotAddImportForRegularClassWithPackage() { rewriteRun( java( """ @@ -276,8 +262,6 @@ public void greet() { """ package com.helloworld; - import java.io.IO; - public class Main { public void greet() { IO.println("hello");